1 /* DWARF2 EH unwinding support for MIPS Linux.
2 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2012 Free Software
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
27 /* Do code reading to identify a signal frame, and set the frame
28 state data appropriately. See unwind-dw2.c for the structs. */
31 #include <asm/unistd.h>
33 /* The third parameter to the signal handler points to something with
34 * this structure defined in asm/ucontext.h, but the name clashes with
35 * struct ucontext from sys/ucontext.h so this private copy is used. */
36 typedef struct _sig_ucontext {
37 unsigned long uc_flags;
38 struct _sig_ucontext *uc_link;
40 struct sigcontext uc_mcontext;
44 #define MD_FALLBACK_FRAME_STATE_FOR mips_fallback_frame_state
46 static _Unwind_Reason_Code
47 mips_fallback_frame_state (struct _Unwind_Context *context,
48 _Unwind_FrameState *fs)
50 u_int32_t *pc = (u_int32_t *) context->ra;
51 struct sigcontext *sc;
52 _Unwind_Ptr new_cfa, reg_offset;
55 /* 24021061 li v0, 0x1061 (rt_sigreturn)*/
56 /* 0000000c syscall */
58 /* 24021017 li v0, 0x1017 (sigreturn) */
59 /* 0000000c syscall */
60 if (pc[1] != 0x0000000c)
61 return _URC_END_OF_STACK;
62 #if _MIPS_SIM == _ABIO32
63 if (pc[0] == (0x24020000 | __NR_sigreturn))
66 u_int32_t ass[4]; /* Argument save space for o32. */
67 u_int32_t trampoline[2];
68 struct sigcontext sigctx;
69 } *rt_ = context->cfa;
74 if (pc[0] == (0x24020000 | __NR_rt_sigreturn))
77 u_int32_t ass[4]; /* Argument save space for o32. */
78 u_int32_t trampoline[2];
81 } *rt_ = context->cfa;
82 sc = &rt_->uc.uc_mcontext;
85 return _URC_END_OF_STACK;
87 new_cfa = (_Unwind_Ptr) sc;
88 fs->regs.cfa_how = CFA_REG_OFFSET;
89 fs->regs.cfa_reg = STACK_POINTER_REGNUM;
90 fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
92 /* On o32 Linux, the register save slots in the sigcontext are
93 eight bytes. We need the lower half of each register slot,
94 so slide our view of the structure back four bytes. */
95 #if _MIPS_SIM == _ABIO32 && defined __MIPSEB__
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]) + reg_offset - new_cfa;
106 /* "PC & -2" points to the faulting instruction, but the unwind code
107 searches for "(ADDR & -2) - 1". (See MASK_RETURN_ADDR for the source
108 of the -2 mask.) Adding 2 here ensures that "(ADDR & -2) - 1" is the
109 address of the second byte of the faulting instruction.
111 Note that setting fs->signal_frame would not work. As the comment
112 above MASK_RETURN_ADDR explains, MIPS unwinders must earch for an
113 odd-valued address. */
114 fs->regs.reg[DWARF_ALT_FRAME_RETURN_COLUMN].how = REG_SAVED_VAL_OFFSET;
115 fs->regs.reg[DWARF_ALT_FRAME_RETURN_COLUMN].loc.offset
116 = (_Unwind_Ptr)(sc->sc_pc) + 2 - new_cfa;
117 fs->retaddr_column = DWARF_ALT_FRAME_RETURN_COLUMN;
119 return _URC_NO_REASON;