OSDN Git Service

e2bad480b7250690c8aef14c62bfeb52e416711b
[pf3gnuchains/gcc-fork.git] / gcc / config / ia64 / linux-unwind.h
1 /* DWARF2 EH unwinding support for IA64 Linux.
2    Copyright (C) 2004, 2005, 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 it
7    under the terms of the GNU General Public License as published
8    by the Free Software Foundation; either version 3, or (at your
9    option) any later version.
10
11    GCC is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
14    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
28 /* This works only for glibc-2.3 and later, because sigcontext is different
29    in glibc-2.2.4.  */
30
31 #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)
32 #include <signal.h>
33 #include <sys/ucontext.h>
34
35 #define IA64_GATE_AREA_START 0xa000000000000100LL
36 #define IA64_GATE_AREA_END   0xa000000000030000LL
37
38 #define MD_FALLBACK_FRAME_STATE_FOR ia64_fallback_frame_state
39
40 static _Unwind_Reason_Code
41 ia64_fallback_frame_state (struct _Unwind_Context *context,
42                            _Unwind_FrameState *fs)
43 {
44   if (context->rp >= IA64_GATE_AREA_START
45       && context->rp < IA64_GATE_AREA_END)
46     {
47       struct sigframe {
48         char scratch[16];
49         unsigned long sig_number;
50         struct siginfo *info;
51         struct sigcontext *sc;
52       } *frame_ = (struct sigframe *)context->psp;
53       struct sigcontext *sc = frame_->sc;
54
55       /* Restore scratch registers in case the unwinder needs to
56          refer to a value stored in one of them.  */
57       {
58         int i;
59
60         for (i = 2; i < 4; i++)
61           context->ireg[i - 2].loc = &sc->sc_gr[i];
62         for (i = 8; i < 12; i++)
63           context->ireg[i - 2].loc = &sc->sc_gr[i];
64         for (i = 14; i < 32; i++)
65           context->ireg[i - 2].loc = &sc->sc_gr[i];
66       }
67
68       context->fpsr_loc = &(sc->sc_ar_fpsr);
69       context->pfs_loc = &(sc->sc_ar_pfs);
70       context->lc_loc = &(sc->sc_ar_lc);
71       context->unat_loc = &(sc->sc_ar_unat);
72       context->br_loc[0] = &(sc->sc_br[0]);
73       context->br_loc[6] = &(sc->sc_br[6]);
74       context->br_loc[7] = &(sc->sc_br[7]);
75       context->pr = sc->sc_pr;
76       context->psp = sc->sc_gr[12];
77       context->gp = sc->sc_gr[1];
78       /* Signal frame doesn't have an associated reg. stack frame
79          other than what we adjust for below.     */
80       fs -> no_reg_stack_frame = 1;
81
82       if (sc->sc_rbs_base)
83         {
84           /* Need to switch from alternate register backing store.  */
85           long ndirty, loadrs = sc->sc_loadrs >> 16;
86           unsigned long alt_bspstore = context->bsp - loadrs;
87           unsigned long bspstore;
88           unsigned long *ar_bsp = (unsigned long *)(sc->sc_ar_bsp);
89
90           ndirty = ia64_rse_num_regs ((unsigned long *) alt_bspstore,
91                                       (unsigned long *) context->bsp);
92           bspstore = (unsigned long)
93             ia64_rse_skip_regs (ar_bsp, -ndirty);
94           ia64_copy_rbs (context, bspstore, alt_bspstore, loadrs,
95                          sc->sc_ar_rnat);
96         }
97
98       /* Don't touch the branch registers o.t. b0, b6 and b7.
99          The kernel doesn't pass the preserved branch registers
100          in the sigcontext but leaves them intact, so there's no
101          need to do anything with them here.  */
102       {
103         unsigned long sof = sc->sc_cfm & 0x7f;
104         context->bsp = (unsigned long)
105           ia64_rse_skip_regs ((unsigned long *)(sc->sc_ar_bsp), -sof);
106       }
107
108       fs->curr.reg[UNW_REG_RP].where = UNW_WHERE_SPREL;
109       fs->curr.reg[UNW_REG_RP].val
110         = (unsigned long)&(sc->sc_ip) - context->psp;
111       fs->curr.reg[UNW_REG_RP].when = -1;
112
113       return _URC_NO_REASON;
114     }
115   return _URC_END_OF_STACK;
116 }
117
118 #define MD_HANDLE_UNWABI ia64_handle_unwabi
119
120 static void
121 ia64_handle_unwabi (struct _Unwind_Context *context, _Unwind_FrameState *fs)
122 {
123   if (fs->unwabi == ((3 << 8) | 's')
124       || fs->unwabi == ((0 << 8) | 's'))
125     {
126       struct sigframe {
127         char scratch[16];
128         unsigned long sig_number;
129         struct siginfo *info;
130         struct sigcontext *sc;
131       } *frame = (struct sigframe *)context->psp;
132       struct sigcontext *sc = frame->sc;
133
134       /* Restore scratch registers in case the unwinder needs to
135          refer to a value stored in one of them.  */
136       {
137         int i;
138
139         for (i = 2; i < 4; i++)
140           context->ireg[i - 2].loc = &sc->sc_gr[i];
141         for (i = 8; i < 12; i++)
142           context->ireg[i - 2].loc = &sc->sc_gr[i];
143         for (i = 14; i < 32; i++)
144           context->ireg[i - 2].loc = &sc->sc_gr[i];
145       }
146
147       context->pfs_loc = &(sc->sc_ar_pfs);
148       context->lc_loc = &(sc->sc_ar_lc);
149       context->unat_loc = &(sc->sc_ar_unat);
150       context->br_loc[0] = &(sc->sc_br[0]);
151       context->br_loc[6] = &(sc->sc_br[6]);
152       context->br_loc[7] = &(sc->sc_br[7]);
153       context->pr = sc->sc_pr;
154       context->gp = sc->sc_gr[1];
155       /* Signal frame doesn't have an associated reg. stack frame
156          other than what we adjust for below.     */
157       fs -> no_reg_stack_frame = 1;
158
159       if (sc->sc_rbs_base)
160         {
161           /* Need to switch from alternate register backing store.  */
162           long ndirty, loadrs = sc->sc_loadrs >> 16;
163           unsigned long alt_bspstore = context->bsp - loadrs;
164           unsigned long bspstore;
165           unsigned long *ar_bsp = (unsigned long *)(sc->sc_ar_bsp);
166
167           ndirty = ia64_rse_num_regs ((unsigned long *) alt_bspstore,
168                                       (unsigned long *) context->bsp);
169           bspstore = (unsigned long) ia64_rse_skip_regs (ar_bsp, -ndirty);
170           ia64_copy_rbs (context, bspstore, alt_bspstore, loadrs,
171                          sc->sc_ar_rnat);
172         }
173
174       /* Don't touch the branch registers o.t. b0, b6 and b7.
175          The kernel doesn't pass the preserved branch registers
176          in the sigcontext but leaves them intact, so there's no
177          need to do anything with them here.  */
178       {
179         unsigned long sof = sc->sc_cfm & 0x7f;
180         context->bsp = (unsigned long)
181           ia64_rse_skip_regs ((unsigned long *)(sc->sc_ar_bsp), -sof);
182       }
183
184       /* pfs_loc already set above.  Without this pfs_loc would point
185          incorrectly to sc_cfm instead of sc_ar_pfs.  */
186       fs->curr.reg[UNW_REG_PFS].where = UNW_WHERE_NONE;
187     }
188 }
189 #endif /* glibc-2.3 or better */