OSDN Git Service

2008-11-18 Kai Tietz <kai.tietz@onevision.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / xtensa / linux-unwind.h
1 /* DWARF2 EH unwinding support for Xtensa.
2    Copyright (C) 2008 Free Software Foundation, Inc.
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
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file with other programs, and to distribute
14 those programs without any restriction coming from the use of this
15 file.  (The General Public License restrictions do apply in other
16 respects; for example, they cover modification of the file, and
17 distribution when not linked into another program.)
18
19 GCC is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING.  If not, write to
26 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27 Boston, MA 02110-1301, USA.  */
28
29 /* Do code reading to identify a signal frame, and set the frame
30    state data appropriately.  See unwind-dw2-xtensa.c for the structs.
31    Don't use this at all if inhibit_libc is used.  */
32
33 #ifndef inhibit_libc
34
35 #include <signal.h>
36 #include <sys/ucontext.h>
37
38 /* Encoded bytes for Xtensa instructions:
39         movi a2, __NR_rt_sigreturn
40         syscall
41         entry (first byte only)
42    Some of the bytes are endian-dependent.  */
43
44 #define MOVI_BYTE0 0x22
45 #define MOVI_BYTE2 225 /* __NR_rt_sigreturn */
46 #define SYSC_BYTE0 0
47 #define SYSC_BYTE2 0
48
49 #ifdef __XTENSA_EB__
50 #define MOVI_BYTE1 0x0a
51 #define SYSC_BYTE1 0x05
52 #define ENTRY_BYTE 0x6c
53 #else
54 #define MOVI_BYTE1 0xa0
55 #define SYSC_BYTE1 0x50
56 #define ENTRY_BYTE 0x36
57 #endif
58
59 #define MD_FALLBACK_FRAME_STATE_FOR xtensa_fallback_frame_state
60
61 static _Unwind_Reason_Code
62 xtensa_fallback_frame_state (struct _Unwind_Context *context,
63                              _Unwind_FrameState *fs)
64 {
65   unsigned char *pc = context->ra;
66   struct sigcontext *sc;
67
68   struct rt_sigframe {
69     struct siginfo info;
70     struct ucontext uc;
71   } *rt_;
72
73   /* movi a2, __NR_rt_sigreturn; syscall */
74   if (pc[0] != MOVI_BYTE0
75       || pc[1] != MOVI_BYTE1
76       || pc[2] != MOVI_BYTE2
77       || pc[3] != SYSC_BYTE0
78       || pc[4] != SYSC_BYTE1
79       || pc[5] != SYSC_BYTE2)
80     return _URC_END_OF_STACK;
81
82   rt_ = context->sp;
83   sc = &rt_->uc.uc_mcontext;
84   fs->signal_regs = (_Unwind_Word *) sc->sc_a;
85
86   /* If the signal arrived just before an ENTRY instruction, find the return
87      address and pretend the signal arrived before executing the CALL.  */
88   if (*(unsigned char *) sc->sc_pc == ENTRY_BYTE)
89    {
90      unsigned callinc = (sc->sc_ps >> 16) & 3;
91      fs->signal_ra = ((sc->sc_a[callinc << 2] & XTENSA_RA_FIELD_MASK)
92                       | context->ra_high_bits) - 3;
93    }
94   else
95     fs->signal_ra = sc->sc_pc;
96
97   fs->signal_frame = 1;
98   return _URC_NO_REASON;
99 }
100
101 #endif /* ifdef inhibit_libc  */