]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/sh/linux-unwind.h
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / sh / linux-unwind.h
CommitLineData
8662eb14 1/* DWARF2 EH unwinding support for SH Linux.
85ec4feb 2 Copyright (C) 2004-2018 Free Software Foundation, Inc.
8662eb14
AM
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
748086b7 8the Free Software Foundation; either version 3, or (at your option)
8662eb14
AM
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
748086b7
JJ
16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23<http://www.gnu.org/licenses/>. */
24
8662eb14
AM
25
26/* Do code reading to identify a signal frame, and set the frame
47e4dfcf
AS
27 state data appropriately. See unwind-dw2.c for the structs.
28 Don't use this at all if inhibit_libc is used. */
29
30#ifndef inhibit_libc
8662eb14
AM
31
32#include <signal.h>
33#include <sys/ucontext.h>
34#include "insn-constants.h"
35
8662eb14
AM
36#define SH_DWARF_FRAME_GP0 0
37#define SH_DWARF_FRAME_FP0 25
38#define SH_DWARF_FRAME_XD0 87
39#define SH_DWARF_FRAME_PR 17
926e663e 40#define SH_DWARF_FRAME_GBR 18
8662eb14
AM
41#define SH_DWARF_FRAME_MACH 20
42#define SH_DWARF_FRAME_MACL 21
43#define SH_DWARF_FRAME_PC 16
44#define SH_DWARF_FRAME_SR 22
45#define SH_DWARF_FRAME_FPUL 23
46#define SH_DWARF_FRAME_FPSCR 24
8662eb14
AM
47
48#define MD_FALLBACK_FRAME_STATE_FOR sh_fallback_frame_state
49
50static _Unwind_Reason_Code
51sh_fallback_frame_state (struct _Unwind_Context *context,
52 _Unwind_FrameState *fs)
53{
54 unsigned char *pc = context->ra;
55 struct sigcontext *sc;
56 long new_cfa;
57 int i;
58#if defined (__SH3E__) || defined (__SH4__)
59 int r;
60#endif
61
62 /* mov.w 1f,r3; trapa #0x10; 1: .short 0x77 (sigreturn) */
63 /* mov.w 1f,r3; trapa #0x10; 1: .short 0xad (rt_sigreturn) */
64 /* Newer kernel uses pad instructions to avoid an SH-4 core bug. */
65 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;
66 or r0,r0; 1: .short 0x77 (sigreturn) */
67 /* mov.w 1f,r3; trapa #0x10; or r0,r0; or r0,r0; or r0,r0; or r0,r0;
68 or r0,r0; 1: .short 0xad (rt_sigreturn) */
69 if (((*(unsigned short *) (pc+0) == 0x9300)
70 && (*(unsigned short *) (pc+2) == 0xc310)
71 && (*(unsigned short *) (pc+4) == 0x0077))
72 || (((*(unsigned short *) (pc+0) == 0x9305)
73 && (*(unsigned short *) (pc+2) == 0xc310)
74 && (*(unsigned short *) (pc+14) == 0x0077))))
75 sc = context->cfa;
76 else if (((*(unsigned short *) (pc+0) == 0x9300)
77 && (*(unsigned short *) (pc+2) == 0xc310)
78 && (*(unsigned short *) (pc+4) == 0x00ad))
79 || (((*(unsigned short *) (pc+0) == 0x9305)
80 && (*(unsigned short *) (pc+2) == 0xc310)
81 && (*(unsigned short *) (pc+14) == 0x00ad))))
82 {
83 struct rt_sigframe {
1bde7dab 84 siginfo_t info;
883312dc 85 ucontext_t uc;
8662eb14 86 } *rt_ = context->cfa;
4f1eb6e3
KK
87 /* The void * cast is necessary to avoid an aliasing warning.
88 The aliasing warning is correct, but should not be a problem
89 because it does not alias anything. */
90 sc = (struct sigcontext *) (void *) &rt_->uc.uc_mcontext;
8662eb14
AM
91 }
92 else
93 return _URC_END_OF_STACK;
94
95 new_cfa = sc->sc_regs[15];
6673f90b
NF
96 fs->regs.cfa_how = CFA_REG_OFFSET;
97 fs->regs.cfa_reg = 15;
98 fs->regs.cfa_offset = new_cfa - (long) context->cfa;
8662eb14
AM
99
100 for (i = 0; i < 15; i++)
101 {
102 fs->regs.reg[i].how = REG_SAVED_OFFSET;
103 fs->regs.reg[i].loc.offset
104 = (long)&(sc->sc_regs[i]) - new_cfa;
105 }
106
107 fs->regs.reg[SH_DWARF_FRAME_PR].how = REG_SAVED_OFFSET;
108 fs->regs.reg[SH_DWARF_FRAME_PR].loc.offset
109 = (long)&(sc->sc_pr) - new_cfa;
110 fs->regs.reg[SH_DWARF_FRAME_SR].how = REG_SAVED_OFFSET;
111 fs->regs.reg[SH_DWARF_FRAME_SR].loc.offset
112 = (long)&(sc->sc_sr) - new_cfa;
113 fs->regs.reg[SH_DWARF_FRAME_GBR].how = REG_SAVED_OFFSET;
114 fs->regs.reg[SH_DWARF_FRAME_GBR].loc.offset
115 = (long)&(sc->sc_gbr) - new_cfa;
116 fs->regs.reg[SH_DWARF_FRAME_MACH].how = REG_SAVED_OFFSET;
117 fs->regs.reg[SH_DWARF_FRAME_MACH].loc.offset
118 = (long)&(sc->sc_mach) - new_cfa;
119 fs->regs.reg[SH_DWARF_FRAME_MACL].how = REG_SAVED_OFFSET;
120 fs->regs.reg[SH_DWARF_FRAME_MACL].loc.offset
121 = (long)&(sc->sc_macl) - new_cfa;
122
123#if defined (__SH3E__) || defined (__SH4__)
124 r = SH_DWARF_FRAME_FP0;
125 for (i = 0; i < 16; i++)
126 {
127 fs->regs.reg[r+i].how = REG_SAVED_OFFSET;
128 fs->regs.reg[r+i].loc.offset
129 = (long)&(sc->sc_fpregs[i]) - new_cfa;
130 }
131
132 r = SH_DWARF_FRAME_XD0;
133 for (i = 0; i < 8; i++)
134 {
192c543c
KK
135 fs->regs.reg[r+i].how = REG_SAVED_OFFSET;
136 fs->regs.reg[r+i].loc.offset
8662eb14
AM
137 = (long)&(sc->sc_xfpregs[2*i]) - new_cfa;
138 }
139
140 fs->regs.reg[SH_DWARF_FRAME_FPUL].how = REG_SAVED_OFFSET;
141 fs->regs.reg[SH_DWARF_FRAME_FPUL].loc.offset
142 = (long)&(sc->sc_fpul) - new_cfa;
143 fs->regs.reg[SH_DWARF_FRAME_FPSCR].how = REG_SAVED_OFFSET;
144 fs->regs.reg[SH_DWARF_FRAME_FPSCR].loc.offset
145 = (long)&(sc->sc_fpscr) - new_cfa;
146#endif
147
8662eb14
AM
148 fs->regs.reg[SH_DWARF_FRAME_PC].how = REG_SAVED_OFFSET;
149 fs->regs.reg[SH_DWARF_FRAME_PC].loc.offset
150 = (long)&(sc->sc_pc) - new_cfa;
151 fs->retaddr_column = SH_DWARF_FRAME_PC;
3062335c 152 fs->signal_frame = 1;
8662eb14
AM
153 return _URC_NO_REASON;
154}
47e4dfcf
AS
155
156#endif /* inhibit_libc */