14cc2cf9159a8fad911ce55af76ce5f5cb253cec
[gcc.git] / gcc / config / pa / pa32-linux.h
1 /* Definitions for PA_RISC with ELF-32 format
2 Copyright (C) 2000, 2002 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21 /* Turn off various SOM crap we don't want. */
22 #undef TARGET_ELF32
23 #define TARGET_ELF32 1
24
25 /* The libcall __canonicalize_funcptr_for_compare is referenced in
26 crtend.o and the reference isn't resolved in objects that don't
27 compare function pointers. Thus, we need to play games to provide
28 a reference in crtbegin.o. The rest of the define is the same
29 as that in crtstuff.c */
30 #define CTOR_LIST_BEGIN \
31 asm (".type __canonicalize_funcptr_for_compare,@function\n" \
32 " .text\n" \
33 " .word __canonicalize_funcptr_for_compare-$PIC_pcrel$0"); \
34 STATIC func_ptr __CTOR_LIST__[1] \
35 __attribute__ ((__unused__, section(".ctors"), \
36 aligned(sizeof(func_ptr)))) \
37 = { (func_ptr) (-1) }
38
39 /* Do code reading to identify a signal frame, and set the frame
40 state data appropriately. See unwind-dw2.c for the structs. */
41
42 #ifdef IN_LIBGCC2
43 #include <signal.h>
44 #include <sys/ucontext.h>
45
46 /* Unfortunately, because of various bugs and changes to the kernel,
47 we have several cases to deal with.
48
49 In 2.4, the signal trampoline is 4 words, and (CONTEXT)->ra should
50 point directly at the beginning of the trampoline and struct rt_sigframe.
51
52 In <= 2.6.5-rc2-pa3, the signal trampoline is 9 words, and
53 (CONTEXT)->ra points at the 4th word in the trampoline structure. This
54 is wrong, it should point at the 5th word. This is fixed in 2.6.5-rc2-pa4.
55
56 To detect these cases, we first take (CONTEXT)->ra, align it to 64-bytes
57 to get the beginning of the signal frame, and then check offsets 0, 4
58 and 5 to see if we found the beginning of the trampoline. This will
59 tell us how to locate the sigcontext structure.
60
61 Note that with a 2.4 64-bit kernel, the signal context is not properly
62 passed back to userspace so the unwind will not work correctly. */
63 #define MD_FALLBACK_FRAME_STATE_FOR(CONTEXT, FS, SUCCESS) \
64 do { \
65 unsigned long sp = (unsigned long)(CONTEXT)->ra & ~63; \
66 unsigned int *pc = (unsigned int *)sp; \
67 unsigned long off; \
68 _Unwind_Ptr new_cfa; \
69 int i; \
70 struct sigcontext *sc; \
71 struct rt_sigframe { \
72 struct siginfo info; \
73 struct ucontext uc; \
74 } *frame; \
75 \
76 /* rt_sigreturn trampoline: \
77 3419000x ldi 0, %r25 or ldi 1, %r25 (x = 0 or 2) \
78 3414015a ldi __NR_rt_sigreturn, %r20 \
79 e4008200 be,l 0x100(%sr2, %r0), %sr0, %r31 \
80 08000240 nop */ \
81 \
82 if (pc[0] == 0x34190000 || pc[0] == 0x34190002) \
83 off = 4*4; \
84 else if (pc[4] == 0x34190000 || pc[4] == 0x34190002) \
85 { \
86 pc += 4; \
87 off = 10 * 4; \
88 } \
89 else if (pc[5] == 0x34190000 || pc[5] == 0x34190002) \
90 { \
91 pc += 5; \
92 off = 10 * 4; \
93 } \
94 else \
95 break; \
96 if (pc[1] != 0x3414015a \
97 || pc[2] != 0xe4008200 \
98 || pc[3] != 0x08000240) \
99 break; \
100 \
101 frame = (struct rt_sigframe *)(sp + off); \
102 sc = &frame->uc.uc_mcontext; \
103 \
104 new_cfa = sc->sc_gr[30]; \
105 (FS)->cfa_how = CFA_REG_OFFSET; \
106 (FS)->cfa_reg = 30; \
107 (FS)->cfa_offset = new_cfa - (long) (CONTEXT)->cfa; \
108 for (i = 1; i <= 31; i++) \
109 { \
110 (FS)->regs.reg[i].how = REG_SAVED_OFFSET; \
111 (FS)->regs.reg[i].loc.offset = (long)&sc->sc_gr[i] - new_cfa; \
112 } \
113 for (i = 4; i <= 31; i++) \
114 { \
115 /* FP regs have left and right halves */ \
116 (FS)->regs.reg[2*i+24].how = REG_SAVED_OFFSET; \
117 (FS)->regs.reg[2*i+24].loc.offset \
118 = (long)&sc->sc_fr[i] - new_cfa; \
119 (FS)->regs.reg[2*i+24+1].how = REG_SAVED_OFFSET; \
120 (FS)->regs.reg[2*i+24+1].loc.offset \
121 = (long)&sc->sc_fr[i] + 4 - new_cfa; \
122 } \
123 (FS)->regs.reg[88].how = REG_SAVED_OFFSET; \
124 (FS)->regs.reg[88].loc.offset = (long) &sc->sc_sar - new_cfa; \
125 (FS)->regs.reg[2].how = REG_SAVED_OFFSET; \
126 (FS)->regs.reg[2].loc.offset = (long) &sc->sc_iaoq[0] - new_cfa; \
127 (FS)->retaddr_column = 2; \
128 goto SUCCESS; \
129 } while (0)
130
131 #endif /* IN_LIBGCC2 */