2 * IA-64 specific setjmp/longjmp routines
4 * Inspired by setjmp.s from the FreeBSD kernel.
46 #define J_SIGMASK 0x1d8
47 #define J_SIGSET 0x1e0
50 // int setjmp(struct jmp_buffer *)
52 // Setup a non-local goto.
56 // SetJump stores the current register set in the area pointed to
57 // by "save". It returns zero. Subsequent calls to "LongJump" will
58 // restore the registers and return non-zero to the same location.
60 // On entry, r32 contains the pointer to the jmp_buffer
66 // Make sure buffer is aligned at 16byte boundary
68 add r10 = -0x10,r0 ;; // mask the lower 4 bits
70 add r32 = 0x10, r32;; // move to next 16 byte boundary
72 add r10 = J_PREDS, r32 // skip Unats & pfs save area
75 // save immediate context
77 mov r2 = ar.bsp // save backing store pointer
78 mov r3 = pr // save predicates
82 // save user Unat register
84 mov r16 = ar.lc // save loop count register
85 mov r14 = ar.unat // save user Unat register
87 st8 [r10] = r3, J_LC-J_PREDS
88 st8 [r11] = r2, J_R4-J_BSP
90 st8 [r10] = r16, J_R5-J_LC
91 st8 [r32] = r14, J_NATS // Note: Unat at the
92 // beginning of the save area
96 // save preserved general registers & NaT's
98 st8.spill [r11] = r4, J_R6-J_R4
100 st8.spill [r10] = r5, J_R7-J_R5
102 st8.spill [r11] = r6, J_SP-J_R6
104 st8.spill [r10] = r7, J_F3-J_R7
106 st8.spill [r11] = sp, J_F2-J_SP
109 // save spilled Unat and pfs registers
111 mov r2 = ar.unat // save Unat register after spill
113 st8 [r32] = r2, J_PFS-J_NATS // save unat for spilled regs
115 st8 [r32] = r15 // save pfs
117 // save floating registers
119 stf.spill [r11] = f2, J_F4-J_F2
120 stf.spill [r10] = f3, J_F5-J_F3
122 stf.spill [r11] = f4, J_F16-J_F4
123 stf.spill [r10] = f5, J_F17-J_F5
125 stf.spill [r11] = f16, J_F18-J_F16
126 stf.spill [r10] = f17, J_F19-J_F17
128 stf.spill [r11] = f18, J_F20-J_F18
129 stf.spill [r10] = f19, J_F21-J_F19
131 stf.spill [r11] = f20, J_F22-J_F20
132 stf.spill [r10] = f21, J_F23-J_F21
134 stf.spill [r11] = f22, J_F24-J_F22
135 stf.spill [r10] = f23, J_F25-J_F23
137 stf.spill [r11] = f24, J_F26-J_F24
138 stf.spill [r10] = f25, J_F27-J_F25
140 stf.spill [r11] = f26, J_F28-J_F26
141 stf.spill [r10] = f27, J_F29-J_F27
143 stf.spill [r11] = f28, J_F30-J_F28
144 stf.spill [r10] = f29, J_F31-J_F29
146 stf.spill [r11] = f30, J_FPSR-J_F30
147 stf.spill [r10] = f31, J_B0-J_F31 // size of f31 + fpsr
149 // save FPSR register & branch registers
151 mov r2 = ar.fpsr // save fpsr register
154 st8 [r11] = r2, J_B1-J_FPSR
155 st8 [r10] = r3, J_B2-J_B0
159 st8 [r11] = r2, J_B3-J_B1
160 st8 [r10] = r3, J_B4-J_B2
164 st8 [r11] = r2, J_B5-J_B3
173 mov r8 = r0 // return 0 from setjmp
174 mov ar.unat = r14 // restore unat
179 // void longjmp(struct jmp_buffer *, int val)
181 // Perform a non-local goto.
185 // LongJump initializes the register set to the values saved by a
186 // previous 'SetJump' and jumps to the return location saved by that
187 // 'SetJump'. This has the effect of unwinding the stack and returning
188 // for a second time to the 'SetJump'.
195 // Make sure buffer is aligned at 16byte boundary
197 add r10 = -0x10,r0 ;; // mask the lower 4 bits
199 add r32 = 0x10, r32;; // move to next 16 byte boundary
202 // caching the return value as we do invala in the end
204 mov r8 = r33 // return value
207 // get immediate context
209 mov r14 = ar.rsc // get user RSC conf
210 add r10 = J_PFS, r32 // get address of pfs
211 add r11 = J_NATS, r32
213 ld8 r15 = [r10], J_BSP-J_PFS // get pfs
214 ld8 r2 = [r11], J_LC-J_NATS // get unat for spilled regs
218 ld8 r16 = [r10], J_PREDS-J_BSP // get backing store pointer
219 mov ar.rsc = r0 // put RSE in enforced lazy
224 // while returning from longjmp the BSPSTORE and BSP needs to be
225 // same and discard all the registers allocated after we did
226 // setjmp. Also, we need to generate the RNAT register since we
227 // did not flushed the RSE on setjmp.
229 mov r17 = ar.bspstore // get current BSPSTORE
231 cmp.ltu p6,p7 = r17, r16 // is it less than BSP of
232 (p6) br.spnt.few .flush_rse
233 mov r19 = ar.rnat // get current RNAT
235 loadrs // invalidate dirty regs
236 br.sptk.many .restore_rnat // restore RNAT
241 mov r19 = ar.rnat // get current RNAT
242 mov r17 = r16 // current BSPSTORE
246 // check if RNAT is saved between saved BSP and curr BSPSTORE
250 dep r18 = r18,r16,3,6 // get RNAT address
252 cmp.ltu p8,p9 = r18, r17 // RNAT saved on RSE
254 (p8) ld8 r19 = [r18] // get RNAT from RSE
256 mov ar.bspstore = r16 // set new BSPSTORE
258 mov ar.rnat = r19 // restore RNAT
259 mov ar.rsc = r14 // restore RSC conf
262 ld8 r3 = [r11], J_R4-J_LC // get lc register
263 ld8 r2 = [r10], J_R5-J_PREDS // get predicates
268 // restore preserved general registers & NaT's
270 ld8.fill r4 = [r11], J_R6-J_R4
272 ld8.fill r5 = [r10], J_R7-J_R5
273 ld8.fill r6 = [r11], J_SP-J_R6
275 ld8.fill r7 = [r10], J_F2-J_R7
276 ld8.fill sp = [r11], J_F3-J_SP
279 // restore floating registers
281 ldf.fill f2 = [r10], J_F4-J_F2
282 ldf.fill f3 = [r11], J_F5-J_F3
284 ldf.fill f4 = [r10], J_F16-J_F4
285 ldf.fill f5 = [r11], J_F17-J_F5
287 ldf.fill f16 = [r10], J_F18-J_F16
288 ldf.fill f17 = [r11], J_F19-J_F17
290 ldf.fill f18 = [r10], J_F20-J_F18
291 ldf.fill f19 = [r11], J_F21-J_F19
293 ldf.fill f20 = [r10], J_F22-J_F20
294 ldf.fill f21 = [r11], J_F23-J_F21
296 ldf.fill f22 = [r10], J_F24-J_F22
297 ldf.fill f23 = [r11], J_F25-J_F23
299 ldf.fill f24 = [r10], J_F26-J_F24
300 ldf.fill f25 = [r11], J_F27-J_F25
302 ldf.fill f26 = [r10], J_F28-J_F26
303 ldf.fill f27 = [r11], J_F29-J_F27
305 ldf.fill f28 = [r10], J_F30-J_F28
306 ldf.fill f29 = [r11], J_F31-J_F29
308 ldf.fill f30 = [r10], J_FPSR-J_F30
309 ldf.fill f31 = [r11], J_B0-J_F31 ;;
312 // restore branch registers and fpsr
314 ld8 r16 = [r10], J_B1-J_FPSR // get fpsr
315 ld8 r17 = [r11], J_B2-J_B0 // get return pointer
319 ld8 r2 = [r10], J_B3-J_B1
320 ld8 r3 = [r11], J_B4-J_B2
324 ld8 r2 = [r10], J_B5-J_B3
330 ld8 r21 = [r32] // get user unat