Use a XOR cipher instead of byte shuffling to protect against bad seeds.
[official-gcc.git] / libgcc / config / nios2 / linux-unwind.h
blob23041420525babb15a6d0f5c04672e3ea2c261a6
1 /* DWARF2 EH unwinding support for Nios II Linux.
2 Copyright (C) 2008-2016 Free Software Foundation, Inc.
4 This file is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3, or (at your option) any
7 later version.
9 This file is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 Under Section 7 of GPL version 3, you are granted additional
15 permissions described in the GCC Runtime Library Exception, version
16 3.1, as published by the Free Software Foundation.
18 You should have received a copy of the GNU General Public License and
19 a copy of the GCC Runtime Library Exception along with this program;
20 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 <http://www.gnu.org/licenses/>. */
23 #ifndef inhibit_libc
25 /* Do code reading to identify a signal frame, and set the frame
26 state data appropriately. See unwind-dw2.c for the structs.
27 The corresponding bits in the Linux kernel are in
28 arch/nios2/kernel/signal.c. */
30 #include <signal.h>
31 #include <asm/unistd.h>
33 /* Exactly the same layout as the kernel structures, unique names. */
34 struct nios2_mcontext {
35 int version;
36 int gregs[32];
39 struct nios2_ucontext {
40 unsigned long uc_flags;
41 struct ucontext *uc_link;
42 stack_t uc_stack;
43 struct nios2_mcontext uc_mcontext;
44 sigset_t uc_sigmask; /* mask last for extensibility */
47 #define MD_FALLBACK_FRAME_STATE_FOR nios2_fallback_frame_state
49 static _Unwind_Reason_Code
50 nios2_fallback_frame_state (struct _Unwind_Context *context,
51 _Unwind_FrameState *fs)
53 u_int32_t *pc = (u_int32_t *) context->ra;
54 _Unwind_Ptr new_cfa;
56 /* The expected sequence of instructions is:
57 movi r2,(rt_sigreturn)
58 trap
59 Check for the trap first. */
60 if (pc[1] != 0x003b683a)
61 return _URC_END_OF_STACK;
63 #define NIOS2_REG(NUM,NAME) \
64 (fs->regs.reg[NUM].how = REG_SAVED_OFFSET, \
65 fs->regs.reg[NUM].loc.offset = (_Unwind_Ptr)&(regs->NAME) - new_cfa)
67 if (pc[0] == (0x00800004 | (__NR_rt_sigreturn << 6)))
69 struct rt_sigframe {
70 siginfo_t info;
71 struct nios2_ucontext uc;
72 } *rt_ = context->cfa;
73 struct nios2_mcontext *regs = &rt_->uc.uc_mcontext;
74 int i;
76 /* MCONTEXT_VERSION is defined to 2 in the kernel. */
77 if (regs->version != 2)
78 return _URC_END_OF_STACK;
80 /* The CFA is the user's incoming stack pointer value. */
81 new_cfa = (_Unwind_Ptr)regs->gregs[28];
82 fs->regs.cfa_how = CFA_REG_OFFSET;
83 fs->regs.cfa_reg = __LIBGCC_STACK_POINTER_REGNUM__;
84 fs->regs.cfa_offset = new_cfa - (_Unwind_Ptr) context->cfa;
86 /* The sequential registers. */
87 for (i = 1; i < 24; i++)
88 NIOS2_REG (i, gregs[i-1]);
90 /* The random registers. The kernel stores these in a funny order
91 in the gregs array. */
92 NIOS2_REG (RA_REGNO, gregs[23]);
93 NIOS2_REG (FP_REGNO, gregs[24]);
94 NIOS2_REG (GP_REGNO, gregs[25]);
95 NIOS2_REG (EA_REGNO, gregs[27]);
97 fs->retaddr_column = EA_REGNO;
98 fs->signal_frame = 1;
100 return _URC_NO_REASON;
102 #undef NIOS2_REG
103 return _URC_END_OF_STACK;
105 #endif