* config/nvptx/nvptx.c (nvptx_option_override): Emit sorry for
[official-gcc.git] / gcc / ada / sigtramp-vxworks-target.inc
bloba031360cd21852ec5995fb41f55f39b7337816d2
1 /****************************************************************************
2  *                                                                          *
3  *                         GNAT COMPILER COMPONENTS                         *
4  *                                                                          *
5  *                      S I G T R A M P - T A R G E T                       *
6  *                                                                          *
7  *                     Asm Implementation Include File                      *
8  *                                                                          *
9  *         Copyright (C) 2011-2015, 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  * In particular,  you can freely  distribute your programs  built with the *
23  * GNAT Pro compiler, including any required library run-time units,  using *
24  * any licensing terms  of your choosing.  See the AdaCore Software License *
25  * for full details.                                                        *
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  ****************************************************************************/
32 /***************************************************************
33  * VxWorks target specific part of the __gnat_sigtramp service *
34  ***************************************************************/
36 /* Note: This target specific part is kept in a separate file to avoid
37    duplication of its code for the vxworks and vxworks-vxsim asm
38    implementation files.  */
40 /* ---------------------------
41    -- And now the asm stubs --
42    ---------------------------
44    They all have a common structure with blocks of asm sequences queued one
45    after the others.  Typically:
47    SYMBOL_START
49    CFI_DIRECTIVES
50      CFI_DEF_CFA,
51      CFI_COMMON_REGISTERS,
52      ...
54    STUB_BODY
55      asm code to establish frame, setup the cfa reg value,
56      call the real signal handler, ...
58    SYMBOL_END
61 /*--------------------------------
62   -- Misc constants and helpers --
63   -------------------------------- */
65 /* asm string construction helpers.  */
67 #define STR(TEXT) #TEXT
68 /* stringify expanded TEXT, surrounding it with double quotes.  */
70 #define S(E) STR(E)
71 /* stringify E, which will resolve as text but may contain macros
72    still to be expanded.  */
74 /* asm (TEXT) outputs <tab>TEXT. These facilitate the output of
75    multine contents:  */
76 #define TAB(S) "\t" S
77 #define CR(S)  S "\n"
79 #undef TCR
80 #define TCR(S) TAB(CR(S))
82 /* REGNO constants, dwarf column numbers for registers of interest.  */
84 #if defined (__PPC__)
86 #define REGNO_LR  65
87 #define REGNO_CTR 66
88 #define REGNO_CR  70
89 #define REGNO_XER 76
90 #define REGNO_GR(N) (N)
92 #define REGNO_PC  67  /* ARG_POINTER_REGNUM  */
94 #define FUNCTION "@function"
96 #elif defined (__ARMEL__)
98 #define REGNO_G_REG_OFFSET(N) (N)
100 #define REGNO_PC_OFFSET  15  /* PC_REGNUM  */
102 #define FUNCTION "%function"
104 #elif defined (i386)
106 /* These are the cfi colunm numbers */
108 #define REGNO_EDI 7
109 #define REGNO_ESI 6
110 #define REGNO_EBP 5
111 #define REGNO_ESP 4
112 #define REGNO_EBX 3
113 #define REGNO_EDX 2
114 #define REGNO_ECX 1
115 #define REGNO_EAX 0
116 #define REGNO_EFLAGS 9
117 #define REGNO_SET_PC 8 /* aka %eip */
119 #define FUNCTION "@function"
121 /* Mapping of CFI Column, Gcc Regno, Signal context offset for 32bit
123    Name    CFI     GCC     SCTX
124    %eax     0       0       7
125    %ecx     1       2       6
126    %edx     2       1       5
127    %ebx     3       3       4
128    %esp     4       7       3
129    %ebp     5       6       2
130    %esi     6       4       1
131    %edi     7       5       0
132    %eflags  9      17       8
133    %eip     8     n/a       9
136    In general:
137    There is no unique numbering for the x86 architecture.  It's parameterized
138    by DWARF_FRAME_REGNUM, which is DBX_REGISTER_NUMBER except for Windows, and
139    the latter depends on the platform.
142 #elif defined (__x86_64__)
144 /* These are the cfi colunm numbers */
146 #define REGNO_RAX 0
147 #define REGNO_RDX 1
148 #define REGNO_RCX 2
149 #define REGNO_RBX 3
150 #define REGNO_RSI 4
151 #define REGNO_RDI 5
152 #define REGNO_RBP 6
153 #define REGNO_RSP 7
154 #define REGNO_R8 8
155 #define REGNO_R9 9
156 #define REGNO_R10 10
157 #define REGNO_R11 11
158 #define REGNO_R12 12
159 #define REGNO_R13 13
160 #define REGNO_R14 14
161 #define REGNO_R15 15
162 #define REGNO_SET_PC 16 /* aka %rip */
163 #define REGNO_EFLAGS 49
164 #define REGNO_FS 54
166 #define FUNCTION "@function"
168 #else
169 Not_implemented;
170 #endif /* REGNO constants */
173 /*------------------------------
174   -- Stub construction blocks --
175   ------------------------------ */
177 /* CFA setup block
178    ---------------
179    Only non-volatile registers are suitable for a CFA base. These are the
180    only ones we can expect to be able retrieve from the unwinding context
181    while walking up the chain, saved by at least the bottom-most exception
182    propagation services.  We set a non-volatile register to the value we
183    need in the stub body that follows.  */
185 #if defined (__PPC__)
187 /* Use r15 for PPC.  Note that r14 is inappropriate here, even though it
188    is non-volatile according to the ABI, because GCC uses it as an extra
189    SCRATCH on SPE targets.  */
191 #define CFA_REG 15
193 #elif defined (__ARMEL__)
195 /* Use r8 for ARM.  Any of r4-r8 should work.  */
197 #define CFA_REG 8
199 #elif defined (i386)
201 #define CFA_REG 7
203 #elif defined (__x86_64__)
205 /* R15 register */
206 #define CFA_REG 15
208 #else
209 Not_implemented;
210 #endif /* CFA setup block */
212 #define CFI_DEF_CFA \
213 CR(".cfi_def_cfa " S(CFA_REG) ", 0")
215 /* Register location blocks
216    ------------------------
217    Rules to find registers of interest from the CFA. This should comprise
218    all the non-volatile registers relevant to the interrupted context.
220    Note that we include r1 in this set, unlike the libgcc unwinding
221    fallbacks.  This is useful for fallbacks to allow the use of r1 in CFI
222    expressions and the absence of rule for r1 gets compensated by using the
223    target CFA instead.  We don't need the expression facility here and
224    setup a fake CFA to allow very simple offset expressions, so having a
225    rule for r1 is the proper thing to do.  We for sure have observed
226    crashes in some cases without it.  */
228 #if defined (__PPC__)
230 #define COMMON_CFI(REG) \
231   ".cfi_offset " S(REGNO_##REG) "," S(REG_SET_##REG)
233 #define CFI_COMMON_REGS \
234 CR("# CFI for common registers\n") \
235 TCR(COMMON_CFI(GR(0)))  \
236 TCR(COMMON_CFI(GR(1)))  \
237 TCR(COMMON_CFI(GR(2)))  \
238 TCR(COMMON_CFI(GR(3)))  \
239 TCR(COMMON_CFI(GR(4)))  \
240 TCR(COMMON_CFI(GR(5)))  \
241 TCR(COMMON_CFI(GR(6)))  \
242 TCR(COMMON_CFI(GR(7)))  \
243 TCR(COMMON_CFI(GR(8)))  \
244 TCR(COMMON_CFI(GR(9)))  \
245 TCR(COMMON_CFI(GR(10)))  \
246 TCR(COMMON_CFI(GR(11)))  \
247 TCR(COMMON_CFI(GR(12)))  \
248 TCR(COMMON_CFI(GR(13)))  \
249 TCR(COMMON_CFI(GR(14))) \
250 TCR(COMMON_CFI(GR(15))) \
251 TCR(COMMON_CFI(GR(16))) \
252 TCR(COMMON_CFI(GR(17))) \
253 TCR(COMMON_CFI(GR(18))) \
254 TCR(COMMON_CFI(GR(19))) \
255 TCR(COMMON_CFI(GR(20))) \
256 TCR(COMMON_CFI(GR(21))) \
257 TCR(COMMON_CFI(GR(22))) \
258 TCR(COMMON_CFI(GR(23))) \
259 TCR(COMMON_CFI(GR(24))) \
260 TCR(COMMON_CFI(GR(25))) \
261 TCR(COMMON_CFI(GR(26))) \
262 TCR(COMMON_CFI(GR(27))) \
263 TCR(COMMON_CFI(GR(28))) \
264 TCR(COMMON_CFI(GR(29))) \
265 TCR(COMMON_CFI(GR(30))) \
266 TCR(COMMON_CFI(GR(31))) \
267 TCR(COMMON_CFI(LR)) \
268 TCR(COMMON_CFI(CR)) \
269 TCR(COMMON_CFI(CTR)) \
270 TCR(COMMON_CFI(XER)) \
271 TCR(COMMON_CFI(PC)) \
272 TCR(".cfi_return_column " S(REGNO_PC))
274 /* Trampoline body block
275    ---------------------  */
277 #define SIGTRAMP_BODY \
278 CR("") \
279 TCR("# Allocate frame and save the non-volatile") \
280 TCR("# registers we're going to modify") \
281 TCR("stwu %r1,-16(%r1)")  \
282 TCR("mflr %r0") \
283 TCR("stw %r0,20(%r1)")  \
284 TCR("stw %r" S(CFA_REG) ",8(%r1)")      \
285 TCR("")                 \
286 TCR("# Setup CFA_REG = context, which we'll retrieve as our CFA value") \
287 TCR("mr %r" S(CFA_REG) ", %r7") \
288 TCR("")                 \
289 TCR("# Call the real handler. The signo, siginfo and sigcontext") \
290 TCR("# arguments are the same as those we received in r3, r4 and r5") \
291 TCR("mtctr %r6") \
292 TCR("bctrl")    \
293 TCR("")         \
294 TCR("# Restore our callee-saved items, release our frame and return") \
295 TCR("lwz %r" S(CFA_REG) ",8(%r1)")      \
296 TCR("lwz %r0,20(%r1)")  \
297 TCR("mtlr %r0")         \
298 TCR("")                 \
299 TCR("addi %r1,%r1,16")  \
300 TCR("blr")
302 #elif defined (__ARMEL__)
304 #define COMMON_CFI(REG) \
305   ".cfi_offset " S(REGNO_##REG) "," S(REG_SET_##REG)
307 #define CFI_COMMON_REGS \
308 CR("# CFI for common registers\n") \
309 TCR(COMMON_CFI(G_REG_OFFSET(0)))  \
310 TCR(COMMON_CFI(G_REG_OFFSET(1)))  \
311 TCR(COMMON_CFI(G_REG_OFFSET(2)))  \
312 TCR(COMMON_CFI(G_REG_OFFSET(3)))  \
313 TCR(COMMON_CFI(G_REG_OFFSET(4)))  \
314 TCR(COMMON_CFI(G_REG_OFFSET(5)))  \
315 TCR(COMMON_CFI(G_REG_OFFSET(6)))  \
316 TCR(COMMON_CFI(G_REG_OFFSET(7)))  \
317 TCR(COMMON_CFI(G_REG_OFFSET(8)))  \
318 TCR(COMMON_CFI(G_REG_OFFSET(9)))  \
319 TCR(COMMON_CFI(G_REG_OFFSET(10)))  \
320 TCR(COMMON_CFI(G_REG_OFFSET(11)))  \
321 TCR(COMMON_CFI(G_REG_OFFSET(12)))  \
322 TCR(COMMON_CFI(G_REG_OFFSET(13)))  \
323 TCR(COMMON_CFI(G_REG_OFFSET(14))) \
324 TCR(COMMON_CFI(PC_OFFSET)) \
325 TCR(".cfi_return_column " S(REGNO_PC_OFFSET))
327 /* Trampoline body block
328    ---------------------  */
330 #define SIGTRAMP_BODY \
331 CR("") \
332 TCR("# Allocate frame and save the non-volatile") \
333 TCR("# registers we're going to modify") \
334 TCR("mov        ip, sp") \
335 TCR("stmfd      sp!, {r"S(CFA_REG)", fp, ip, lr, pc}") \
336 TCR("# Setup CFA_REG = context, which we'll retrieve as our CFA value") \
337 TCR("ldr        r"S(CFA_REG)", [ip]") \
338 TCR("")                 \
339 TCR("# Call the real handler. The signo, siginfo and sigcontext") \
340 TCR("# arguments are the same as those we received in r0, r1 and r2") \
341 TCR("sub        fp, ip, #4") \
342 TCR("blx        r3") \
343 TCR("# Restore our callee-saved items, release our frame and return") \
344 TCR("ldmfd      sp, {r"S(CFA_REG)", fp, sp, pc}")
346 #elif defined (i386)
348 #if CPU == SIMNT || CPU == SIMPENTIUM || CPU == SIMLINUX
349 #define COMMON_CFI(REG) \
350   ".cfi_offset " S(REGNO_##REG) "," S(REG_SET_##REG)
351 #else
352 #define COMMON_CFI(REG) \
353   ".cfi_offset " S(REGNO_##REG) "," S(REG_##REG)
354 #endif
356 #define PC_CFI(REG) \
357   ".cfi_offset " S(REGNO_##REG) "," S(REG_##REG)
359 #define CFI_COMMON_REGS \
360 CR("# CFI for common registers\n") \
361 TCR(COMMON_CFI(EDI)) \
362 TCR(COMMON_CFI(ESI)) \
363 TCR(COMMON_CFI(EBP)) \
364 TCR(COMMON_CFI(ESP)) \
365 TCR(COMMON_CFI(EBX)) \
366 TCR(COMMON_CFI(EDX)) \
367 TCR(COMMON_CFI(ECX)) \
368 TCR(COMMON_CFI(EAX)) \
369 TCR(COMMON_CFI(EFLAGS)) \
370 TCR(PC_CFI(SET_PC)) \
371 TCR(".cfi_return_column " S(REGNO_SET_PC))
373 /* Trampoline body block
374    ---------------------  */
376 #define SIGTRAMP_BODY \
377 CR("") \
378 TCR("# Allocate frame and save the non-volatile") \
379 TCR("# registers we're going to modify") \
380 TCR("pushl      %ebp") \
381 TCR("movl       %esp, %ebp") \
382 TCR("pushl      %edi") \
383 TCR("subl       $24, %esp") \
384 TCR("# Setup CFA_REG = context, which we'll retrieve as our CFA value") \
385 TCR("movl       24(%ebp), %edi") \
386 TCR("# Call the real handler. The signo, siginfo and sigcontext") \
387 TCR("# arguments are the same as those we received") \
388 TCR("movl       16(%ebp), %eax") \
389 TCR("movl       %eax, 8(%esp)") \
390 TCR("movl       12(%ebp), %eax") \
391 TCR("movl       %eax, 4(%esp)") \
392 TCR("movl       8(%ebp), %eax") \
393 TCR("movl       %eax, (%esp)") \
394 TCR("call       *20(%ebp)") \
395 TCR("# Restore our callee-saved items, release our frame and return") \
396 TCR("popl       %edi") \
397 TCR("leave") \
398 TCR("ret")
400 #elif defined (__x86_64__)
402 #define COMMON_CFI(REG) \
403   ".cfi_offset " S(REGNO_##REG) "," S(REG_##REG)
404 #define PC_CFI(REG) \
405   ".cfi_offset " S(REGNO_##REG) "," S(REG_##REG)
407 #define CFI_COMMON_REGS \
408 CR("# CFI for common registers\n") \
409 TCR(COMMON_CFI(R15)) \
410 TCR(COMMON_CFI(R14)) \
411 TCR(COMMON_CFI(R13)) \
412 TCR(COMMON_CFI(R12)) \
413 TCR(COMMON_CFI(R11)) \
414 TCR(COMMON_CFI(R10)) \
415 TCR(COMMON_CFI(R9)) \
416 TCR(COMMON_CFI(R8)) \
417 TCR(COMMON_CFI(RDI)) \
418 TCR(COMMON_CFI(RSI)) \
419 TCR(COMMON_CFI(RBP)) \
420 TCR(COMMON_CFI(RSP)) \
421 TCR(COMMON_CFI(RBX)) \
422 TCR(COMMON_CFI(RDX)) \
423 TCR(COMMON_CFI(RCX)) \
424 TCR(COMMON_CFI(RAX)) \
425 TCR(COMMON_CFI(EFLAGS)) \
426 TCR(COMMON_CFI(SET_PC)) \
427 TCR(COMMON_CFI(FS)) \
428 TCR(".cfi_return_column " S(REGNO_SET_PC))
430 /* Trampoline body block
431    ---------------------  */
433 #define SIGTRAMP_BODY \
434 CR("") \
435 TCR("# Allocate frame and save the non-volatile") \
436 TCR("# registers we're going to modify") \
437 TCR("subq       $8, %rsp") \
438 TCR("# Setup CFA_REG = context, which we'll retrieve as our CFA value") \
439 TCR("movq       %r8, %r15") \
440 TCR("# Call the real handler. The signo, siginfo and sigcontext") \
441 TCR("# arguments are the same as those we received") \
442 TCR("call       *%rcx") \
443 TCR("# This part should never be executed") \
444 TCR("addq       $8, %rsp") \
445 TCR("ret")
447 #else
448 Not_implemented;
449 #endif /* CFI_COMMON_REGS and SIGTRAMP_BODY */
451 /* Symbol definition block
452    -----------------------  */
454 #define SIGTRAMP_START(SYM) \
455 CR("# " S(SYM) " cfi trampoline") \
456 TCR(".type " S(SYM) ", "FUNCTION) \
457 CR("") \
458 CR(S(SYM) ":") \
459 TCR(".cfi_startproc") \
460 TCR(".cfi_signal_frame")
462 /* Symbol termination block
463    ------------------------  */
465 #define SIGTRAMP_END(SYM) \
466 CR(".cfi_endproc") \
467 TCR(".size " S(SYM) ", .-" S(SYM))
469 /*----------------------------
470   -- And now, the real code --
471   ---------------------------- */
473 /* Text section start.  The compiler isn't aware of that switch.  */
475 asm (".text\n"
476      TCR(".align 2"));