jit: document union types
[official-gcc.git] / gcc / ada / sigtramp-armdroid.c
blobfb522dfcd994ab5af7055c11d5a9d7d0b11ed283
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * S I G T R A M P *
6 * *
7 * Asm Implementation File *
8 * *
9 * Copyright (C) 2014, 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 * ARM-Android version of the __gnat_sigtramp service *
34 ******************************************************/
36 #include "sigtramp.h"
37 /* See sigtramp.h for a general explanation of functionality. */
39 /* ----------------------
40 -- General comments --
41 ----------------------
43 Stubs are generated from toplevel asms,
44 The general idea is to establish CFA as the sigcontext
45 and state where to find the registers as offsets from there.
47 We support stubs for VxWorks and Android, providing unwind info for
48 common registers. We might need variants with support for floating
49 point or altivec registers as well at some point.
51 For Android it would be simpler to write this in Asm since there's only
52 one variant, but to keep it looking like the VxWorks stubs,
53 C is the choice for our toplevel interface.
55 Note that the registers we "restore" here are those to which we have
56 direct access through the system sigcontext structure, which includes
57 only a partial set of the non-volatiles ABI-wise. */
59 /* -----------------------------------------
60 -- Protypes for our internal asm stubs --
61 -----------------------------------------
63 The registers are expected to be at SIGCONTEXT + 12 (reference the
64 sicontext structure in asm/sigcontext.h which describes the first
65 3 * 4byte fields.) Even though our symbols will remain local, the
66 prototype claims "extern" and not "static" to prevent compiler complaints
67 about a symbol used but never defined. */
69 /* sigtramp stub providing unwind info for common registers. */
71 extern void __gnat_sigtramp_common
72 (int signo, void *siginfo, void *sigcontext,
73 __sigtramphandler_t * handler);
75 void __gnat_sigtramp (int signo, void *si, void *sc,
76 __sigtramphandler_t * handler)
77 __attribute__((optimize(2)));
79 void __gnat_sigtramp (int signo, void *si, void *ucontext,
80 __sigtramphandler_t * handler)
82 struct sigcontext *mcontext = &((ucontext_t *) ucontext)->uc_mcontext;
84 __gnat_sigtramp_common (signo, si, mcontext, handler);
87 /* asm string construction helpers. */
89 #define STR(TEXT) #TEXT
90 /* stringify expanded TEXT, surrounding it with double quotes. */
92 #define S(E) STR(E)
93 /* stringify E, which will resolve as text but may contain macros
94 still to be expanded. */
96 /* asm (TEXT) outputs <tab>TEXT. These facilitate the output of
97 multiline contents: */
98 #define TAB(S) "\t" S
99 #define CR(S) S "\n"
101 #undef TCR
102 #define TCR(S) TAB(CR(S))
104 /* Trampoline body block
105 --------------------- */
107 #define SIGTRAMP_BODY \
108 CR("") \
109 TCR("# Allocate frame and also save r2 which is the argument register") \
110 TCR("# containing the sigcontext, so that we can restore it during") \
111 TCR("# unwinding and thereby load the rest of the desired context.") \
112 TCR("stmfd sp!, {r2, r3, lr}") \
113 TCR("# The unwinder undo's these operations in reverse order so starting") \
114 TCR("# from bottom, restore r2 from the current vsp location, move r2 into") \
115 TCR("# the vsp, add 12 bytes to get the start of the register save area") \
116 TCR("# then restore the 15 general purpose registers of the frame which") \
117 TCR("# raised the signal.") \
118 TCR(".save {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15}") \
119 TCR(".pad #12") \
120 TCR(".movsp r2") \
121 TCR(".save {r2}") \
122 TCR("# Call the real handler. The signo, siginfo and sigcontext") \
123 TCR("# arguments are the same as those we received in r0, r1 and r2.") \
124 TCR("blx r3") \
125 TCR("# Restore our callee-saved items, release our frame and return") \
126 TCR("# (should never get here!).") \
127 TCR("ldmfd sp, {r2, r3, pc}")
129 /* Symbol definition block
130 ----------------------- */
132 #define SIGTRAMP_START(SYM) \
133 CR("# " S(SYM) " unwind trampoline") \
134 TCR(".type " S(SYM) ", %function") \
135 CR("") \
136 CR(S(SYM) ":") \
137 TCR(".fnstart")
139 /* Symbol termination block
140 ------------------------ */
142 #define SIGTRAMP_END(SYM) \
143 CR(".fnend") \
144 TCR(".size " S(SYM) ", .-" S(SYM))
146 /*----------------------------
147 -- And now, the real code --
148 ---------------------------- */
150 /* Text section start. The compiler isn't aware of that switch. */
152 asm (".text\n"
153 TCR(".align 2"));
155 /* sigtramp stub for common registers. */
157 #define TRAMP_COMMON __gnat_sigtramp_common
159 asm (SIGTRAMP_START(TRAMP_COMMON));
160 asm (SIGTRAMP_BODY);
161 asm (SIGTRAMP_END(TRAMP_COMMON));