1*0a6a1f1dSLionel Sambuc/*.$NetBSD: setjmp.S,v 1.1 2014/08/10 05:47:36 matt Exp $.*/ 2*0a6a1f1dSLionel Sambuc 3*0a6a1f1dSLionel Sambuc/*- 4*0a6a1f1dSLionel Sambuc * Copyright (c) 2014 The NetBSD Foundation, Inc. 5*0a6a1f1dSLionel Sambuc * All rights reserved. 6*0a6a1f1dSLionel Sambuc * 7*0a6a1f1dSLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation 8*0a6a1f1dSLionel Sambuc * by Matt Thomas of 3am Software Foundry. 9*0a6a1f1dSLionel Sambuc * 10*0a6a1f1dSLionel Sambuc * Redistribution and use in source and binary forms, with or without 11*0a6a1f1dSLionel Sambuc * modification, are permitted provided that the following conditions 12*0a6a1f1dSLionel Sambuc * are met: 13*0a6a1f1dSLionel Sambuc * 1. Redistributions of source code must retain the above copyright 14*0a6a1f1dSLionel Sambuc * notice, this list of conditions and the following disclaimer. 15*0a6a1f1dSLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 16*0a6a1f1dSLionel Sambuc * notice, this list of conditions and the following disclaimer in the 17*0a6a1f1dSLionel Sambuc * documentation and/or other materials provided with the distribution. 18*0a6a1f1dSLionel Sambuc * 19*0a6a1f1dSLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20*0a6a1f1dSLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21*0a6a1f1dSLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22*0a6a1f1dSLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23*0a6a1f1dSLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24*0a6a1f1dSLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25*0a6a1f1dSLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26*0a6a1f1dSLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27*0a6a1f1dSLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28*0a6a1f1dSLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29*0a6a1f1dSLionel Sambuc * POSSIBILITY OF SUCH DAMAGE. 30*0a6a1f1dSLionel Sambuc */ 31*0a6a1f1dSLionel Sambuc 32*0a6a1f1dSLionel Sambuc#include <machine/asm.h> 33*0a6a1f1dSLionel Sambuc#include "assym.h" 34*0a6a1f1dSLionel Sambuc 35*0a6a1f1dSLionel Sambuc/* 36*0a6a1f1dSLionel Sambuc * C library -- setjmp, longjmp 37*0a6a1f1dSLionel Sambuc * 38*0a6a1f1dSLionel Sambuc * longjmp(a,v) 39*0a6a1f1dSLionel Sambuc * will generate a "return(v)" from the last call to 40*0a6a1f1dSLionel Sambuc * setjmp(a) 41*0a6a1f1dSLionel Sambuc * by restoring registers from the stack. 42*0a6a1f1dSLionel Sambuc * The previous signal state is restored. 43*0a6a1f1dSLionel Sambuc */ 44*0a6a1f1dSLionel Sambuc 45*0a6a1f1dSLionel Sambuc .section .rodata.cst8,"aM",@progbits,8 46*0a6a1f1dSLionel Sambuc .align 3 47*0a6a1f1dSLionel Sambuc.L_MAGIC: 48*0a6a1f1dSLionel Sambuc .xword _JB_MAGIC_AARCH64_SETJMP 49*0a6a1f1dSLionel Sambuc 50*0a6a1f1dSLionel SambucENTRY(__setjmp14) 51*0a6a1f1dSLionel Sambuc adrp x7, .L_MAGIC 52*0a6a1f1dSLionel Sambuc ldr x7, [x7, #:lo12:.L_MAGIC] 53*0a6a1f1dSLionel Sambuc 54*0a6a1f1dSLionel Sambuc mov x3, sp 55*0a6a1f1dSLionel Sambuc stp x7, x3, [x0, #_JB_MAGIC] 56*0a6a1f1dSLionel Sambuc 57*0a6a1f1dSLionel Sambuc stp x19, x20, [x0, #_JB_X19] 58*0a6a1f1dSLionel Sambuc stp x21, x22, [x0, #_JB_X21] 59*0a6a1f1dSLionel Sambuc stp x23, x24, [x0, #_JB_X23] 60*0a6a1f1dSLionel Sambuc stp x25, x26, [x0, #_JB_X25] 61*0a6a1f1dSLionel Sambuc stp x27, x28, [x0, #_JB_X27] 62*0a6a1f1dSLionel Sambuc stp x29, x30, [x0, #_JB_X29] 63*0a6a1f1dSLionel Sambuc 64*0a6a1f1dSLionel Sambuc mrs x5, tpidr_el0 65*0a6a1f1dSLionel Sambuc str x5, [x0, #_JB_TPIDR] 66*0a6a1f1dSLionel Sambuc 67*0a6a1f1dSLionel Sambuc stp d8, d9, [x0, #_JB_D8] 68*0a6a1f1dSLionel Sambuc stp d10, d11, [x0, #_JB_D10] 69*0a6a1f1dSLionel Sambuc stp d12, d13, [x0, #_JB_D12] 70*0a6a1f1dSLionel Sambuc stp d14, d15, [x0, #_JB_D14] 71*0a6a1f1dSLionel Sambuc 72*0a6a1f1dSLionel Sambuc /* Get the signal mask. */ 73*0a6a1f1dSLionel Sambuc add x2, x0, #_JB_SIGMASK 74*0a6a1f1dSLionel Sambuc mov x1, #0 75*0a6a1f1dSLionel Sambuc mov x0, #0 76*0a6a1f1dSLionel Sambuc 77*0a6a1f1dSLionel Sambuc stp x29, x30, [sp, #-16]! 78*0a6a1f1dSLionel Sambuc mov x29, sp 79*0a6a1f1dSLionel Sambuc bl _C_LABEL(__sigprocmask14) 80*0a6a1f1dSLionel Sambuc ldp x29, x30, [sp], #16 81*0a6a1f1dSLionel Sambuc 82*0a6a1f1dSLionel Sambuc mov x0, xzr 83*0a6a1f1dSLionel Sambuc ret 84*0a6a1f1dSLionel SambucEND(__setjmp14) 85*0a6a1f1dSLionel Sambuc 86*0a6a1f1dSLionel SambucENTRY(__longjmp14) 87*0a6a1f1dSLionel Sambuc adrp x7, .L_MAGIC 88*0a6a1f1dSLionel Sambuc ldr x7, [x7, #:lo12:.L_MAGIC] 89*0a6a1f1dSLionel Sambuc ldp x2, x3, [x0, #_JB_MAGIC] 90*0a6a1f1dSLionel Sambuc cmp x2, x7 91*0a6a1f1dSLionel Sambuc b.ne .Lbotch 92*0a6a1f1dSLionel Sambuc 93*0a6a1f1dSLionel Sambuc ldp x4, x5, [x0, #_JB_X29] 94*0a6a1f1dSLionel Sambuc cbz x3, .Lbotch 95*0a6a1f1dSLionel Sambuc cbz x4, .Lbotch 96*0a6a1f1dSLionel Sambuc cbz x5, .Lbotch 97*0a6a1f1dSLionel Sambuc 98*0a6a1f1dSLionel Sambuc ldp x19, x20, [x0, #_JB_X19] 99*0a6a1f1dSLionel Sambuc ldp x21, x22, [x0, #_JB_X21] 100*0a6a1f1dSLionel Sambuc ldp x23, x24, [x0, #_JB_X23] 101*0a6a1f1dSLionel Sambuc ldp x25, x26, [x0, #_JB_X25] 102*0a6a1f1dSLionel Sambuc ldp x27, x28, [x0, #_JB_X27] 103*0a6a1f1dSLionel Sambuc 104*0a6a1f1dSLionel Sambuc ldr x5, [x0, #_JB_TPIDR] 105*0a6a1f1dSLionel Sambuc msr tpidr_el0, x5 106*0a6a1f1dSLionel Sambuc 107*0a6a1f1dSLionel Sambuc ldp d8, d9, [x0, #_JB_D8] 108*0a6a1f1dSLionel Sambuc ldp d10, d11, [x0, #_JB_D10] 109*0a6a1f1dSLionel Sambuc ldp d12, d13, [x0, #_JB_D12] 110*0a6a1f1dSLionel Sambuc ldp d14, d15, [x0, #_JB_D14] 111*0a6a1f1dSLionel Sambuc 112*0a6a1f1dSLionel Sambuc sub sp, x3, #32 113*0a6a1f1dSLionel Sambuc 114*0a6a1f1dSLionel Sambuc stp x4, x5, [sp, #16] 115*0a6a1f1dSLionel Sambuc str x1, [sp, #8] 116*0a6a1f1dSLionel Sambuc add x29, sp, #16 117*0a6a1f1dSLionel Sambuc 118*0a6a1f1dSLionel Sambuc mov x2, #0 119*0a6a1f1dSLionel Sambuc add x1, x0, #_JB_SIGMASK 120*0a6a1f1dSLionel Sambuc mov x0, #3 /* SIG_SETMASK */ 121*0a6a1f1dSLionel Sambuc bl _C_LABEL(__sigprocmask14) 122*0a6a1f1dSLionel Sambuc 123*0a6a1f1dSLionel Sambuc ldp x29, x30, [sp, #16] 124*0a6a1f1dSLionel Sambuc ldr x0, [sp, #8] 125*0a6a1f1dSLionel Sambuc add sp, sp, #32 126*0a6a1f1dSLionel Sambuc ret 127*0a6a1f1dSLionel Sambuc 128*0a6a1f1dSLionel Sambuc /* validation failed, die die die. */ 129*0a6a1f1dSLionel Sambuc.Lbotch: 130*0a6a1f1dSLionel Sambuc bl _C_LABEL(longjmperror) 131*0a6a1f1dSLionel Sambuc bl _C_LABEL(abort) 132*0a6a1f1dSLionel Sambuc1: b 1b /* Cannot get here */ 133*0a6a1f1dSLionel SambucEND(__longjmp14) 134