2 /// Contains an implementation of setjmp and longjmp for the
3 /// Itanium-based architecture.
5 /// Copyright (c) 2006, Intel Corporation
6 /// All rights reserved. This program and the accompanying materials
7 /// are licensed and made available under the terms and conditions of the BSD License
8 /// which accompanies this distribution. The full text of the license may be found at
9 /// http://opensource.org/licenses/bsd-license.php
11 /// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 /// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 /// Module Name: setjmp.s
23 /// int SetJump(struct jmp_buffer save)
25 /// Setup a non-local goto.
29 /// SetJump stores the current register set in the area pointed to
30 /// by "save". It returns zero. Subsequent calls to "LongJump" will
31 /// restore the registers and return non-zero to the same location.
33 /// On entry, r32 contains the pointer to the jmp_buffer
36 PROCEDURE_ENTRY(SetJump)
38 // Make sure buffer is aligned at 16byte boundary
42 add r10 = -0x10,r0 ;; // mask the lower 4 bits
44 add r32 = 0x10, r32;; // move to next 16 byte boundary
46 add r10 = J_PREDS, r32 // skip Unats & pfs save area
49 // save immediate context
51 mov r2 = ar.bsp // save backing store pointer
52 mov r3 = pr // save predicates
55 // save user Unat register
57 mov r16 = ar.lc // save loop count register
58 mov r14 = ar.unat // save user Unat register
60 st8 [r10] = r3, J_LC-J_PREDS
61 st8 [r11] = r2, J_R4-J_BSP
63 st8 [r10] = r16, J_R5-J_LC
64 st8 [r32] = r14, J_NATS // Note: Unat at the
65 // beginning of the save area
69 // save preserved general registers & NaT's
71 st8.spill [r11] = r4, J_R6-J_R4
73 st8.spill [r10] = r5, J_R7-J_R5
75 st8.spill [r11] = r6, J_SP-J_R6
77 st8.spill [r10] = r7, J_F3-J_R7
79 st8.spill [r11] = sp, J_F2-J_SP
82 // save spilled Unat and pfs registers
84 mov r2 = ar.unat // save Unat register after spill
86 st8 [r32] = r2, J_PFS-J_NATS // save unat for spilled regs
88 st8 [r32] = r15 // save pfs
90 // save floating registers
92 stf.spill [r11] = f2, J_F4-J_F2
93 stf.spill [r10] = f3, J_F5-J_F3
95 stf.spill [r11] = f4, J_F16-J_F4
96 stf.spill [r10] = f5, J_F17-J_F5
98 stf.spill [r11] = f16, J_F18-J_F16
99 stf.spill [r10] = f17, J_F19-J_F17
101 stf.spill [r11] = f18, J_F20-J_F18
102 stf.spill [r10] = f19, J_F21-J_F19
104 stf.spill [r11] = f20, J_F22-J_F20
105 stf.spill [r10] = f21, J_F23-J_F21
107 stf.spill [r11] = f22, J_F24-J_F22
108 stf.spill [r10] = f23, J_F25-J_F23
110 stf.spill [r11] = f24, J_F26-J_F24
111 stf.spill [r10] = f25, J_F27-J_F25
113 stf.spill [r11] = f26, J_F28-J_F26
114 stf.spill [r10] = f27, J_F29-J_F27
116 stf.spill [r11] = f28, J_F30-J_F28
117 stf.spill [r10] = f29, J_F31-J_F29
119 stf.spill [r11] = f30, J_FPSR-J_F30
120 stf.spill [r10] = f31, J_B0-J_F31 // size of f31 + fpsr
122 // save FPSR register & branch registers
124 mov r2 = ar.fpsr // save fpsr register
127 st8 [r11] = r2, J_B1-J_FPSR
128 st8 [r10] = r3, J_B2-J_B0
132 st8 [r11] = r2, J_B3-J_B1
133 st8 [r10] = r3, J_B4-J_B2
137 st8 [r11] = r2, J_B5-J_B3
146 mov r8 = r0 // return 0 from setjmp
147 mov ar.unat = r14 // restore unat
150 PROCEDURE_EXIT(SetJump)
154 // void _LongJump(struct jmp_buffer *)
156 // Perform a non-local goto.
160 // LongJump initializes the register set to the values saved by a
161 // previous 'SetJump' and jumps to the return location saved by that
162 // 'SetJump'. This has the effect of unwinding the stack and returning
163 // for a second time to the 'SetJump'.
166 PROCEDURE_ENTRY(_LongJump)
168 // Make sure buffer is aligned at 16byte boundary
172 add r10 = -0x10,r0 ;; // mask the lower 4 bits
174 add r32 = 0x10, r32;; // move to next 16 byte boundary
177 // caching the return value as we do invala in the end
179 /// mov r8 = r33 // return value
180 mov r8 = 1 // For now return hard coded 1
183 // get immediate context
185 mov r14 = ar.rsc // get user RSC conf
186 add r10 = J_PFS, r32 // get address of pfs
187 add r11 = J_NATS, r32
189 ld8 r15 = [r10], J_BSP-J_PFS // get pfs
190 ld8 r2 = [r11], J_LC-J_NATS // get unat for spilled regs
194 ld8 r16 = [r10], J_PREDS-J_BSP // get backing store pointer
195 mov ar.rsc = r0 // put RSE in enforced lazy
200 // while returning from longjmp the BSPSTORE and BSP needs to be
201 // same and discard all the registers allocated after we did
202 // setjmp. Also, we need to generate the RNAT register since we
203 // did not flushed the RSE on setjmp.
205 mov r17 = ar.bspstore // get current BSPSTORE
207 cmp.ltu p6,p7 = r17, r16 // is it less than BSP of
208 (p6) br.spnt.few .flush_rse
209 mov r19 = ar.rnat // get current RNAT
211 loadrs // invalidate dirty regs
212 br.sptk.many .restore_rnat // restore RNAT
217 mov r19 = ar.rnat // get current RNAT
218 mov r17 = r16 // current BSPSTORE
222 // check if RNAT is saved between saved BSP and curr BSPSTORE
224 dep r18 = 1,r16,3,6 // get RNAT address
226 cmp.ltu p8,p9 = r18, r17 // RNAT saved on RSE
228 (p8) ld8 r19 = [r18] // get RNAT from RSE
230 mov ar.bspstore = r16 // set new BSPSTORE
232 mov ar.rnat = r19 // restore RNAT
233 mov ar.rsc = r14 // restore RSC conf
236 ld8 r3 = [r11], J_R4-J_LC // get lc register
237 ld8 r2 = [r10], J_R5-J_PREDS // get predicates
242 // restore preserved general registers & NaT's
244 ld8.fill r4 = [r11], J_R6-J_R4
246 ld8.fill r5 = [r10], J_R7-J_R5
247 ld8.fill r6 = [r11], J_SP-J_R6
249 ld8.fill r7 = [r10], J_F2-J_R7
250 ld8.fill sp = [r11], J_F3-J_SP
253 // restore floating registers
255 ldf.fill f2 = [r10], J_F4-J_F2
256 ldf.fill f3 = [r11], J_F5-J_F3
258 ldf.fill f4 = [r10], J_F16-J_F4
259 ldf.fill f5 = [r11], J_F17-J_F5
261 ldf.fill f16 = [r10], J_F18-J_F16
262 ldf.fill f17 = [r11], J_F19-J_F17
264 ldf.fill f18 = [r10], J_F20-J_F18
265 ldf.fill f19 = [r11], J_F21-J_F19
267 ldf.fill f20 = [r10], J_F22-J_F20
268 ldf.fill f21 = [r11], J_F23-J_F21
270 ldf.fill f22 = [r10], J_F24-J_F22
271 ldf.fill f23 = [r11], J_F25-J_F23
273 ldf.fill f24 = [r10], J_F26-J_F24
274 ldf.fill f25 = [r11], J_F27-J_F25
276 ldf.fill f26 = [r10], J_F28-J_F26
277 ldf.fill f27 = [r11], J_F29-J_F27
279 ldf.fill f28 = [r10], J_F30-J_F28
280 ldf.fill f29 = [r11], J_F31-J_F29
282 ldf.fill f30 = [r10], J_FPSR-J_F30
283 ldf.fill f31 = [r11], J_B0-J_F31 ;;
286 // restore branch registers and fpsr
288 ld8 r16 = [r10], J_B1-J_FPSR // get fpsr
289 ld8 r17 = [r11], J_B2-J_B0 // get return pointer
293 ld8 r2 = [r10], J_B3-J_B1
294 ld8 r3 = [r11], J_B4-J_B2
298 ld8 r2 = [r10], J_B5-J_B3
304 ld8 r21 = [r32] // get user unat
315 PROCEDURE_EXIT(_LongJump)