]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/s390/linux-unwind.h
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / gcc / config / s390 / linux-unwind.h
CommitLineData
8662eb14 1/* DWARF2 EH unwinding support for S/390 Linux.
748086b7 2 Copyright (C) 2004, 2005, 2006, 2009 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 it under
7the terms of the GNU General Public License as published by the Free
748086b7 8Software Foundation; either version 3, or (at your option) any later
8662eb14
AM
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for 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/>. */
8662eb14
AM
24
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
28#define MD_FALLBACK_FRAME_STATE_FOR s390_fallback_frame_state
29
30static _Unwind_Reason_Code
31s390_fallback_frame_state (struct _Unwind_Context *context,
32 _Unwind_FrameState *fs)
33{
34 unsigned char *pc = context->ra;
35 long new_cfa;
36 int i;
37
38 typedef struct
39 {
40 unsigned long psw_mask;
41 unsigned long psw_addr;
42 unsigned long gprs[16];
43 unsigned int acrs[16];
44 unsigned int fpc;
45 unsigned int __pad;
46 double fprs[16];
47 } __attribute__ ((__aligned__ (8))) sigregs_;
48
49 sigregs_ *regs;
47a4949a 50 int *signo;
8662eb14
AM
51
52 /* svc $__NR_sigreturn or svc $__NR_rt_sigreturn */
53 if (pc[0] != 0x0a || (pc[1] != 119 && pc[1] != 173))
54 return _URC_END_OF_STACK;
55
47a4949a
UW
56 /* Legacy frames:
57 old signal mask (8 bytes)
58 pointer to sigregs (8 bytes) - points always to next location
59 sigregs
60 retcode
61 This frame layout was used on kernels < 2.6.9 for non-RT frames,
62 and on kernels < 2.4.13 for RT frames as well. Note that we need
63 to look at RA to detect this layout -- this means that if you use
64 sa_restorer to install a different signal restorer on a legacy
65 kernel, unwinding from signal frames will not work. */
66 if (context->ra == context->cfa + 16 + sizeof (sigregs_))
67 {
68 regs = (sigregs_ *)(context->cfa + 16);
69 signo = NULL;
70 }
71
8662eb14
AM
72 /* New-style RT frame:
73 retcode + alignment (8 bytes)
74 siginfo (128 bytes)
75 ucontext (contains sigregs) */
47a4949a 76 else if (pc[1] == 173 /* __NR_rt_sigreturn */)
8662eb14
AM
77 {
78 struct ucontext_
79 {
80 unsigned long uc_flags;
81 struct ucontext_ *uc_link;
82 unsigned long uc_stack[3];
83 sigregs_ uc_mcontext;
84 } *uc = context->cfa + 8 + 128;
85
86 regs = &uc->uc_mcontext;
87 signo = context->cfa + sizeof(long);
88 }
89
47a4949a 90 /* New-style non-RT frame:
8662eb14 91 old signal mask (8 bytes)
47a4949a 92 pointer to sigregs (followed by signal number) */
8662eb14
AM
93 else
94 {
95 regs = *(sigregs_ **)(context->cfa + 8);
47a4949a 96 signo = (int *)(regs + 1);
8662eb14
AM
97 }
98
99 new_cfa = regs->gprs[15] + 16*sizeof(long) + 32;
6673f90b
NF
100 fs->regs.cfa_how = CFA_REG_OFFSET;
101 fs->regs.cfa_reg = 15;
102 fs->regs.cfa_offset =
8662eb14
AM
103 new_cfa - (long) context->cfa + 16*sizeof(long) + 32;
104
105 for (i = 0; i < 16; i++)
106 {
107 fs->regs.reg[i].how = REG_SAVED_OFFSET;
108 fs->regs.reg[i].loc.offset =
109 (long)&regs->gprs[i] - new_cfa;
110 }
111 for (i = 0; i < 16; i++)
112 {
113 fs->regs.reg[16+i].how = REG_SAVED_OFFSET;
114 fs->regs.reg[16+i].loc.offset =
115 (long)&regs->fprs[i] - new_cfa;
116 }
117
118 /* Load return addr from PSW into dummy register 32. */
119
120 fs->regs.reg[32].how = REG_SAVED_OFFSET;
121 fs->regs.reg[32].loc.offset = (long)&regs->psw_addr - new_cfa;
122 fs->retaddr_column = 32;
754e45a8
JJ
123 /* SIGILL, SIGFPE and SIGTRAP are delivered with psw_addr
124 after the faulting instruction rather than before it.
125 Don't set FS->signal_frame in that case. */
126 if (!signo || (*signo != 4 && *signo != 5 && *signo != 8))
127 fs->signal_frame = 1;
8662eb14
AM
128
129 return _URC_NO_REASON;
130}