Mercurial > hg > CbC > CbC_gcc
comparison gcc/config/i386/linux-unwind.h @ 0:a06113de4d67
first commit
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 14:47:48 +0900 |
parents | |
children | 77e2b8dfacca |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a06113de4d67 |
---|---|
1 /* DWARF2 EH unwinding support for AMD x86-64 and x86. | |
2 Copyright (C) 2004, 2005, 2006, 2009 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 3, 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 Under Section 7 of GPL version 3, you are granted additional | |
17 permissions described in the GCC Runtime Library Exception, version | |
18 3.1, as published by the Free Software Foundation. | |
19 | |
20 You should have received a copy of the GNU General Public License and | |
21 a copy of the GCC Runtime Library Exception along with this program; | |
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 <http://www.gnu.org/licenses/>. */ | |
24 | |
25 /* Do code reading to identify a signal frame, and set the frame | |
26 state data appropriately. See unwind-dw2.c for the structs. | |
27 Don't use this at all if inhibit_libc is used. */ | |
28 | |
29 #ifndef inhibit_libc | |
30 | |
31 #ifdef __x86_64__ | |
32 | |
33 #include <signal.h> | |
34 #include <sys/ucontext.h> | |
35 | |
36 #define MD_FALLBACK_FRAME_STATE_FOR x86_64_fallback_frame_state | |
37 | |
38 static _Unwind_Reason_Code | |
39 x86_64_fallback_frame_state (struct _Unwind_Context *context, | |
40 _Unwind_FrameState *fs) | |
41 { | |
42 unsigned char *pc = context->ra; | |
43 struct sigcontext *sc; | |
44 long new_cfa; | |
45 | |
46 /* movq __NR_rt_sigreturn, %rax ; syscall */ | |
47 if (*(unsigned char *)(pc+0) == 0x48 | |
48 && *(unsigned long *)(pc+1) == 0x050f0000000fc0c7) | |
49 { | |
50 struct ucontext *uc_ = context->cfa; | |
51 /* The void * cast is necessary to avoid an aliasing warning. | |
52 The aliasing warning is correct, but should not be a problem | |
53 because it does not alias anything. */ | |
54 sc = (struct sigcontext *) (void *) &uc_->uc_mcontext; | |
55 } | |
56 else | |
57 return _URC_END_OF_STACK; | |
58 | |
59 new_cfa = sc->rsp; | |
60 fs->regs.cfa_how = CFA_REG_OFFSET; | |
61 /* Register 7 is rsp */ | |
62 fs->regs.cfa_reg = 7; | |
63 fs->regs.cfa_offset = new_cfa - (long) context->cfa; | |
64 | |
65 /* The SVR4 register numbering macros aren't usable in libgcc. */ | |
66 fs->regs.reg[0].how = REG_SAVED_OFFSET; | |
67 fs->regs.reg[0].loc.offset = (long)&sc->rax - new_cfa; | |
68 fs->regs.reg[1].how = REG_SAVED_OFFSET; | |
69 fs->regs.reg[1].loc.offset = (long)&sc->rdx - new_cfa; | |
70 fs->regs.reg[2].how = REG_SAVED_OFFSET; | |
71 fs->regs.reg[2].loc.offset = (long)&sc->rcx - new_cfa; | |
72 fs->regs.reg[3].how = REG_SAVED_OFFSET; | |
73 fs->regs.reg[3].loc.offset = (long)&sc->rbx - new_cfa; | |
74 fs->regs.reg[4].how = REG_SAVED_OFFSET; | |
75 fs->regs.reg[4].loc.offset = (long)&sc->rsi - new_cfa; | |
76 fs->regs.reg[5].how = REG_SAVED_OFFSET; | |
77 fs->regs.reg[5].loc.offset = (long)&sc->rdi - new_cfa; | |
78 fs->regs.reg[6].how = REG_SAVED_OFFSET; | |
79 fs->regs.reg[6].loc.offset = (long)&sc->rbp - new_cfa; | |
80 fs->regs.reg[8].how = REG_SAVED_OFFSET; | |
81 fs->regs.reg[8].loc.offset = (long)&sc->r8 - new_cfa; | |
82 fs->regs.reg[9].how = REG_SAVED_OFFSET; | |
83 fs->regs.reg[9].loc.offset = (long)&sc->r9 - new_cfa; | |
84 fs->regs.reg[10].how = REG_SAVED_OFFSET; | |
85 fs->regs.reg[10].loc.offset = (long)&sc->r10 - new_cfa; | |
86 fs->regs.reg[11].how = REG_SAVED_OFFSET; | |
87 fs->regs.reg[11].loc.offset = (long)&sc->r11 - new_cfa; | |
88 fs->regs.reg[12].how = REG_SAVED_OFFSET; | |
89 fs->regs.reg[12].loc.offset = (long)&sc->r12 - new_cfa; | |
90 fs->regs.reg[13].how = REG_SAVED_OFFSET; | |
91 fs->regs.reg[13].loc.offset = (long)&sc->r13 - new_cfa; | |
92 fs->regs.reg[14].how = REG_SAVED_OFFSET; | |
93 fs->regs.reg[14].loc.offset = (long)&sc->r14 - new_cfa; | |
94 fs->regs.reg[15].how = REG_SAVED_OFFSET; | |
95 fs->regs.reg[15].loc.offset = (long)&sc->r15 - new_cfa; | |
96 fs->regs.reg[16].how = REG_SAVED_OFFSET; | |
97 fs->regs.reg[16].loc.offset = (long)&sc->rip - new_cfa; | |
98 fs->retaddr_column = 16; | |
99 fs->signal_frame = 1; | |
100 return _URC_NO_REASON; | |
101 } | |
102 | |
103 #else /* ifdef __x86_64__ */ | |
104 | |
105 /* There's no sys/ucontext.h for glibc 2.0, so no | |
106 signal-turned-exceptions for them. There's also no configure-run for | |
107 the target, so we can't check on (e.g.) HAVE_SYS_UCONTEXT_H. Using the | |
108 target libc version macro should be enough. */ | |
109 #if !(__GLIBC__ == 2 && __GLIBC_MINOR__ == 0) | |
110 | |
111 #include <signal.h> | |
112 #include <sys/ucontext.h> | |
113 | |
114 #define MD_FALLBACK_FRAME_STATE_FOR x86_fallback_frame_state | |
115 | |
116 static _Unwind_Reason_Code | |
117 x86_fallback_frame_state (struct _Unwind_Context *context, | |
118 _Unwind_FrameState *fs) | |
119 { | |
120 unsigned char *pc = context->ra; | |
121 struct sigcontext *sc; | |
122 long new_cfa; | |
123 | |
124 /* popl %eax ; movl $__NR_sigreturn,%eax ; int $0x80 */ | |
125 if (*(unsigned short *)(pc+0) == 0xb858 | |
126 && *(unsigned int *)(pc+2) == 119 | |
127 && *(unsigned short *)(pc+6) == 0x80cd) | |
128 sc = context->cfa + 4; | |
129 /* movl $__NR_rt_sigreturn,%eax ; int $0x80 */ | |
130 else if (*(unsigned char *)(pc+0) == 0xb8 | |
131 && *(unsigned int *)(pc+1) == 173 | |
132 && *(unsigned short *)(pc+5) == 0x80cd) | |
133 { | |
134 struct rt_sigframe { | |
135 int sig; | |
136 struct siginfo *pinfo; | |
137 void *puc; | |
138 struct siginfo info; | |
139 struct ucontext uc; | |
140 } *rt_ = context->cfa; | |
141 /* The void * cast is necessary to avoid an aliasing warning. | |
142 The aliasing warning is correct, but should not be a problem | |
143 because it does not alias anything. */ | |
144 sc = (struct sigcontext *) (void *) &rt_->uc.uc_mcontext; | |
145 } | |
146 else | |
147 return _URC_END_OF_STACK; | |
148 | |
149 new_cfa = sc->REG_NAME(esp); | |
150 fs->regs.cfa_how = CFA_REG_OFFSET; | |
151 fs->regs.cfa_reg = 4; | |
152 fs->regs.cfa_offset = new_cfa - (long) context->cfa; | |
153 | |
154 /* The SVR4 register numbering macros aren't usable in libgcc. */ | |
155 fs->regs.reg[0].how = REG_SAVED_OFFSET; | |
156 fs->regs.reg[0].loc.offset = (long)&sc->REG_NAME(eax) - new_cfa; | |
157 fs->regs.reg[3].how = REG_SAVED_OFFSET; | |
158 fs->regs.reg[3].loc.offset = (long)&sc->REG_NAME(ebx) - new_cfa; | |
159 fs->regs.reg[1].how = REG_SAVED_OFFSET; | |
160 fs->regs.reg[1].loc.offset = (long)&sc->REG_NAME(ecx) - new_cfa; | |
161 fs->regs.reg[2].how = REG_SAVED_OFFSET; | |
162 fs->regs.reg[2].loc.offset = (long)&sc->REG_NAME(edx) - new_cfa; | |
163 fs->regs.reg[6].how = REG_SAVED_OFFSET; | |
164 fs->regs.reg[6].loc.offset = (long)&sc->REG_NAME(esi) - new_cfa; | |
165 fs->regs.reg[7].how = REG_SAVED_OFFSET; | |
166 fs->regs.reg[7].loc.offset = (long)&sc->REG_NAME(edi) - new_cfa; | |
167 fs->regs.reg[5].how = REG_SAVED_OFFSET; | |
168 fs->regs.reg[5].loc.offset = (long)&sc->REG_NAME(ebp) - new_cfa; | |
169 fs->regs.reg[8].how = REG_SAVED_OFFSET; | |
170 fs->regs.reg[8].loc.offset = (long)&sc->REG_NAME(eip) - new_cfa; | |
171 fs->retaddr_column = 8; | |
172 fs->signal_frame = 1; | |
173 return _URC_NO_REASON; | |
174 } | |
175 #endif /* not glibc 2.0 */ | |
176 #endif /* ifdef __x86_64__ */ | |
177 #endif /* ifdef inhibit_libc */ |