OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [ada/] [sigtramp-ppcvxw.c] - Blame information for rev 821

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 706 jeremybenn
/****************************************************************************
2
 *                                                                          *
3
 *                         GNAT COMPILER COMPONENTS                         *
4
 *                                                                          *
5
 *                             S I G T R A M P                              *
6
 *                                                                          *
7
 *                         Asm Implementation File                          *
8
 *                                                                          *
9
 *         Copyright (C) 2011-2012, Free Software Foundation, Inc.          *
10
 *                                                                          *
11
 * GNAT is free software;  you can  redistribute it  and/or modify it under *
12
 * terms of the  GNU General Public License as published  by the Free Soft- *
13
 * ware  Foundation;  either version 3,  or (at your option) any later ver- *
14
 * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
15
 * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
16
 * or FITNESS FOR A PARTICULAR PURPOSE.                                     *
17
 *                                                                          *
18
 * As a special exception under Section 7 of GPL version 3, you are granted *
19
 * additional permissions described in the GCC Runtime Library Exception,   *
20
 * version 3.1, as published by the Free Software Foundation.               *
21
 *                                                                          *
22
 * You should have received a copy of the GNU General Public License and    *
23
 * a copy of the GCC Runtime Library Exception along with this program;     *
24
 * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    *
25
 * <http://www.gnu.org/licenses/>.                                          *
26
 *                                                                          *
27
 * GNAT was originally developed  by the GNAT team at  New York University. *
28
 * Extensive contributions were provided by Ada Core Technologies Inc.      *
29
 *                                                                          *
30
 ****************************************************************************/
31
 
32
/**********************************************************
33
 * PowerPC-VxWorks version of the __gnat_sigtramp service *
34
 **********************************************************/
35
 
36
#include "sigtramp.h"
37
 
38
#include <vxWorks.h>
39
#include <arch/../regs.h>
40
#include <sigLib.h>
41
 
42
/* ----------------------
43
   -- General comments --
44
   ----------------------
45
 
46
   Stubs are generated from toplevel asms and .cfi directives, much simpler
47
   to use and check for correctness than manual encodings of CFI byte
48
   sequences.  The general idea is to establish CFA as sigcontext->sc_pregs
49
   and state where to find the registers as offsets from there.
50
 
51
   As of today, we support a single stub, providing CFI info for common
52
   registers (GPRs, LR, ...). We might need variants with support for floating
53
   point or altivec registers as well at some point.
54
 
55
   Checking which variant should apply and getting at sc_pregs is simpler
56
   to express in C (we can't use offsetof in toplevel asms and hardcoding
57
   constants is not workable with the flurry of VxWorks variants), so this
58
   is the choice for our toplevel interface.
59
 
60
   Note that the registers we "restore" here are those to which we have
61
   direct access through the system sigcontext structure, which includes
62
   only a partial set of the non-volatiles ABI-wise.  */
63
 
64
/* -----------------------------------------
65
   -- Protypes for our internal asm stubs --
66
   -----------------------------------------
67
 
68
   SC_PREGS is always expected to be SIGCONTEXT->sc_pregs.  Eventhough our
69
   symbols will remain local, the prototype claims "extern" and not
70
   "static" to prevent compiler complaints about a symbol used but never
71
   defined.  */
72
 
73
/* sigtramp stub providing CFI info for common registers.  */
74
 
75
extern void __gnat_sigtramp_common
76
(int signo, void *siginfo, void *sigcontext,
77
 sighandler_t * handler, void * sc_pregs);
78
 
79
 
80
/* -------------------------------------
81
   -- Common interface implementation --
82
   -------------------------------------
83
 
84
   We enforce optimization to minimize the overhead of the extra layer.  */
85
 
86
void __gnat_sigtramp (int signo, void *si, void *sc,
87
                      sighandler_t * handler)
88
     __attribute__((optimize(2)));
89
 
90
void __gnat_sigtramp (int signo, void *si, void *sc,
91
                      sighandler_t * handler)
92
{
93
  struct sigcontext * sctx = (struct sigcontext *) sc;
94
 
95
  __gnat_sigtramp_common (signo, si, sctx, handler, sctx->sc_pregs);
96
}
97
 
