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