]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ipf/setjmp.s
1098be83061b87492ba3e5119066eb3d6d9c91e3
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ipf / setjmp.s
1 /// @file
2 /// Contains an implementation of setjmp and longjmp for the
3 /// Itanium-based architecture.
4 ///
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
10 ///
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.
13 ///
14 /// Module Name: setjmp.s
15 ///
16 ///
17
18 .file "setjmp.s"
19
20 #include "asm.h"
21 #include "ia_64gen.h"
22
23 /// int SetJump(struct jmp_buffer save)
24 ///
25 /// Setup a non-local goto.
26 ///
27 /// Description:
28 ///
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.
32 ///
33 /// On entry, r32 contains the pointer to the jmp_buffer
34 ///
35
36 PROCEDURE_ENTRY(SetJump)
37 //
38 // Make sure buffer is aligned at 16byte boundary
39 //
40 mov r32 = r33
41
42 add r10 = -0x10,r0 ;; // mask the lower 4 bits
43 and r32 = r32, r10;;
44 add r32 = 0x10, r32;; // move to next 16 byte boundary
45
46 add r10 = J_PREDS, r32 // skip Unats & pfs save area
47 add r11 = J_BSP, r32
48 //
49 // save immediate context
50 //
51 mov r2 = ar.bsp // save backing store pointer
52 mov r3 = pr // save predicates
53 ;;
54 //
55 // save user Unat register
56 //
57 mov r16 = ar.lc // save loop count register
58 mov r14 = ar.unat // save user Unat register
59
60 st8 [r10] = r3, J_LC-J_PREDS
61 st8 [r11] = r2, J_R4-J_BSP
62 ;;
63 st8 [r10] = r16, J_R5-J_LC
64 st8 [r32] = r14, J_NATS // Note: Unat at the
65 // beginning of the save area
66 mov r15 = ar.pfs
67 ;;
68 //
69 // save preserved general registers & NaT's
70 //
71 st8.spill [r11] = r4, J_R6-J_R4
72 ;;
73 st8.spill [r10] = r5, J_R7-J_R5
74 ;;
75 st8.spill [r11] = r6, J_SP-J_R6
76 ;;
77 st8.spill [r10] = r7, J_F3-J_R7
78 ;;
79 st8.spill [r11] = sp, J_F2-J_SP
80 ;;
81 //
82 // save spilled Unat and pfs registers
83 //
84 mov r2 = ar.unat // save Unat register after spill
85 ;;
86 st8 [r32] = r2, J_PFS-J_NATS // save unat for spilled regs
87 ;;
88 st8 [r32] = r15 // save pfs
89 //
90 // save floating registers
91 //
92 stf.spill [r11] = f2, J_F4-J_F2
93 stf.spill [r10] = f3, J_F5-J_F3
94 ;;
95 stf.spill [r11] = f4, J_F16-J_F4
96 stf.spill [r10] = f5, J_F17-J_F5
97 ;;
98 stf.spill [r11] = f16, J_F18-J_F16
99 stf.spill [r10] = f17, J_F19-J_F17
100 ;;
101 stf.spill [r11] = f18, J_F20-J_F18
102 stf.spill [r10] = f19, J_F21-J_F19
103 ;;
104 stf.spill [r11] = f20, J_F22-J_F20
105 stf.spill [r10] = f21, J_F23-J_F21
106 ;;
107 stf.spill [r11] = f22, J_F24-J_F22
108 stf.spill [r10] = f23, J_F25-J_F23
109 ;;
110 stf.spill [r11] = f24, J_F26-J_F24
111 stf.spill [r10] = f25, J_F27-J_F25
112 ;;
113 stf.spill [r11] = f26, J_F28-J_F26
114 stf.spill [r10] = f27, J_F29-J_F27
115 ;;
116 stf.spill [r11] = f28, J_F30-J_F28
117 stf.spill [r10] = f29, J_F31-J_F29
118 ;;
119 stf.spill [r11] = f30, J_FPSR-J_F30
120 stf.spill [r10] = f31, J_B0-J_F31 // size of f31 + fpsr
121 //
122 // save FPSR register & branch registers
123 //
124 mov r2 = ar.fpsr // save fpsr register
125 mov r3 = b0
126 ;;
127 st8 [r11] = r2, J_B1-J_FPSR
128 st8 [r10] = r3, J_B2-J_B0
129 mov r2 = b1
130 mov r3 = b2
131 ;;
132 st8 [r11] = r2, J_B3-J_B1
133 st8 [r10] = r3, J_B4-J_B2
134 mov r2 = b3
135 mov r3 = b4
136 ;;
137 st8 [r11] = r2, J_B5-J_B3
138 st8 [r10] = r3
139 mov r2 = b5
140 ;;
141 st8 [r11] = r2
142 ;;
143 //
144 // return
145 //
146 mov r8 = r0 // return 0 from setjmp
147 mov ar.unat = r14 // restore unat
148 br.ret.sptk b0
149
150 PROCEDURE_EXIT(SetJump)
151
152
153 //
154 // void _LongJump(struct jmp_buffer *)
155 //
156 // Perform a non-local goto.
157 //
158 // Description:
159 //
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'.
164 //
165
166 PROCEDURE_ENTRY(_LongJump)
167 //
168 // Make sure buffer is aligned at 16byte boundary
169 //
170 mov r32 = r33
171
172 add r10 = -0x10,r0 ;; // mask the lower 4 bits
173 and r32 = r32, r10;;
174 add r32 = 0x10, r32;; // move to next 16 byte boundary
175
176 //
177 // caching the return value as we do invala in the end
178 //
179 /// mov r8 = r33 // return value
180 mov r8 = 1 // For now return hard coded 1
181
182 //
183 // get immediate context
184 //
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
188 ;;
189 ld8 r15 = [r10], J_BSP-J_PFS // get pfs
190 ld8 r2 = [r11], J_LC-J_NATS // get unat for spilled regs
191 ;;
192 mov ar.unat = r2
193 ;;
194 ld8 r16 = [r10], J_PREDS-J_BSP // get backing store pointer
195 mov ar.rsc = r0 // put RSE in enforced lazy
196 mov ar.pfs = r15
197 ;;
198
199 //
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.
204 //
205 mov r17 = ar.bspstore // get current BSPSTORE
206 ;;
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
210 ;;
211 loadrs // invalidate dirty regs
212 br.sptk.many .restore_rnat // restore RNAT
213
214 .flush_rse:
215 flushrs
216 ;;
217 mov r19 = ar.rnat // get current RNAT
218 mov r17 = r16 // current BSPSTORE
219 ;;
220 .restore_rnat:
221 //
222 // check if RNAT is saved between saved BSP and curr BSPSTORE
223 //
224 dep r18 = 1,r16,3,6 // get RNAT address
225 ;;
226 cmp.ltu p8,p9 = r18, r17 // RNAT saved on RSE
227 ;;
228 (p8) ld8 r19 = [r18] // get RNAT from RSE
229 ;;
230 mov ar.bspstore = r16 // set new BSPSTORE
231 ;;
232 mov ar.rnat = r19 // restore RNAT
233 mov ar.rsc = r14 // restore RSC conf
234
235
236 ld8 r3 = [r11], J_R4-J_LC // get lc register
237 ld8 r2 = [r10], J_R5-J_PREDS // get predicates
238 ;;
239 mov pr = r2, -1
240 mov ar.lc = r3
241 //
242 // restore preserved general registers & NaT's
243 //
244 ld8.fill r4 = [r11], J_R6-J_R4
245 ;;
246 ld8.fill r5 = [r10], J_R7-J_R5
247 ld8.fill r6 = [r11], J_SP-J_R6
248 ;;
249 ld8.fill r7 = [r10], J_F2-J_R7
250 ld8.fill sp = [r11], J_F3-J_SP
251 ;;
252 //
253 // restore floating registers
254 //
255 ldf.fill f2 = [r10], J_F4-J_F2
256 ldf.fill f3 = [r11], J_F5-J_F3
257 ;;
258 ldf.fill f4 = [r10], J_F16-J_F4
259 ldf.fill f5 = [r11], J_F17-J_F5
260 ;;
261 ldf.fill f16 = [r10], J_F18-J_F16
262 ldf.fill f17 = [r11], J_F19-J_F17
263 ;;
264 ldf.fill f18 = [r10], J_F20-J_F18
265 ldf.fill f19 = [r11], J_F21-J_F19
266 ;;
267 ldf.fill f20 = [r10], J_F22-J_F20
268 ldf.fill f21 = [r11], J_F23-J_F21
269 ;;
270 ldf.fill f22 = [r10], J_F24-J_F22
271 ldf.fill f23 = [r11], J_F25-J_F23
272 ;;
273 ldf.fill f24 = [r10], J_F26-J_F24
274 ldf.fill f25 = [r11], J_F27-J_F25
275 ;;
276 ldf.fill f26 = [r10], J_F28-J_F26
277 ldf.fill f27 = [r11], J_F29-J_F27
278 ;;
279 ldf.fill f28 = [r10], J_F30-J_F28
280 ldf.fill f29 = [r11], J_F31-J_F29
281 ;;
282 ldf.fill f30 = [r10], J_FPSR-J_F30
283 ldf.fill f31 = [r11], J_B0-J_F31 ;;
284
285 //
286 // restore branch registers and fpsr
287 //
288 ld8 r16 = [r10], J_B1-J_FPSR // get fpsr
289 ld8 r17 = [r11], J_B2-J_B0 // get return pointer
290 ;;
291 mov ar.fpsr = r16
292 mov b0 = r17
293 ld8 r2 = [r10], J_B3-J_B1
294 ld8 r3 = [r11], J_B4-J_B2
295 ;;
296 mov b1 = r2
297 mov b2 = r3
298 ld8 r2 = [r10], J_B5-J_B3
299 ld8 r3 = [r11]
300 ;;
301 mov b3 = r2
302 mov b4 = r3
303 ld8 r2 = [r10]
304 ld8 r21 = [r32] // get user unat
305 ;;
306 mov b5 = r2
307 mov ar.unat = r21
308
309 //
310 // invalidate ALAT
311 //
312 invala ;;
313
314 br.ret.sptk b0
315 PROCEDURE_EXIT(_LongJump)
316
317