98
 
99
/* ---------------------------
100
   -- And now the asm stubs --
101
   ---------------------------
102
 
103
   They all have a common structure with blocks of asm sequences queued one
104
   after the others.  Typically:
105
 
106
   SYMBOL_START
107
 
108
   CFI_DIRECTIVES
109
     CFI_DEF_CFA,
110
     CFI_COMMON_REGISTERS,
111
     ...
112
 
113
   STUB_BODY
114
     asm code to establish frame, setup the cfa reg value,
115
     call the real signal handler, ...
116
 
117
   SYMBOL_END
118
*/
119
 
120
/*--------------------------------
121
  -- Misc constants and helpers --
122
  -------------------------------- */
123
 
124
/* REGNO constants, dwarf column numbers for registers of interest.  */
125
 
126
#define REGNO_LR  65
127
#define REGNO_CTR 66
128
#define REGNO_CR  70
129
#define REGNO_XER 76
130
#define REGNO_GR(N) (N)
131
 
132
#define REGNO_PC  67  /* ARG_POINTER_REGNUM  */
133
 
134
/* asm string contruction helpers.  */
135
 
136
#define STR(TEXT) #TEXT
137
/* stringify expanded TEXT, surrounding it with double quotes.  */
138
 
139
#define S(E) STR(E)
140
/* stringify E, which will resolve as text but may contain macros
141
   still to be expanded.  */
142
 
143
/* asm (TEXT) outputs <tab>TEXT. These facilitate the output of
144
   multine contents:  */
145
#define TAB(S) "\t" S
146
#define CR(S)  S "\n"
147
 
148
#undef TCR
149
#define TCR(S) TAB(CR(S))
150
 
151
/*------------------------------
152
  -- Stub construction blocks --
153
  ------------------------------ */
154
 
155
/* CFA setup block
156
   ---------------
157
   Only non-volatile registers are suitable for a CFA base. These are the
158
   only ones we can expect to be able retrieve from the unwinding context
159
   while walking up the chain, saved by at least the bottom-most exception
160
   propagation services.  We use r15 here and set it to the value we need
161
   in stub body that follows.  Note that r14 is inappropriate here, even
162
   though it is non-volatile according to the ABI, because GCC uses it as
163
   an extra SCRATCH on SPE targets.  */
164
 
165
#define CFA_REG 15
166
 
167
#define CFI_DEF_CFA \
168
CR(".cfi_def_cfa " S(CFA_REG) ", 0")
169
 
170
/* Register location blocks
171
   ------------------------
172
   Rules to find registers of interest from the CFA. This should comprise
173
   all the non-volatile registers relevant to the interrupted context.
174
 
175
   Note that we include r1 in this set, unlike the libgcc unwinding
176
   fallbacks.  This is useful for fallbacks to allow the use of r1 in CFI
177
   expressions and the absence of rule for r1 gets compensated by using the
178
   target CFA instead.  We don't need the expression facility here and
179
   setup a fake CFA to allow very simple offset expressions, so having a
180
   rule for r1 is the proper thing to do.  We for sure have observed
181
   crashes in some cases without it.  */
182
 
