fortran frontend:
[official-gcc.git] / gcc / config / mips / linux-unwind.h
blobe10fc7698302e20a3114506d0094d8503da2dcdb
1 /* DWARF2 EH unwinding support for MIPS Linux.
2 Copyright (C) 2004, 2005, 2006 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 #ifndef inhibit_libc
30 /* Do code reading to identify a signal frame, and set the frame
31 state data appropriately. See unwind-dw2.c for the structs. */
33 #include <signal.h>
34 #include <asm/unistd.h>
36 /* The third parameter to the signal handler points to something with
37 * this structure defined in asm/ucontext.h, but the name clashes with
38 * struct ucontext from sys/ucontext.h so this private copy is used. */
39 typedef struct _sig_ucontext {
40 unsigned long uc_flags;
41 struct _sig_ucontext *uc_link;
42 stack_t uc_stack;
43 struct sigcontext uc_mcontext;
44 sigset_t uc_sigmask;
45 } _sig_ucontext_t;
47 #define MD_FALLBACK_FRAME_STATE_FOR mips_fallback_frame_state
49 static _Unwind_Reason_Code
50 mips_fallback_frame_state (struct _Unwind_Context *context,
51 _Unwind_FrameState *fs)
53 u_int32_t *pc = (u_int32_t *) context->ra;
54 u_int32_t t;
55 struct sigcontext *sc;
56 _Unwind_Ptr new_cfa;
57 int i;
59 /* 24021061 li v0, 0x1061 (rt_sigreturn)*/
60 /* 0000000c syscall */
61 /* or */
62 /* 24021017 li v0, 0x1017 (sigreturn) */
63 /* 0000000c syscall */
64 if (pc[1] != 0x0000000c)
65 return _URC_END_OF_STACK;
66 #if _MIPS_SIM == _ABIO32
67 if (pc[0] == (0x24020000 | __NR_sigreturn))
69 struct sigframe {
70 u_int32_t trampoline[2];
71 struct sigcontext sigctx;
72 } *rt_ = context->ra;
73 sc = &rt_->sigctx;
75 else
76 #endif
77 if (pc[0] == (0x24020000 | __NR_rt_sigreturn))
79 struct rt_sigframe {
80 u_int32_t trampoline[2];
81 struct siginfo info;
82 _sig_ucontext_t uc;
83 } *rt_ = context->ra;
84 sc = &rt_->uc.uc_mcontext;
86 else
87 return _URC_END_OF_STACK;
89 new_cfa = (_Unwind_Ptr)sc;
90 fs->regs.cfa_how = CFA_REG_OFFSET;
91 fs->regs.cfa_reg = STACK_POINTER_REGNUM;
92 fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
94 #if _MIPS_SIM == _ABIO32 && defined __MIPSEB__
95 /* On o32 Linux, the register save slots in the sigcontext are
96 eight bytes. We need the lower half of each register slot,
97 so slide our view of the structure back four bytes. */
98 new_cfa -= 4;
99 #endif
101 for (i = 0; i < 32; i++) {
102 fs->regs.reg[i].how = REG_SAVED_OFFSET;
103 fs->regs.reg[i].loc.offset
104 = (_Unwind_Ptr)&(sc->sc_regs[i]) - new_cfa;
106 /* The PC points to the faulting instruction, but the unwind tables
107 expect it point to the following instruction. We compensate by
108 reporting a return address at the next instruction. */
109 fs->regs.reg[SIGNAL_UNWIND_RETURN_COLUMN].how = REG_SAVED_VAL_OFFSET;
110 t = (*(u_int32_t *)(void *)&sc->sc_pc) + 4;
111 fs->regs.reg[SIGNAL_UNWIND_RETURN_COLUMN].loc.offset
112 = (_Unwind_Ptr)t - new_cfa;
113 fs->retaddr_column = SIGNAL_UNWIND_RETURN_COLUMN;
115 return _URC_NO_REASON;
117 #endif