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