183
#define COMMON_CFI(REG) \
184
  ".cfi_offset " S(REGNO_##REG) "," S(REG_SET_##REG)
185
 
186
#define CFI_COMMON_REGS \
187
CR("# CFI for common registers\n") \
188
TCR(COMMON_CFI(GR(1)))  \
189
TCR(COMMON_CFI(GR(2)))  \
190
TCR(COMMON_CFI(GR(3)))  \
191
TCR(COMMON_CFI(GR(4)))  \
192
TCR(COMMON_CFI(GR(5)))  \
193
TCR(COMMON_CFI(GR(6)))  \
194
TCR(COMMON_CFI(GR(7)))  \
195
TCR(COMMON_CFI(GR(8)))  \
196
TCR(COMMON_CFI(GR(9)))  \
197
TCR(COMMON_CFI(GR(10)))  \
198
TCR(COMMON_CFI(GR(11)))  \
199
TCR(COMMON_CFI(GR(12)))  \
200
TCR(COMMON_CFI(GR(13)))  \
201
TCR(COMMON_CFI(GR(14))) \
202
TCR(COMMON_CFI(GR(15))) \
203
TCR(COMMON_CFI(GR(16))) \
204
TCR(COMMON_CFI(GR(17))) \
205
TCR(COMMON_CFI(GR(18))) \
206
TCR(COMMON_CFI(GR(19))) \
207
TCR(COMMON_CFI(GR(20))) \
208
TCR(COMMON_CFI(GR(21))) \
209
TCR(COMMON_CFI(GR(22))) \
210
TCR(COMMON_CFI(GR(23))) \
211
TCR(COMMON_CFI(GR(24))) \
212
TCR(COMMON_CFI(GR(25))) \
213
TCR(COMMON_CFI(GR(26))) \
214
TCR(COMMON_CFI(GR(27))) \
215
TCR(COMMON_CFI(GR(28))) \
216
TCR(COMMON_CFI(GR(29))) \
217
TCR(COMMON_CFI(GR(30))) \
218
TCR(COMMON_CFI(GR(31))) \
219
TCR(COMMON_CFI(LR)) \
220
TCR(COMMON_CFI(CR)) \
221
TCR(COMMON_CFI(CTR)) \
222
TCR(COMMON_CFI(XER)) \
223
TCR(COMMON_CFI(PC)) \
224
TCR(".cfi_return_column " S(REGNO_PC))
225
 
226
/* Trampoline body block
227
   ---------------------  */
228
 
229
#define SIGTRAMP_BODY \
230
CR("") \
231
TCR("# Allocate frame and save the non-volatile") \
232
TCR("# registers we're going to modify") \
233
TCR("stwu %r1,-16(%r1)")  \
234
TCR("mflr %r0") \
235
TCR("stw %r0,20(%r1)")  \
236
TCR("stw %r" S(CFA_REG) ",8(%r1)")      \
237
TCR("")                 \
238
TCR("# Setup CFA_REG = sc_pregs, that we'll retrieve as our CFA value") \
239
TCR("mr %r" S(CFA_REG) ", %r7") \
240
TCR("")                 \
241
TCR("# Call the real handler. The signo, siginfo and sigcontext") \
242
TCR("# arguments are the same as those we received in r3, r4 and r5") \
243
TCR("mtctr %r6") \
244
TCR("bctrl")    \
245
TCR("")         \
246
TCR("# Restore our callee-saved items, release our frame and return") \
247
TCR("lwz %r" S(CFA_REG) ",8(%r1)")      \
248
TCR("lwz %r0,20(%r1)")  \
249
TCR("mtlr %r0")         \
250
TCR("")                 \
251
TCR("addi %r1,%r1,16")  \
252
TCR("blr")
253
 
254
/* Symbol definition block
255
   -----------------------  */
256
 
257
#define SIGTRAMP_START(SYM) \
258
CR("# " S(SYM) " cfi trampoline") \
259
TCR(".type " S(SYM) ", @function") \
260
CR("") \
261
CR(S(SYM) ":") \
262
TCR(".cfi_startproc") \
263
TCR(".cfi_signal_frame")
264
 
265
/* Symbol termination block
266
   ------------------------  */
267
 
268
#define SIGTRAMP_END(SYM) \
269
CR(".cfi_endproc") \
270
TCR(".size " S(SYM) ", .-" S(SYM))
271
 
272
/*----------------------------
273
  -- And now, the real code --
274
  ---------------------------- */
275
 
276
/* Text section start.  The compiler isn't aware of that switch.  */
277
 
278
asm (".text\n"
279
     TCR(".align 2"));
280
 
281
/* sigtramp stub for common registers.  */
282
 
283
#define TRAMP_COMMON __gnat_sigtramp_common
284
 
285
asm (SIGTRAMP_START(TRAMP_COMMON));
286
asm (CFI_DEF_CFA);
287
asm (CFI_COMMON_REGS);
288
asm (SIGTRAMP_BODY);
289
asm (SIGTRAMP_END(TRAMP_COMMON));
290
 
291
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.