1*0a6a1f1dSLionel Sambuc// 2*0a6a1f1dSLionel Sambuc// Copyright (c) 1999, 2000 3*0a6a1f1dSLionel Sambuc// Intel Corporation. 4*0a6a1f1dSLionel Sambuc// All rights reserved. 5*0a6a1f1dSLionel Sambuc// 6*0a6a1f1dSLionel Sambuc// Redistribution and use in source and binary forms, with or without 7*0a6a1f1dSLionel Sambuc// modification, are permitted provided that the following conditions 8*0a6a1f1dSLionel Sambuc// are met: 9*0a6a1f1dSLionel Sambuc// 10*0a6a1f1dSLionel Sambuc// 1. Redistributions of source code must retain the above copyright 11*0a6a1f1dSLionel Sambuc// notice, this list of conditions and the following disclaimer. 12*0a6a1f1dSLionel Sambuc// 13*0a6a1f1dSLionel Sambuc// 2. Redistributions in binary form must reproduce the above copyright 14*0a6a1f1dSLionel Sambuc// notice, this list of conditions and the following disclaimer in the 15*0a6a1f1dSLionel Sambuc// documentation and/or other materials provided with the distribution. 16*0a6a1f1dSLionel Sambuc// 17*0a6a1f1dSLionel Sambuc// 3. All advertising materials mentioning features or use of this software 18*0a6a1f1dSLionel Sambuc// must display the following acknowledgement: 19*0a6a1f1dSLionel Sambuc// 20*0a6a1f1dSLionel Sambuc// This product includes software developed by Intel Corporation and 21*0a6a1f1dSLionel Sambuc// its contributors. 22*0a6a1f1dSLionel Sambuc// 23*0a6a1f1dSLionel Sambuc// 4. Neither the name of Intel Corporation or its contributors may be 24*0a6a1f1dSLionel Sambuc// used to endorse or promote products derived from this software 25*0a6a1f1dSLionel Sambuc// without specific prior written permission. 26*0a6a1f1dSLionel Sambuc// 27*0a6a1f1dSLionel Sambuc// THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS'' 28*0a6a1f1dSLionel Sambuc// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29*0a6a1f1dSLionel Sambuc// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30*0a6a1f1dSLionel Sambuc// ARE DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE 31*0a6a1f1dSLionel Sambuc// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32*0a6a1f1dSLionel Sambuc// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33*0a6a1f1dSLionel Sambuc// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34*0a6a1f1dSLionel Sambuc// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35*0a6a1f1dSLionel Sambuc// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36*0a6a1f1dSLionel Sambuc// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 37*0a6a1f1dSLionel Sambuc// THE POSSIBILITY OF SUCH DAMAGE. 38*0a6a1f1dSLionel Sambuc// 39*0a6a1f1dSLionel Sambuc// 40*0a6a1f1dSLionel Sambuc 41*0a6a1f1dSLionel Sambuc// 42*0a6a1f1dSLionel Sambuc// Module Name: 43*0a6a1f1dSLionel Sambuc// 44*0a6a1f1dSLionel Sambuc// setjmp.s 45*0a6a1f1dSLionel Sambuc// 46*0a6a1f1dSLionel Sambuc// Abstract: 47*0a6a1f1dSLionel Sambuc// 48*0a6a1f1dSLionel Sambuc// Contains an implementation of setjmp and longjmp for the 49*0a6a1f1dSLionel Sambuc// IA-64 architecture. 50*0a6a1f1dSLionel Sambuc 51*0a6a1f1dSLionel Sambuc .file "setjmp.s" 52*0a6a1f1dSLionel Sambuc 53*0a6a1f1dSLionel Sambuc#include <machine/asm.h> 54*0a6a1f1dSLionel SambucRCSID("$NetBSD: _setjmp.S,v 1.1 2015/04/17 12:51:05 martin Exp $"); 55*0a6a1f1dSLionel Sambuc 56*0a6a1f1dSLionel Sambuc#include <machine/setjmp.h> 57*0a6a1f1dSLionel Sambuc 58*0a6a1f1dSLionel Sambuc// int _setjmp(struct jmp_buffer *) 59*0a6a1f1dSLionel Sambuc// 60*0a6a1f1dSLionel Sambuc// Setup a non-local goto. 61*0a6a1f1dSLionel Sambuc// 62*0a6a1f1dSLionel Sambuc// Description: 63*0a6a1f1dSLionel Sambuc// 64*0a6a1f1dSLionel Sambuc// SetJump stores the current register set in the area pointed to 65*0a6a1f1dSLionel Sambuc// by "save". It returns zero. Subsequent calls to "LongJump" will 66*0a6a1f1dSLionel Sambuc// restore the registers and return non-zero to the same location. 67*0a6a1f1dSLionel Sambuc// 68*0a6a1f1dSLionel Sambuc// On entry, r32 contains the pointer to the jmp_buffer 69*0a6a1f1dSLionel Sambuc// 70*0a6a1f1dSLionel Sambuc 71*0a6a1f1dSLionel SambucENTRY(_setjmp, 1) 72*0a6a1f1dSLionel Sambuc add r10 = J_PREDS, r32 // skip Unats & pfs save area 73*0a6a1f1dSLionel Sambuc add r11 = J_BSP, r32 74*0a6a1f1dSLionel Sambuc // 75*0a6a1f1dSLionel Sambuc // save immediate context 76*0a6a1f1dSLionel Sambuc // 77*0a6a1f1dSLionel Sambuc mov r2 = ar.bsp // save backing store pointer 78*0a6a1f1dSLionel Sambuc mov r3 = pr // save predicates 79*0a6a1f1dSLionel Sambuc flushrs 80*0a6a1f1dSLionel Sambuc ;; 81*0a6a1f1dSLionel Sambuc // 82*0a6a1f1dSLionel Sambuc // save user Unat register 83*0a6a1f1dSLionel Sambuc // 84*0a6a1f1dSLionel Sambuc mov r16 = ar.lc // save loop count register 85*0a6a1f1dSLionel Sambuc mov r14 = ar.unat // save user Unat register 86*0a6a1f1dSLionel Sambuc 87*0a6a1f1dSLionel Sambuc st8 [r10] = r3, J_LC-J_PREDS 88*0a6a1f1dSLionel Sambuc st8 [r11] = r2, J_R4-J_BSP 89*0a6a1f1dSLionel Sambuc ;; 90*0a6a1f1dSLionel Sambuc st8 [r10] = r16, J_R5-J_LC 91*0a6a1f1dSLionel Sambuc st8 [r32] = r14, J_NATS // Note: Unat at the 92*0a6a1f1dSLionel Sambuc // beginning of the save area 93*0a6a1f1dSLionel Sambuc mov r15 = ar.pfs 94*0a6a1f1dSLionel Sambuc ;; 95*0a6a1f1dSLionel Sambuc // 96*0a6a1f1dSLionel Sambuc // save preserved general registers & NaT's 97*0a6a1f1dSLionel Sambuc // 98*0a6a1f1dSLionel Sambuc .mem.offset 0,0 99*0a6a1f1dSLionel Sambuc st8.spill [r11] = r4, J_R6-J_R4 100*0a6a1f1dSLionel Sambuc .mem.offset 8,0 101*0a6a1f1dSLionel Sambuc st8.spill [r10] = r5, J_R7-J_R5 102*0a6a1f1dSLionel Sambuc ;; 103*0a6a1f1dSLionel Sambuc .mem.offset 16,0 104*0a6a1f1dSLionel Sambuc st8.spill [r11] = r6, J_SP-J_R6 105*0a6a1f1dSLionel Sambuc .mem.offset 24,0 106*0a6a1f1dSLionel Sambuc st8.spill [r10] = r7, J_F3-J_R7 107*0a6a1f1dSLionel Sambuc ;; 108*0a6a1f1dSLionel Sambuc st8.spill [r11] = sp, J_F2-J_SP 109*0a6a1f1dSLionel Sambuc mov r16 = ar.rsc 110*0a6a1f1dSLionel Sambuc ;; 111*0a6a1f1dSLionel Sambuc // 112*0a6a1f1dSLionel Sambuc // save spilled Unat and pfs registers 113*0a6a1f1dSLionel Sambuc // 114*0a6a1f1dSLionel Sambuc mov r2 = ar.unat // save Unat register after spill 115*0a6a1f1dSLionel Sambuc mov ar.rsc = r0 116*0a6a1f1dSLionel Sambuc ;; 117*0a6a1f1dSLionel Sambuc st8 [r32] = r2, J_PFS-J_NATS // save unat for spilled regs 118*0a6a1f1dSLionel Sambuc mov r17 = ar.rnat 119*0a6a1f1dSLionel Sambuc ;; 120*0a6a1f1dSLionel Sambuc st8 [r32] = r15, J_RNAT-J_PFS // save pfs 121*0a6a1f1dSLionel Sambuc mov ar.rsc = r16 122*0a6a1f1dSLionel Sambuc // 123*0a6a1f1dSLionel Sambuc // save floating registers 124*0a6a1f1dSLionel Sambuc // 125*0a6a1f1dSLionel Sambuc stf.spill [r11] = f2, J_F4-J_F2 126*0a6a1f1dSLionel Sambuc stf.spill [r10] = f3, J_F5-J_F3 127*0a6a1f1dSLionel Sambuc ;; 128*0a6a1f1dSLionel Sambuc stf.spill [r11] = f4, J_F16-J_F4 129*0a6a1f1dSLionel Sambuc stf.spill [r10] = f5, J_F17-J_F5 130*0a6a1f1dSLionel Sambuc ;; 131*0a6a1f1dSLionel Sambuc stf.spill [r11] = f16, J_F18-J_F16 132*0a6a1f1dSLionel Sambuc stf.spill [r10] = f17, J_F19-J_F17 133*0a6a1f1dSLionel Sambuc ;; 134*0a6a1f1dSLionel Sambuc stf.spill [r11] = f18, J_F20-J_F18 135*0a6a1f1dSLionel Sambuc stf.spill [r10] = f19, J_F21-J_F19 136*0a6a1f1dSLionel Sambuc ;; 137*0a6a1f1dSLionel Sambuc stf.spill [r11] = f20, J_F22-J_F20 138*0a6a1f1dSLionel Sambuc stf.spill [r10] = f21, J_F23-J_F21 139*0a6a1f1dSLionel Sambuc ;; 140*0a6a1f1dSLionel Sambuc stf.spill [r11] = f22, J_F24-J_F22 141*0a6a1f1dSLionel Sambuc stf.spill [r10] = f23, J_F25-J_F23 142*0a6a1f1dSLionel Sambuc ;; 143*0a6a1f1dSLionel Sambuc stf.spill [r11] = f24, J_F26-J_F24 144*0a6a1f1dSLionel Sambuc stf.spill [r10] = f25, J_F27-J_F25 145*0a6a1f1dSLionel Sambuc ;; 146*0a6a1f1dSLionel Sambuc stf.spill [r11] = f26, J_F28-J_F26 147*0a6a1f1dSLionel Sambuc stf.spill [r10] = f27, J_F29-J_F27 148*0a6a1f1dSLionel Sambuc ;; 149*0a6a1f1dSLionel Sambuc stf.spill [r11] = f28, J_F30-J_F28 150*0a6a1f1dSLionel Sambuc stf.spill [r10] = f29, J_F31-J_F29 151*0a6a1f1dSLionel Sambuc ;; 152*0a6a1f1dSLionel Sambuc stf.spill [r11] = f30, J_FPSR-J_F30 153*0a6a1f1dSLionel Sambuc stf.spill [r10] = f31, J_B0-J_F31 // size of f31 + fpsr 154*0a6a1f1dSLionel Sambuc ;; 155*0a6a1f1dSLionel Sambuc st8 [r32] = r17 156*0a6a1f1dSLionel Sambuc // 157*0a6a1f1dSLionel Sambuc // save FPSR register & branch registers 158*0a6a1f1dSLionel Sambuc // 159*0a6a1f1dSLionel Sambuc mov r2 = ar.fpsr // save fpsr register 160*0a6a1f1dSLionel Sambuc mov r3 = b0 161*0a6a1f1dSLionel Sambuc ;; 162*0a6a1f1dSLionel Sambuc st8 [r11] = r2, J_B1-J_FPSR 163*0a6a1f1dSLionel Sambuc st8 [r10] = r3, J_B2-J_B0 164*0a6a1f1dSLionel Sambuc mov r2 = b1 165*0a6a1f1dSLionel Sambuc mov r3 = b2 166*0a6a1f1dSLionel Sambuc ;; 167*0a6a1f1dSLionel Sambuc st8 [r11] = r2, J_B3-J_B1 168*0a6a1f1dSLionel Sambuc st8 [r10] = r3, J_B4-J_B2 169*0a6a1f1dSLionel Sambuc mov r2 = b3 170*0a6a1f1dSLionel Sambuc mov r3 = b4 171*0a6a1f1dSLionel Sambuc ;; 172*0a6a1f1dSLionel Sambuc st8 [r11] = r2, J_B5-J_B3 173*0a6a1f1dSLionel Sambuc st8 [r10] = r3 174*0a6a1f1dSLionel Sambuc mov r2 = b5 175*0a6a1f1dSLionel Sambuc ;; 176*0a6a1f1dSLionel Sambuc st8 [r11] = r2 177*0a6a1f1dSLionel Sambuc ;; 178*0a6a1f1dSLionel Sambuc // 179*0a6a1f1dSLionel Sambuc // return 180*0a6a1f1dSLionel Sambuc // 181*0a6a1f1dSLionel Sambuc mov r8 = r0 // return 0 from setjmp 182*0a6a1f1dSLionel Sambuc mov ar.unat = r14 // restore unat 183*0a6a1f1dSLionel Sambuc br.ret.sptk b0 184*0a6a1f1dSLionel Sambuc 185*0a6a1f1dSLionel SambucEND(_setjmp) 186*0a6a1f1dSLionel Sambuc 187*0a6a1f1dSLionel Sambuc 188*0a6a1f1dSLionel Sambuc// 189*0a6a1f1dSLionel Sambuc// void _longjmp(struct jmp_buffer *, int val) 190*0a6a1f1dSLionel Sambuc// 191*0a6a1f1dSLionel Sambuc// Perform a non-local goto. 192*0a6a1f1dSLionel Sambuc// 193*0a6a1f1dSLionel Sambuc// Description: 194*0a6a1f1dSLionel Sambuc// 195*0a6a1f1dSLionel Sambuc// LongJump initializes the register set to the values saved by a 196*0a6a1f1dSLionel Sambuc// previous 'SetJump' and jumps to the return location saved by that 197*0a6a1f1dSLionel Sambuc// 'SetJump'. This has the effect of unwinding the stack and returning 198*0a6a1f1dSLionel Sambuc// for a second time to the 'SetJump'. 199*0a6a1f1dSLionel Sambuc// 200*0a6a1f1dSLionel Sambuc 201*0a6a1f1dSLionel SambucENTRY(_longjmp, 2) 202*0a6a1f1dSLionel Sambuc mov r14 = ar.rsc // get user RSC conf 203*0a6a1f1dSLionel Sambuc mov r8 = r33 // return value 204*0a6a1f1dSLionel Sambuc add r10 = J_PFS, r32 // get address of pfs 205*0a6a1f1dSLionel Sambuc ;; 206*0a6a1f1dSLionel Sambuc mov ar.rsc = r0 207*0a6a1f1dSLionel Sambuc add r11 = J_NATS, r32 208*0a6a1f1dSLionel Sambuc add r17 = J_RNAT, r32 209*0a6a1f1dSLionel Sambuc ;; 210*0a6a1f1dSLionel Sambuc ld8 r15 = [r10], J_BSP-J_PFS // get pfs 211*0a6a1f1dSLionel Sambuc ld8 r2 = [r11], J_LC-J_NATS // get unat for spilled regs 212*0a6a1f1dSLionel Sambuc mov r31 = r32 213*0a6a1f1dSLionel Sambuc ;; 214*0a6a1f1dSLionel Sambuc loadrs 215*0a6a1f1dSLionel Sambuc mov ar.unat = r2 216*0a6a1f1dSLionel Sambuc cmp.eq p6,p0=0,r8 // Return value 0? 217*0a6a1f1dSLionel Sambuc ;; 218*0a6a1f1dSLionel Sambuc ld8 r16 = [r10], J_PREDS-J_BSP // get backing store pointer 219*0a6a1f1dSLionel Sambuc ld8 r17 = [r17] // ar.rnat 220*0a6a1f1dSLionel Sambuc mov ar.pfs = r15 221*0a6a1f1dSLionel Sambuc ;; 222*0a6a1f1dSLionel Sambuc mov ar.bspstore = r16 223*0a6a1f1dSLionel Sambuc(p6) add r8 = 1, r0 224*0a6a1f1dSLionel Sambuc ;; 225*0a6a1f1dSLionel Sambuc mov ar.rnat = r17 226*0a6a1f1dSLionel Sambuc mov ar.rsc = r14 // restore RSC conf 227*0a6a1f1dSLionel Sambuc 228*0a6a1f1dSLionel Sambuc ld8 r3 = [r11], J_R4-J_LC // get lc register 229*0a6a1f1dSLionel Sambuc ld8 r2 = [r10], J_R5-J_PREDS // get predicates 230*0a6a1f1dSLionel Sambuc ;; 231*0a6a1f1dSLionel Sambuc mov pr = r2, -1 232*0a6a1f1dSLionel Sambuc mov ar.lc = r3 233*0a6a1f1dSLionel Sambuc // 234*0a6a1f1dSLionel Sambuc // restore preserved general registers & NaT's 235*0a6a1f1dSLionel Sambuc // 236*0a6a1f1dSLionel Sambuc ld8.fill r4 = [r11], J_R6-J_R4 237*0a6a1f1dSLionel Sambuc ;; 238*0a6a1f1dSLionel Sambuc ld8.fill r5 = [r10], J_R7-J_R5 239*0a6a1f1dSLionel Sambuc ld8.fill r6 = [r11], J_SP-J_R6 240*0a6a1f1dSLionel Sambuc ;; 241*0a6a1f1dSLionel Sambuc ld8.fill r7 = [r10], J_F2-J_R7 242*0a6a1f1dSLionel Sambuc ld8.fill sp = [r11], J_F3-J_SP 243*0a6a1f1dSLionel Sambuc ;; 244*0a6a1f1dSLionel Sambuc // 245*0a6a1f1dSLionel Sambuc // restore floating registers 246*0a6a1f1dSLionel Sambuc // 247*0a6a1f1dSLionel Sambuc ldf.fill f2 = [r10], J_F4-J_F2 248*0a6a1f1dSLionel Sambuc ldf.fill f3 = [r11], J_F5-J_F3 249*0a6a1f1dSLionel Sambuc ;; 250*0a6a1f1dSLionel Sambuc ldf.fill f4 = [r10], J_F16-J_F4 251*0a6a1f1dSLionel Sambuc ldf.fill f5 = [r11], J_F17-J_F5 252*0a6a1f1dSLionel Sambuc ;; 253*0a6a1f1dSLionel Sambuc ldf.fill f16 = [r10], J_F18-J_F16 254*0a6a1f1dSLionel Sambuc ldf.fill f17 = [r11], J_F19-J_F17 255*0a6a1f1dSLionel Sambuc ;; 256*0a6a1f1dSLionel Sambuc ldf.fill f18 = [r10], J_F20-J_F18 257*0a6a1f1dSLionel Sambuc ldf.fill f19 = [r11], J_F21-J_F19 258*0a6a1f1dSLionel Sambuc ;; 259*0a6a1f1dSLionel Sambuc ldf.fill f20 = [r10], J_F22-J_F20 260*0a6a1f1dSLionel Sambuc ldf.fill f21 = [r11], J_F23-J_F21 261*0a6a1f1dSLionel Sambuc ;; 262*0a6a1f1dSLionel Sambuc ldf.fill f22 = [r10], J_F24-J_F22 263*0a6a1f1dSLionel Sambuc ldf.fill f23 = [r11], J_F25-J_F23 264*0a6a1f1dSLionel Sambuc ;; 265*0a6a1f1dSLionel Sambuc ldf.fill f24 = [r10], J_F26-J_F24 266*0a6a1f1dSLionel Sambuc ldf.fill f25 = [r11], J_F27-J_F25 267*0a6a1f1dSLionel Sambuc ;; 268*0a6a1f1dSLionel Sambuc ldf.fill f26 = [r10], J_F28-J_F26 269*0a6a1f1dSLionel Sambuc ldf.fill f27 = [r11], J_F29-J_F27 270*0a6a1f1dSLionel Sambuc ;; 271*0a6a1f1dSLionel Sambuc ldf.fill f28 = [r10], J_F30-J_F28 272*0a6a1f1dSLionel Sambuc ldf.fill f29 = [r11], J_F31-J_F29 273*0a6a1f1dSLionel Sambuc ;; 274*0a6a1f1dSLionel Sambuc ldf.fill f30 = [r10], J_FPSR-J_F30 275*0a6a1f1dSLionel Sambuc ldf.fill f31 = [r11], J_B0-J_F31 ;; 276*0a6a1f1dSLionel Sambuc 277*0a6a1f1dSLionel Sambuc // 278*0a6a1f1dSLionel Sambuc // restore branch registers and fpsr 279*0a6a1f1dSLionel Sambuc // 280*0a6a1f1dSLionel Sambuc ld8 r16 = [r10], J_B1-J_FPSR // get fpsr 281*0a6a1f1dSLionel Sambuc ld8 r17 = [r11], J_B2-J_B0 // get return pointer 282*0a6a1f1dSLionel Sambuc ;; 283*0a6a1f1dSLionel Sambuc mov ar.fpsr = r16 284*0a6a1f1dSLionel Sambuc mov b0 = r17 285*0a6a1f1dSLionel Sambuc ld8 r2 = [r10], J_B3-J_B1 286*0a6a1f1dSLionel Sambuc ld8 r3 = [r11], J_B4-J_B2 287*0a6a1f1dSLionel Sambuc ;; 288*0a6a1f1dSLionel Sambuc mov b1 = r2 289*0a6a1f1dSLionel Sambuc mov b2 = r3 290*0a6a1f1dSLionel Sambuc ld8 r2 = [r10], J_B5-J_B3 291*0a6a1f1dSLionel Sambuc ld8 r3 = [r11] 292*0a6a1f1dSLionel Sambuc ;; 293*0a6a1f1dSLionel Sambuc mov b3 = r2 294*0a6a1f1dSLionel Sambuc mov b4 = r3 295*0a6a1f1dSLionel Sambuc ld8 r2 = [r10] 296*0a6a1f1dSLionel Sambuc ld8 r21 = [r31] // get user unat 297*0a6a1f1dSLionel Sambuc ;; 298*0a6a1f1dSLionel Sambuc mov b5 = r2 299*0a6a1f1dSLionel Sambuc mov ar.unat = r21 300*0a6a1f1dSLionel Sambuc 301*0a6a1f1dSLionel Sambuc // 302*0a6a1f1dSLionel Sambuc // invalidate ALAT 303*0a6a1f1dSLionel Sambuc // 304*0a6a1f1dSLionel Sambuc invala ;; 305*0a6a1f1dSLionel Sambuc 306*0a6a1f1dSLionel Sambuc br.ret.sptk b0 307*0a6a1f1dSLionel Sambuc 308*0a6a1f1dSLionel SambucEND(_longjmp) 309