OSDN Git Service

* config/m68k/m68k.c (sched_attr_op_type): Handle all CONSTs.
[pf3gnuchains/gcc-fork.git] / gcc / config / m68k / linux-unwind.h
1 /* DWARF2 EH unwinding support for Linux/m68k.
2    Copyright (C) 2006 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 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.)
18
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.
23
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.  */
28
29 /* Do code reading to identify a signal frame, and set the frame
30    state data appropriately.  See unwind-dw2.c for the structs.
31    Don't use this at all if inhibit_libc is used.  */
32
33 #ifndef inhibit_libc
34
35 #include <signal.h>
36
37 /* <sys/ucontext.h> is unfortunately broken right now.  */
38 struct uw_ucontext {
39         unsigned long     uc_flags;
40         struct ucontext  *uc_link;
41         stack_t           uc_stack;
42         mcontext_t        uc_mcontext;
43         unsigned long     uc_filler[80];
44         __sigset_t        uc_sigmask;
45 };
46
47 #define MD_FALLBACK_FRAME_STATE_FOR m68k_fallback_frame_state
48
49 #ifdef __mcoldfire__
50 #define M68K_FP_SIZE  8
51 #else
52 #define M68K_FP_SIZE  12
53 #endif
54
55 static _Unwind_Reason_Code
56 m68k_fallback_frame_state (struct _Unwind_Context *context,
57                            _Unwind_FrameState *fs)
58 {
59   unsigned short *pc = context->ra;
60   long cfa;
61
62   /* moveq #__NR_sigreturn,%d0; trap #0  */
63   if (pc[0] == 0x7077 && pc[1] == 0x4e40)
64     {
65       struct sigcontext *sc;
66
67       /* Context is passed as the 3rd argument.  */
68       sc = *(struct sigcontext **) (context->cfa + 8);
69
70       cfa = sc->sc_usp;
71       fs->regs.cfa_how = CFA_REG_OFFSET;
72       fs->regs.cfa_reg = 15;
73       fs->regs.cfa_offset = cfa - (long) context->cfa;
74
75       fs->regs.reg[0].how = REG_SAVED_OFFSET;
76       fs->regs.reg[0].loc.offset = (long) &sc->sc_d0 - cfa;
77       fs->regs.reg[1].how = REG_SAVED_OFFSET;
78       fs->regs.reg[1].loc.offset = (long) &sc->sc_d1 - cfa;
79       fs->regs.reg[8].how = REG_SAVED_OFFSET;
80       fs->regs.reg[8].loc.offset = (long) &sc->sc_a0 - cfa;
81       fs->regs.reg[9].how = REG_SAVED_OFFSET;
82       fs->regs.reg[9].loc.offset = (long) &sc->sc_a1 - cfa;
83
84       fs->regs.reg[24].how = REG_SAVED_OFFSET;
85       fs->regs.reg[24].loc.offset = (long) &sc->sc_pc - cfa;
86
87       if (*(int *) sc->sc_fpstate)
88         {
89           int *fpregs = (int *) sc->sc_fpregs;
90
91           fs->regs.reg[16].how = REG_SAVED_OFFSET;
92           fs->regs.reg[16].loc.offset = (long) &fpregs[0] - cfa;
93           fs->regs.reg[17].how = REG_SAVED_OFFSET;
94           fs->regs.reg[17].loc.offset = (long) &fpregs[M68K_FP_SIZE/4] - cfa;
95         }
96     }
97 #ifdef __mcoldfire__
98   /* move.l #__NR_rt_sigreturn,%d0; trap #0 */
99   else if (pc[0] == 0x203c && pc[1] == 0x0000 &&
100            pc[2] == 0x00ad && pc[3] == 0x4e40)
101 #else
102   /* moveq #~__NR_rt_sigreturn,%d0; not.b %d0; trap #0 */
103   else if (pc[0] == 0x7052 && pc[1] == 0x4600 && pc[2] == 0x4e40)
104 #endif
105     {
106       struct uw_ucontext *uc;
107       greg_t *gregs;
108       int i;
109
110       /* Context is passed as the 3rd argument.  */
111       uc = *(struct uw_ucontext **) (context->cfa + 8);
112
113       gregs = uc->uc_mcontext.gregs;
114       cfa = gregs[15];
115       fs->regs.cfa_how = CFA_REG_OFFSET;
116       fs->regs.cfa_reg = 15;
117       fs->regs.cfa_offset = cfa - (long) context->cfa;
118
119       /* register %d0-%d7/%a0-%a6  */
120       for (i = 0; i <= 14; i++)
121         {
122           fs->regs.reg[i].how = REG_SAVED_OFFSET;
123           fs->regs.reg[i].loc.offset = (long) &gregs[i] - cfa;
124         }
125
126       /* return address  */
127       fs->regs.reg[24].how = REG_SAVED_OFFSET;
128       fs->regs.reg[24].loc.offset = (long) &gregs[16] - cfa;
129
130 #define uc_fpstate      uc_filler[0]
131
132       if (uc->uc_fpstate)
133         {
134           long fpregs = (long) uc->uc_mcontext.fpregs.f_fpregs;
135
136           /* register %fp0-%fp7  */
137           for (i = 16; i <= 23; i++)
138             {
139               fs->regs.reg[i].how = REG_SAVED_OFFSET;
140               fs->regs.reg[i].loc.offset = fpregs - cfa;
141               fpregs += M68K_FP_SIZE;
142             }
143         }
144     }
145   else
146     return _URC_END_OF_STACK;
147
148   fs->retaddr_column = 24;
149   fs->signal_frame = 1;
150
151   return _URC_NO_REASON;
152 }
153 #endif /* ifdef inhibit_libc  */