]>
Commit | Line | Data |
---|---|---|
6c633d45 | 1 | /* DWARF2 EH unwinding support for Xtensa. |
5624e564 | 2 | Copyright (C) 2008-2015 Free Software Foundation, Inc. |
6c633d45 BW |
3 | |
4 | This file is part of GCC. | |
5 | ||
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 | |
748086b7 | 8 | the Free Software Foundation; either version 3, or (at your option) |
6c633d45 BW |
9 | any later version. |
10 | ||
6c633d45 BW |
11 | GCC is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | Under Section 7 of GPL version 3, you are granted additional |
17 | permissions described in the GCC Runtime Library Exception, version | |
18 | 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | You should have received a copy of the GNU General Public License and | |
21 | a copy of the GCC Runtime Library Exception along with this program; | |
22 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | <http://www.gnu.org/licenses/>. */ | |
6c633d45 BW |
24 | |
25 | /* Do code reading to identify a signal frame, and set the frame | |
26 | state data appropriately. See unwind-dw2-xtensa.c for the structs. | |
27 | Don't use this at all if inhibit_libc is used. */ | |
28 | ||
29 | #ifndef inhibit_libc | |
30 | ||
31 | #include <signal.h> | |
32 | #include <sys/ucontext.h> | |
33 | ||
34 | /* Encoded bytes for Xtensa instructions: | |
35 | movi a2, __NR_rt_sigreturn | |
36 | syscall | |
37 | entry (first byte only) | |
38 | Some of the bytes are endian-dependent. */ | |
39 | ||
40 | #define MOVI_BYTE0 0x22 | |
41 | #define MOVI_BYTE2 225 /* __NR_rt_sigreturn */ | |
42 | #define SYSC_BYTE0 0 | |
43 | #define SYSC_BYTE2 0 | |
44 | ||
45 | #ifdef __XTENSA_EB__ | |
46 | #define MOVI_BYTE1 0x0a | |
47 | #define SYSC_BYTE1 0x05 | |
48 | #define ENTRY_BYTE 0x6c | |
49 | #else | |
50 | #define MOVI_BYTE1 0xa0 | |
51 | #define SYSC_BYTE1 0x50 | |
52 | #define ENTRY_BYTE 0x36 | |
53 | #endif | |
54 | ||
590e2636 | 55 | #ifdef __XTENSA_WINDOWED_ABI__ |
6c633d45 BW |
56 | #define MD_FALLBACK_FRAME_STATE_FOR xtensa_fallback_frame_state |
57 | ||
58 | static _Unwind_Reason_Code | |
59 | xtensa_fallback_frame_state (struct _Unwind_Context *context, | |
60 | _Unwind_FrameState *fs) | |
61 | { | |
62 | unsigned char *pc = context->ra; | |
63 | struct sigcontext *sc; | |
64 | ||
65 | struct rt_sigframe { | |
1bde7dab | 66 | siginfo_t info; |
6c633d45 BW |
67 | struct ucontext uc; |
68 | } *rt_; | |
69 | ||
70 | /* movi a2, __NR_rt_sigreturn; syscall */ | |
71 | if (pc[0] != MOVI_BYTE0 | |
72 | || pc[1] != MOVI_BYTE1 | |
73 | || pc[2] != MOVI_BYTE2 | |
74 | || pc[3] != SYSC_BYTE0 | |
75 | || pc[4] != SYSC_BYTE1 | |
76 | || pc[5] != SYSC_BYTE2) | |
77 | return _URC_END_OF_STACK; | |
78 | ||
79 | rt_ = context->sp; | |
80 | sc = &rt_->uc.uc_mcontext; | |
81 | fs->signal_regs = (_Unwind_Word *) sc->sc_a; | |
82 | ||
83 | /* If the signal arrived just before an ENTRY instruction, find the return | |
84 | address and pretend the signal arrived before executing the CALL. */ | |
85 | if (*(unsigned char *) sc->sc_pc == ENTRY_BYTE) | |
86 | { | |
87 | unsigned callinc = (sc->sc_ps >> 16) & 3; | |
88 | fs->signal_ra = ((sc->sc_a[callinc << 2] & XTENSA_RA_FIELD_MASK) | |
89 | | context->ra_high_bits) - 3; | |
90 | } | |
91 | else | |
92 | fs->signal_ra = sc->sc_pc; | |
93 | ||
94 | fs->signal_frame = 1; | |
95 | return _URC_NO_REASON; | |
96 | } | |
97 | ||
590e2636 MF |
98 | #endif /* __XTENSA_WINDOWED_ABI__ */ |
99 | ||
6c633d45 | 100 | #endif /* ifdef inhibit_libc */ |