Debian Codegraph @

gcc/ada/sigtramp-android-asm.h

raw
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) 2024-2025, 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 ****************************************************************************/
31
32 /*****************************************************************
33 * CPU specific parts of the __gnat_sigtramp service for Android *
34 *****************************************************************/
35
36 /* The intended use mode of this header is to provide macros
37 and a prologue to the generation of an asm function, as in
38
39 #include <this-header>
40 asm (SIGTRAMP_START(<symbol-name>));
41 asm (SIGTRAMP_BODY);
42 asm (SIGTRAMP_END(<symbol-name>));
43
44 and nothing else after. */
45
46 /* asm string construction helpers. */
47
48 #define STR(TEXT) #TEXT
49 /* stringify expanded TEXT, surrounding it with double quotes. */
50
51 #define S(E) STR(E)
52 /* stringify E, which will resolve as text but may contain macros
53 still to be expanded. */
54
55 /* asm (TEXT) outputs <tab>TEXT. These facilitate the output of
56 multiline contents: */
57 #define TAB(S) "\t" S
58 #define CR(S) S "\n"
59
60 #undef TCR
61 #define TCR(S) TAB(CR(S))
62
63 #if defined(__arm__)
64
65 /* Trampoline body block
66 --------------------- */
67
68 #define SIGTRAMP_BODY \
69 CR("") \
70 TCR("# Allocate frame and also save r2 which is the argument register") \
71 TCR("# containing the sigcontext, so that we can restore it during") \
72 TCR("# unwinding and thereby load the rest of the desired context.") \
73 TCR("stmfd sp!, {r2, r3, lr}") \
74 TCR("# The unwinder undo's these operations in reverse order so starting") \
75 TCR("# from bottom, restore r2 from the current vsp location, move r2 into") \
76 TCR("# the vsp, add 12 bytes to get the start of the register save area") \
77 TCR("# then restore the 15 general purpose registers of the frame which") \
78 TCR("# raised the signal.") \
79 TCR(".save {r0-r15}") \
80 TCR(".pad #12") \
81 TCR(".movsp r2") \
82 TCR(".save {r2}") \
83 TCR("# Call the real handler. The signo, siginfo and sigcontext") \
84 TCR("# arguments are the same as those we received in r0, r1 and r2.") \
85 TCR("blx r3") \
86 TCR("# Restore our callee-saved items, release our frame and return") \
87 TCR("# (should never get here!).") \
88 TCR("ldmfd sp, {r2, r3, pc}")
89
90 /* Symbol definition block
91 ----------------------- */
92
93 #define SIGTRAMP_START(SYM) \
94 CR("# " S(SYM) " unwind trampoline") \
95 TCR(".type " S(SYM) ", %function") \
96 CR("") \
97 CR(S(SYM) ":") \
98 TCR(".fnstart")
99
100 /* Symbol termination block
101 ------------------------ */
102
103 #define SIGTRAMP_END(SYM) \
104 CR(".fnend") \
105 TCR(".size " S(SYM) ", .-" S(SYM))
106
107 #endif
108
109 /* Text section start. The compiler isn't aware of that switch. */
110
111 asm (".text\n"
112 TCR(".align 2"));