2 // Copyright (c) 2004, Intel Corporation
3 // All rights reserved. This program and the accompanying materials
4 // are licensed and made available under the terms and conditions of the BSD License
5 // which accompanies this distribution. The full text of the license may be found at
6 // http://opensource.org/licenses/bsd-license.php
8 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 // Contains an implementation of setjmp and longjmp for the
18 // Itanium-based architecture.
31 // int SetJump(struct jmp_buffer save)
33 // Setup a non-local goto.
37 // SetJump stores the current register set in the area pointed to
38 // by "save". It returns zero. Subsequent calls to "LongJump" will
39 // restore the registers and return non-zero to the same location.
41 // On entry, r32 contains the pointer to the jmp_buffer
44 PROCEDURE_ENTRY(SetJump)
46 // Make sure buffer is aligned at 16byte boundary
50 add r10 = -0x10,r0 ;; // mask the lower 4 bits
52 add r32 = 0x10, r32;; // move to next 16 byte boundary
54 add r10 = J_PREDS, r32 // skip Unats & pfs save area
57 // save immediate context
59 mov r2 = ar.bsp // save backing store pointer
60 mov r3 = pr // save predicates
63 // save user Unat register
65 mov r16 = ar.lc // save loop count register
66 mov r14 = ar.unat // save user Unat register
68 st8 [r10] = r3, J_LC-J_PREDS
69 st8 [r11] = r2, J_R4-J_BSP
71 st8 [r10] = r16, J_R5-J_LC
72 st8 [r32] = r14, J_NATS // Note: Unat at the
73 // beginning of the save area
77 // save preserved general registers & NaT's
79 st8.spill [r11] = r4, J_R6-J_R4
81 st8.spill [r10] = r5, J_R7-J_R5
83 st8.spill [r11] = r6, J_SP-J_R6
85 st8.spill [r10] = r7, J_F3-J_R7
87 st8.spill [r11] = sp, J_F2-J_SP
90 // save spilled Unat and pfs registers
92 mov r2 = ar.unat // save Unat register after spill
94 st8 [r32] = r2, J_PFS-J_NATS // save unat for spilled regs
96 st8 [r32] = r15 // save pfs
98 // save floating registers
100 stf.spill [r11] = f2, J_F4-J_F2
101 stf.spill [r10] = f3, J_F5-J_F3
103 stf.spill [r11] = f4, J_F16-J_F4
104 stf.spill [r10] = f5, J_F17-J_F5
106 stf.spill [r11] = f16, J_F18-J_F16
107 stf.spill [r10] = f17, J_F19-J_F17
109 stf.spill [r11] = f18, J_F20-J_F18
110 stf.spill [r10] = f19, J_F21-J_F19
112 stf.spill [r11] = f20, J_F22-J_F20
113 stf.spill [r10] = f21, J_F23-J_F21
115 stf.spill [r11] = f22, J_F24-J_F22
116 stf.spill [r10] = f23, J_F25-J_F23
118 stf.spill [r11] = f24, J_F26-J_F24
119 stf.spill [r10] = f25, J_F27-J_F25
121 stf.spill [r11] = f26, J_F28-J_F26
122 stf.spill [r10] = f27, J_F29-J_F27
124 stf.spill [r11] = f28, J_F30-J_F28
125 stf.spill [r10] = f29, J_F31-J_F29
127 stf.spill [r11] = f30, J_FPSR-J_F30
128 stf.spill [r10] = f31, J_B0-J_F31 // size of f31 + fpsr
130 // save FPSR register & branch registers
132 mov r2 = ar.fpsr // save fpsr register
135 st8 [r11] = r2, J_B1-J_FPSR
136 st8 [r10] = r3, J_B2-J_B0
140 st8 [r11] = r2, J_B3-J_B1
141 st8 [r10] = r3, J_B4-J_B2
145 st8 [r11] = r2, J_B5-J_B3
154 mov r8 = r0 // return 0 from setjmp
155 mov ar.unat = r14 // restore unat
158 PROCEDURE_EXIT(SetJump)
162 // void LongJump(struct jmp_buffer *)
164 // Perform a non-local goto.
168 // LongJump initializes the register set to the values saved by a
169 // previous 'SetJump' and jumps to the return location saved by that
170 // 'SetJump'. This has the effect of unwinding the stack and returning
171 // for a second time to the 'SetJump'.
174 PROCEDURE_ENTRY(LongJump)
176 // Make sure buffer is aligned at 16byte boundary
180 add r10 = -0x10,r0 ;; // mask the lower 4 bits
182 add r32 = 0x10, r32;; // move to next 16 byte boundary
185 // caching the return value as we do invala in the end
187 /// mov r8 = r33 // return value
188 mov r8 = 1 // For now return hard coded 1
191 // get immediate context
193 mov r14 = ar.rsc // get user RSC conf
194 add r10 = J_PFS, r32 // get address of pfs
195 add r11 = J_NATS, r32
197 ld8 r15 = [r10], J_BSP-J_PFS // get pfs
198 ld8 r2 = [r11], J_LC-J_NATS // get unat for spilled regs
202 ld8 r16 = [r10], J_PREDS-J_BSP // get backing store pointer
203 mov ar.rsc = r0 // put RSE in enforced lazy
208 // while returning from longjmp the BSPSTORE and BSP needs to be
209 // same and discard all the registers allocated after we did
210 // setjmp. Also, we need to generate the RNAT register since we
211 // did not flushed the RSE on setjmp.
213 mov r17 = ar.bspstore // get current BSPSTORE
215 cmp.ltu p6,p7 = r17, r16 // is it less than BSP of
216 (p6) br.spnt.few .flush_rse
217 mov r19 = ar.rnat // get current RNAT
219 loadrs // invalidate dirty regs
220 br.sptk.many .restore_rnat // restore RNAT
225 mov r19 = ar.rnat // get current RNAT
226 mov r17 = r16 // current BSPSTORE
230 // check if RNAT is saved between saved BSP and curr BSPSTORE
232 dep r18 = 1,r16,3,6 // get RNAT address
234 cmp.ltu p8,p9 = r18, r17 // RNAT saved on RSE
236 (p8) ld8 r19 = [r18] // get RNAT from RSE
238 mov ar.bspstore = r16 // set new BSPSTORE
240 mov ar.rnat = r19 // restore RNAT
241 mov ar.rsc = r14 // restore RSC conf
244 ld8 r3 = [r11], J_R4-J_LC // get lc register
245 ld8 r2 = [r10], J_R5-J_PREDS // get predicates
250 // restore preserved general registers & NaT's
252 ld8.fill r4 = [r11], J_R6-J_R4
254 ld8.fill r5 = [r10], J_R7-J_R5
255 ld8.fill r6 = [r11], J_SP-J_R6
257 ld8.fill r7 = [r10], J_F2-J_R7
258 ld8.fill sp = [r11], J_F3-J_SP
261 // restore floating registers
263 ldf.fill f2 = [r10], J_F4-J_F2
264 ldf.fill f3 = [r11], J_F5-J_F3
266 ldf.fill f4 = [r10], J_F16-J_F4
267 ldf.fill f5 = [r11], J_F17-J_F5
269 ldf.fill f16 = [r10], J_F18-J_F16
270 ldf.fill f17 = [r11], J_F19-J_F17
272 ldf.fill f18 = [r10], J_F20-J_F18
273 ldf.fill f19 = [r11], J_F21-J_F19
275 ldf.fill f20 = [r10], J_F22-J_F20
276 ldf.fill f21 = [r11], J_F23-J_F21
278 ldf.fill f22 = [r10], J_F24-J_F22
279 ldf.fill f23 = [r11], J_F25-J_F23
281 ldf.fill f24 = [r10], J_F26-J_F24
282 ldf.fill f25 = [r11], J_F27-J_F25
284 ldf.fill f26 = [r10], J_F28-J_F26
285 ldf.fill f27 = [r11], J_F29-J_F27
287 ldf.fill f28 = [r10], J_F30-J_F28
288 ldf.fill f29 = [r11], J_F31-J_F29
290 ldf.fill f30 = [r10], J_FPSR-J_F30
291 ldf.fill f31 = [r11], J_B0-J_F31 ;;
294 // restore branch registers and fpsr
296 ld8 r16 = [r10], J_B1-J_FPSR // get fpsr
297 ld8 r17 = [r11], J_B2-J_B0 // get return pointer
301 ld8 r2 = [r10], J_B3-J_B1
302 ld8 r3 = [r11], J_B4-J_B2
306 ld8 r2 = [r10], J_B5-J_B3
312 ld8 r21 = [r32] // get user unat
323 PROCEDURE_EXIT(LongJump)