1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2004-2005 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of libunwind.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 #define CALL_NEXT_PTR(gp_save_reg, arg0, arg1) \
29 ld8 r2 = [arg0], 8;; /* read the next function pointer */ \
30 ld8 r3 = [r2], 8;; /* read the function's entry-point */ \
31 ld8 r2 = [r2];; /* read the function's gp */ \
33 mov gp_save_reg = gp; \
37 br.call.sptk.many rp = b6;; \
40 #define CALL_NEXT(gp_save_reg) CALL_NEXT_PTR(gp_save_reg, in0, in1)
42 #define LOAD_VAL(reg) \
43 ld8 reg = [in1], 8;; \
44 tbit.nz p15, p0 = reg, 0;; \
45 (p15) ld8.s reg = [r0]
55 /* Save r4-r7 into stacked registers, load them up with the
56 values passed via the pointer in in1 and then call the
57 function passed via the pointer in in0. */
59 .global save_static_to_stacked
60 .proc save_static_to_stacked
61 save_static_to_stacked:
65 alloc loc0 = ar.pfs, 2, 7, 2, 0
91 .endp save_static_to_stacked
93 /* Save f2 to the memory stack, save r4 to f2, then load
94 r4 with the value passed via in1 and call the function
97 .global save_static_to_fr
98 .proc save_static_to_fr
103 alloc loc0 = ar.pfs, 2, 3, 2, 0
108 stf.spill [sp] = f2, -16
115 tbit.nz p6, p0 = r4, 0;;
120 getf.sig r4 = f2 // restore r4
123 ldf.fill f2 = [sp] // restore r2
128 .endp save_static_to_fr
130 /* If r4 is not a NaT, save b3 to a stacked register and
131 then save r4 in b3. The non-NaTness of r4 is saved in
134 .global save_static_to_br
135 .proc save_static_to_br
140 alloc loc0 = ar.pfs, 2, 6, 2, 0
145 mov loc2 = pr // save predicates
151 .spillreg.p p1, r4, b3
153 .spillreg.p p2, r4, loc4
161 .pred.rel.mutex p1, p2
162 (p1) mov r4 = b3 // restore r4
168 mov b3 = loc3 // restore b3
170 .endp save_static_to_br
172 /* Spill r4 into memory and then save r5 in r4. */
174 .global save_static_to_mem
175 .proc save_static_to_mem
180 alloc loc0 = ar.pfs, 2, 4, 2, 0
188 st8.spill [sp] = r4, -16
198 mov r5 = r4 // restore r5
201 ld8.fill r4 = [sp] // restore r4
205 mov ar.unat = loc2 // restore ar.unat
207 .endp save_static_to_mem
209 /* Spill r6 into memory and save primary ar.unat in a register. */
211 .global save_static_to_mem2
212 .proc save_static_to_mem2
217 alloc loc0 = ar.pfs, 2, 5, 2, 0
225 st8.spill [sp] = r6, -16;;
228 mov ar.unat = 0 // trash ar.unat
235 mov ar.unat = loc3 // restore primary UNaT
238 ld8.fill r6 = [sp] // restore r6
242 mov ar.unat = loc2 // restore ar.unat
244 .endp save_static_to_mem2
246 /* Spill r6 into memory and save primary ar.unat in memory. */
248 .global save_static_to_mem3
249 .proc save_static_to_mem3
254 alloc loc0 = ar.pfs, 2, 5, 2, 0
263 st8.spill [sp] = r6, -16;;
265 .savepsp @priunat, -8
267 mov ar.unat = 0 // trash ar.unat
276 mov ar.unat = r3 // restore primary UNaT
279 ld8.fill r6 = [sp] // restore r6
283 mov ar.unat = loc2 // restore ar.unat
285 .endp save_static_to_mem3
287 /* Spill r6 into memory and save primary ar.unat in register,
290 .global save_static_to_mem4
291 .proc save_static_to_mem4
296 alloc loc0 = ar.pfs, 2, 5, 2, 0
305 st8.spill [sp] = r6, -16;;
308 mov ar.unat = 0 // trash ar.unat
309 .savepsp @priunat, -8
311 mov r3 = r0 // trash register pri UNaT location
319 mov ar.unat = r3 // restore primary UNaT
322 ld8.fill r6 = [sp] // restore r6
326 mov ar.unat = loc2 // restore ar.unat
328 .endp save_static_to_mem4
330 /* Spill r6 into memory and save primary ar.unat in register,
333 .global save_static_to_mem5
334 .proc save_static_to_mem5
339 alloc loc0 = ar.pfs, 2, 5, 2, 0
348 st8.spill [sp] = r6, -16;;
350 mov ar.unat = 0 // trash ar.unat
351 .savepsp @priunat, -8
355 st8 [r2] = r0 // trash memory pri UNaT location
363 mov ar.unat = loc3 // restore primary UNaT
366 ld8.fill r6 = [sp] // restore r6
370 mov ar.unat = loc2 // restore ar.unat
372 .endp save_static_to_mem5
374 /* Save r4-r7 to various scratch registers, then trigger
377 .global save_static_to_scratch
378 .proc save_static_to_scratch
379 save_static_to_scratch:
383 mov r16 = r4 // save r4 in r16
384 tnat.nz p6, p7 = r5;;
385 .spillreg.p p6, r5, f31
386 (p6) setf.sig f31 = r5 // save r5 in f31 if it's a NaT
387 .spillreg.p p7, r5, b6
388 (p7) mov b6 = r5 // in b6 if it not
390 setf.sig f32 = r6 // save r6 in f32 (fph partition)
392 st8.spill [sp] = r7 // save r7 in the scratch stack space
407 /* Now force a SIGSEGV. Make sure the ld8 is at the beginning of a
408 bundle, so the signal-handler can skip over it simply by
409 incrementing the IP. */
419 .pred.rel.mutex p6, p7
420 (p6) getf.sig r5 = f31
426 .endp save_static_to_scratch
428 /* Rotate registers a bit in a vain attempt to sow some confusion.
429 Care must be taken not to write any rotating general register
430 after rotation, because we keep the preserved state
439 alloc loc0 = ar.pfs, 2, 14, 2, 16
459 // use p6 to preserve p63 as it gets rotated into p16:
460 (p16) cmp.eq.unc p6,p0 = r0,r0;;
462 (p6) cmp.eq.unc p16,p0 = r0,r0
463 (p63) cmp.eq.unc p6,p0 = r0,r0
464 br.ctop.dptk.few 1b;;
466 (p6) cmp.eq.unc p63,p0 = r0,r0
468 CALL_NEXT_PTR(r4, r8, r9)
487 alloc loc0 = ar.pfs, 2, 4, 2, 0
506 /* We do not need executable stack. */
507 .section .note.GNU-stack,"",@progbits