Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / config / sh / linux-unwind.h
blob6ca9d56788665b74ebaac805fb5821904b00465b
1 /* DWARF2 EH unwinding support for SH 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 this program; see the file COPYING. If not, write to
26 the Free Software Foundation, 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, 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 #include <signal.h>
33 #include <sys/ucontext.h>
34 #include "insn-constants.h"
36 # if defined (__SH5__)
37 #define SH_DWARF_FRAME_GP0 0
38 #define SH_DWARF_FRAME_FP0 (__SH5__ == 32 ? 245 : 77)
39 #define SH_DWARF_FRAME_XD0 289
40 #define SH_DWARF_FRAME_BT0 68
41 #define SH_DWARF_FRAME_PR 241
42 #define SH_DWARF_FRAME_PR_MEDIA 18
43 #define SH_DWARF_FRAME_GBR 238
44 #define SH_DWARF_FRAME_MACH 239
45 #define SH_DWARF_FRAME_MACL 240
46 #define SH_DWARF_FRAME_PC 64
47 #define SH_DWARF_FRAME_SR 65
48 #define SH_DWARF_FRAME_FPUL 244
49 #define SH_DWARF_FRAME_FPSCR 243
50 #else
51 #define SH_DWARF_FRAME_GP0 0
52 #define SH_DWARF_FRAME_FP0 25
53 #define SH_DWARF_FRAME_XD0 87
54 #define SH_DWARF_FRAME_PR 17
55 #define SH_DWARF_FRAME_GBR 19
56 #define SH_DWARF_FRAME_MACH 20
57 #define SH_DWARF_FRAME_MACL 21
58 #define SH_DWARF_FRAME_PC 16
59 #define SH_DWARF_FRAME_SR 22
60 #define SH_DWARF_FRAME_FPUL 23
61 #define SH_DWARF_FRAME_FPSCR 24
62 #endif /* defined (__SH5__) */
64 #if defined (__SH5__)
65 /* MD_FALLBACK_FRAME_STATE_FOR is not yet defined for SHMEDIA. */
66 #else /* defined (__SH5__) */
68 #define MD_FALLBACK_FRAME_STATE_FOR sh_fallback_frame_state
70 static _Unwind_Reason_Code
71 sh_fallback_frame_state (struct _Unwind_Context *context,
72 _Unwind_FrameState *fs)
74 unsigned char *pc = context->ra;
75 struct sigcontext *sc;
76 long new_cfa;
77 int i;
78 #if defined (__SH3E__) || defined (__SH4__)
79 int r;
80 #endif
82 /* mov.w 1f,r3; trapa #0x10; 1: .short 0x77 (sigreturn) */
83 /* mov.w 1f,r3; trapa #0x10; 1: .short 0xad (rt_sigreturn) */
84 /* Newer kernel uses pad instructions to avoid an SH-4 core bug. */
85 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;
86 or r0,r0; 1: .short 0x77 (sigreturn) */
87 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;
88 or r0,r0; 1: .short 0xad (rt_sigreturn) */
89 if (((*(unsigned short *) (pc+0) == 0x9300)
90 && (*(unsigned short *) (pc+2) == 0xc310)
91 && (*(unsigned short *) (pc+4) == 0x0077))
92 || (((*(unsigned short *) (pc+0) == 0x9305)
93 && (*(unsigned short *) (pc+2) == 0xc310)
94 && (*(unsigned short *) (pc+14) == 0x0077))))
95 sc = context->cfa;
96 else if (((*(unsigned short *) (pc+0) == 0x9300)
97 && (*(unsigned short *) (pc+2) == 0xc310)
98 && (*(unsigned short *) (pc+4) == 0x00ad))
99 || (((*(unsigned short *) (pc+0) == 0x9305)
100 && (*(unsigned short *) (pc+2) == 0xc310)
101 && (*(unsigned short *) (pc+14) == 0x00ad))))
103 struct rt_sigframe {
104 struct siginfo info;
105 struct ucontext uc;
106 } *rt_ = context->cfa;
107 sc = (struct sigcontext *) &rt_->uc.uc_mcontext;
109 else
110 return _URC_END_OF_STACK;
112 new_cfa = sc->sc_regs[15];
113 fs->cfa_how = CFA_REG_OFFSET;
114 fs->cfa_reg = 15;
115 fs->cfa_offset = new_cfa - (long) context->cfa;
117 for (i = 0; i < 15; i++)
119 fs->regs.reg[i].how = REG_SAVED_OFFSET;
120 fs->regs.reg[i].loc.offset
121 = (long)&(sc->sc_regs[i]) - new_cfa;
124 fs->regs.reg[SH_DWARF_FRAME_PR].how = REG_SAVED_OFFSET;
125 fs->regs.reg[SH_DWARF_FRAME_PR].loc.offset
126 = (long)&(sc->sc_pr) - new_cfa;
127 fs->regs.reg[SH_DWARF_FRAME_SR].how = REG_SAVED_OFFSET;
128 fs->regs.reg[SH_DWARF_FRAME_SR].loc.offset
129 = (long)&(sc->sc_sr) - new_cfa;
130 fs->regs.reg[SH_DWARF_FRAME_GBR].how = REG_SAVED_OFFSET;
131 fs->regs.reg[SH_DWARF_FRAME_GBR].loc.offset
132 = (long)&(sc->sc_gbr) - new_cfa;
133 fs->regs.reg[SH_DWARF_FRAME_MACH].how = REG_SAVED_OFFSET;
134 fs->regs.reg[SH_DWARF_FRAME_MACH].loc.offset
135 = (long)&(sc->sc_mach) - new_cfa;
136 fs->regs.reg[SH_DWARF_FRAME_MACL].how = REG_SAVED_OFFSET;
137 fs->regs.reg[SH_DWARF_FRAME_MACL].loc.offset
138 = (long)&(sc->sc_macl) - new_cfa;
140 #if defined (__SH3E__) || defined (__SH4__)
141 r = SH_DWARF_FRAME_FP0;
142 for (i = 0; i < 16; i++)
144 fs->regs.reg[r+i].how = REG_SAVED_OFFSET;
145 fs->regs.reg[r+i].loc.offset
146 = (long)&(sc->sc_fpregs[i]) - new_cfa;
149 r = SH_DWARF_FRAME_XD0;
150 for (i = 0; i < 8; i++)
152 fs->regs.reg[i].how = REG_SAVED_OFFSET;
153 fs->regs.reg[i].loc.offset
154 = (long)&(sc->sc_xfpregs[2*i]) - new_cfa;
157 fs->regs.reg[SH_DWARF_FRAME_FPUL].how = REG_SAVED_OFFSET;
158 fs->regs.reg[SH_DWARF_FRAME_FPUL].loc.offset
159 = (long)&(sc->sc_fpul) - new_cfa;
160 fs->regs.reg[SH_DWARF_FRAME_FPSCR].how = REG_SAVED_OFFSET;
161 fs->regs.reg[SH_DWARF_FRAME_FPSCR].loc.offset
162 = (long)&(sc->sc_fpscr) - new_cfa;
163 #endif
165 fs->regs.reg[SH_DWARF_FRAME_PC].how = REG_SAVED_OFFSET;
166 fs->regs.reg[SH_DWARF_FRAME_PC].loc.offset
167 = (long)&(sc->sc_pc) - new_cfa;
168 fs->retaddr_column = SH_DWARF_FRAME_PC;
169 return _URC_NO_REASON;
171 #endif /* defined (__SH5__) */