Merge with gcc-4_3-branch up to revision 175516.
[official-gcc.git] / gcc / config / pa / linux-unwind.h
blobc6fda5cd7b1584e6ec968961c6b62c2ff1f14c89
1 /* DWARF2 EH unwinding support for PA Linux.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file with other programs, and to distribute
14 those programs without any restriction coming from the use of this
15 file. (The General Public License restrictions do apply in other
16 respects; for example, they cover modification of the file, and
17 distribution when not linked into another program.)
19 GCC is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to
26 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27 Boston, MA 02110-1301, USA. */
29 /* Do code reading to identify a signal frame, and set the frame
30 state data appropriately. See unwind-dw2.c for the structs. */
32 /* Don't use this if inhibit_libc is set.
33 The build for this target will fail trying to include missing headers. */
34 #ifndef inhibit_libc
35 #include <signal.h>
36 #include <sys/ucontext.h>
38 /* Unfortunately, because of various bugs and changes to the kernel,
39 we have several cases to deal with.
41 In 2.4, the signal trampoline is 4 words, and (CONTEXT)->ra should
42 point directly at the beginning of the trampoline and struct rt_sigframe.
44 In <= 2.6.5-rc2-pa3, the signal trampoline is 9 words, and
45 (CONTEXT)->ra points at the 4th word in the trampoline structure. This
46 is wrong, it should point at the 5th word. This is fixed in 2.6.5-rc2-pa4.
48 To detect these cases, we first take (CONTEXT)->ra, align it to 64-bytes
49 to get the beginning of the signal frame, and then check offsets 0, 4
50 and 5 to see if we found the beginning of the trampoline. This will
51 tell us how to locate the sigcontext structure.
53 Note that with a 2.4 64-bit kernel, the signal context is not properly
54 passed back to userspace so the unwind will not work correctly. */
56 #define MD_FALLBACK_FRAME_STATE_FOR pa32_fallback_frame_state
58 static _Unwind_Reason_Code
59 pa32_fallback_frame_state (struct _Unwind_Context *context,
60 _Unwind_FrameState *fs)
62 unsigned long sp = (unsigned long)context->ra & ~63;
63 unsigned int *pc = (unsigned int *)sp;
64 unsigned long off;
65 _Unwind_Ptr new_cfa;
66 int i;
67 struct sigcontext *sc;
68 struct rt_sigframe {
69 struct siginfo info;
70 struct ucontext uc;
71 } *frame;
73 /* rt_sigreturn trampoline:
74 3419000x ldi 0, %r25 or ldi 1, %r25 (x = 0 or 2)
75 3414015a ldi __NR_rt_sigreturn, %r20
76 e4008200 be,l 0x100(%sr2, %r0), %sr0, %r31
77 08000240 nop */
79 if (pc[0] == 0x34190000 || pc[0] == 0x34190002)
80 off = 4*4;
81 else if (pc[4] == 0x34190000 || pc[4] == 0x34190002)
83 pc += 4;
84 off = 10 * 4;
86 else if (pc[5] == 0x34190000 || pc[5] == 0x34190002)
88 pc += 5;
89 off = 10 * 4;
91 else
93 /* We may have to unwind through an alternate signal stack.
94 We assume that the alignment of the alternate signal stack
95 is BIGGEST_ALIGNMENT (i.e., that it has been allocated using
96 malloc). As a result, we can't distinguish trampolines
97 used prior to 2.6.5-rc2-pa4. However after 2.6.5-rc2-pa4,
98 the return address of a signal trampoline will be on an odd
99 word boundary and we can then determine the frame offset. */
100 sp = (unsigned long)context->ra;
101 pc = (unsigned int *)sp;
102 if ((pc[0] == 0x34190000 || pc[0] == 0x34190002) && (sp & 4))
103 off = 5 * 4;
104 else
105 return _URC_END_OF_STACK;
108 if (pc[1] != 0x3414015a
109 || pc[2] != 0xe4008200
110 || pc[3] != 0x08000240)
111 return _URC_END_OF_STACK;
113 frame = (struct rt_sigframe *)(sp + off);
114 sc = &frame->uc.uc_mcontext;
116 new_cfa = sc->sc_gr[30];
117 fs->regs.cfa_how = CFA_REG_OFFSET;
118 fs->regs.cfa_reg = 30;
119 fs->regs.cfa_offset = new_cfa - (long) context->cfa;
120 for (i = 1; i <= 31; i++)
122 fs->regs.reg[i].how = REG_SAVED_OFFSET;
123 fs->regs.reg[i].loc.offset = (long)&sc->sc_gr[i] - new_cfa;
125 for (i = 4; i <= 31; i++)
127 /* FP regs have left and right halves */
128 fs->regs.reg[2*i+24].how = REG_SAVED_OFFSET;
129 fs->regs.reg[2*i+24].loc.offset
130 = (long)&sc->sc_fr[i] - new_cfa;
131 fs->regs.reg[2*i+24+1].how = REG_SAVED_OFFSET;
132 fs->regs.reg[2*i+24+1].loc.offset
133 = (long)&sc->sc_fr[i] + 4 - new_cfa;
135 fs->regs.reg[88].how = REG_SAVED_OFFSET;
136 fs->regs.reg[88].loc.offset = (long) &sc->sc_sar - new_cfa;
137 fs->regs.reg[DWARF_ALT_FRAME_RETURN_COLUMN].how = REG_SAVED_OFFSET;
138 fs->regs.reg[DWARF_ALT_FRAME_RETURN_COLUMN].loc.offset
139 = (long) &sc->sc_iaoq[0] - new_cfa;
140 fs->retaddr_column = DWARF_ALT_FRAME_RETURN_COLUMN;
141 fs->signal_frame = 1;
142 return _URC_NO_REASON;
144 #endif /* inhibit_libc */