Update LOCAL_PATCHES after libsanitizer merge.
[official-gcc.git] / libgcc / config / csky / linux-unwind.h
blob24638defd527b827d051019d9df1a8dbaca5cbe4
1 /* DWARF2 EH unwinding support for C-SKY Linux.
2 Copyright (C) 2018 Free Software Foundation, Inc.
3 Contributed by C-SKY Microsystems and Mentor Graphics.
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)
10 any later version.
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/>. */
26 #ifndef inhibit_libc
28 /* Do code reading to identify a signal frame, and set the frame
29 state data appropriately. See unwind-dw2.c for the structs. */
31 #include <signal.h>
32 #include <asm/unistd.h>
34 /* The third parameter to the signal handler points to something with
35 this structure defined in asm/ucontext.h, but the name clashes with
36 struct ucontext from sys/ucontext.h so this private copy is used. */
37 typedef struct _sig_ucontext {
38 unsigned long uc_flags;
39 struct _sig_ucontext *uc_link;
40 stack_t uc_stack;
41 struct sigcontext uc_mcontext;
42 sigset_t uc_sigmask;
43 } _sig_ucontext_t;
45 #define MD_FALLBACK_FRAME_STATE_FOR csky_fallback_frame_state
47 static _Unwind_Reason_Code
48 csky_fallback_frame_state (struct _Unwind_Context *context,
49 _Unwind_FrameState *fs)
51 u_int16_t *pc = (u_int16_t *) context->ra;
52 struct sigcontext *sc;
53 _Unwind_Ptr new_cfa;
54 int i;
56 /* movi r7, __NR_rt_sigreturn; trap 0 */
57 if ((*(pc+0) == 0xea07) && (*(pc+1) == 119)
58 && (*(pc+2) == 0xc000) && (*(pc+3) == 0x2020))
60 struct sigframe
62 int sig;
63 int code;
64 struct sigcontext *psc;
65 unsigned long extramask[2]; /* _NSIG_WORDS */
66 struct sigcontext sc;
67 } *_rt = context->cfa;
68 sc = _rt->psc; // &(_rt->sc);
70 /* movi r7, __NR_rt_sigreturn; trap 0 */
71 else if ((*(pc+0) == 0xea07) && (*(pc+1) == 173)
72 && (*(pc+2) == 0xc000) && (*(pc+3) == 0x2020))
74 struct rt_sigframe
76 int sig;
77 struct siginfo *pinfo;
78 void* puc;
79 siginfo_t info;
80 struct ucontext uc;
81 } *_rt = context->cfa;
82 sc = &(_rt->uc.uc_mcontext);
84 else
85 return _URC_END_OF_STACK;
87 new_cfa = (_Unwind_Ptr) sc->sc_usp;
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 fs->regs.reg[0].how = REG_SAVED_OFFSET;
93 fs->regs.reg[0].loc.offset = (_Unwind_Ptr)&(sc->sc_a0) - new_cfa;
95 fs->regs.reg[1].how = REG_SAVED_OFFSET;
96 fs->regs.reg[1].loc.offset = (_Unwind_Ptr)&(sc->sc_a1) - new_cfa;
98 fs->regs.reg[2].how = REG_SAVED_OFFSET;
99 fs->regs.reg[2].loc.offset = (_Unwind_Ptr)&(sc->sc_a2) - new_cfa;
101 fs->regs.reg[3].how = REG_SAVED_OFFSET;
102 fs->regs.reg[3].loc.offset = (_Unwind_Ptr)&(sc->sc_a3) - new_cfa;
104 for (i = 4; i < 14; i++)
106 fs->regs.reg[i].how = REG_SAVED_OFFSET;
107 fs->regs.reg[i].loc.offset = ((_Unwind_Ptr)&(sc->sc_regs[i - 4])
108 - new_cfa);
111 for (i = 16; i < 32; i++)
113 fs->regs.reg[i].how = REG_SAVED_OFFSET;
114 fs->regs.reg[i].loc.offset = ((_Unwind_Ptr)&(sc->sc_exregs[i - 16])
115 - new_cfa);
118 /* FIXME : hi lo ? */
119 fs->regs.reg[15].how = REG_SAVED_OFFSET;
120 fs->regs.reg[15].loc.offset = (_Unwind_Ptr)&(sc->sc_r15) - new_cfa;
122 fs->regs.reg[56].how = REG_SAVED_OFFSET;
123 fs->regs.reg[56].loc.offset = (_Unwind_Ptr)&(sc->sc_pc) - new_cfa;
124 fs->retaddr_column = 56;
125 fs->signal_frame = 1;
127 return _URC_NO_REASON;
131 #endif