xref: /netbsd-src/external/gpl3/gcc.old/dist/libgcc/config/or1k/linux-unwind.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /* DWARF2 EH unwinding support for OpenRISC.
2    Copyright (C) 2011, 2012
3    Free Software Foundation, Inc.
4 
5 This file is part of GCC.
6 
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)
10 any later version.
11 
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.
16 
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.
20 
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/>.  */
25 
26 #ifndef inhibit_libc
27 
28 #include <signal.h>
29 #include <sys/ucontext.h>
30 #include <linux/unistd.h>
31 
32 #define MD_FALLBACK_FRAME_STATE_FOR or1k_fallback_frame_state
33 
34 static _Unwind_Reason_Code
35 or1k_fallback_frame_state (struct _Unwind_Context *context,
36 			      _Unwind_FrameState *fs)
37 {
38   struct rt_sigframe {
39     siginfo_t info;
40     struct ucontext uc;
41   } *frame = context->cfa;
42 
43   struct sigcontext *sc;
44   unsigned char *pc = context->ra;
45   long new_cfa;
46   int i;
47 
48   /*
49    * Note: These have to be the same as in the kernel.
50    * Please see arch/openrisc/kernel/signal.c
51    */
52   if (!(*(unsigned short *)(pc + 0) == 0xa960
53       && *(unsigned short *)(pc + 2) == __NR_rt_sigreturn
54       && *(unsigned long *)(pc + 4) == 0x20000001
55       && *(unsigned long *)(pc + 8) == 0x15000000))
56     return _URC_END_OF_STACK;
57 
58   sc = (struct sigcontext *) &frame->uc.uc_mcontext;
59 
60   new_cfa = sc->regs.gpr[1];
61   fs->regs.cfa_how = CFA_REG_OFFSET;
62   fs->regs.cfa_reg = STACK_POINTER_REGNUM;
63   fs->regs.cfa_offset = new_cfa - (long) context->cfa;
64 
65   for (i = 0; i < 32; ++i)
66     {
67       fs->regs.reg[i].how = REG_SAVED_OFFSET;
68       fs->regs.reg[i].loc.offset = (long)&sc->regs.gpr[i] - new_cfa;
69     }
70 
71   fs->retaddr_column = 9;
72   fs->signal_frame = 1;
73 
74   return _URC_NO_REASON;
75 }
76 
77 #endif /* ifdef inhibit_libc  */
78