]> git.ipfire.org Git - people/ms/u-boot.git/blame - examples/standalone/stubs.c
imx-common: compile plugin code
[people/ms/u-boot.git] / examples / standalone / stubs.c
CommitLineData
0910d0bc 1#include <common.h>
27b207fd 2#include <exports.h>
2d5db193 3#include <linux/compiler.h>
93f6a677 4
49cad547
MD
5#define FO(x) offsetof(struct jt_funcs, x)
6
fea25720 7#if defined(CONFIG_X86)
27b207fd
WD
8/*
9 * x86 does not have a dedicated register to store the pointer to
10 * the global_data. Thus the jump table address is stored in a
11 * global variable, but such approach does not allow for execution
12 * from flash memory. The global_data address is passed as argv[-1]
13 * to the application program.
14 */
49cad547 15static struct jt_funcs *jt;
77846748 16gd_t *global_data;
27b207fd 17
49cad547 18#define EXPORT_FUNC(f, a, x, ...) \
27b207fd
WD
19 asm volatile ( \
20" .globl " #x "\n" \
21#x ":\n" \
22" movl %0, %%eax\n" \
23" movl jt, %%ecx\n" \
24" jmp *(%%ecx, %%eax)\n" \
49cad547 25 : : "i"(FO(x)) : "eax", "ecx");
27b207fd
WD
26#elif defined(CONFIG_PPC)
27/*
e7670f6c 28 * r2 holds the pointer to the global_data, r11 is a call-clobbered
27b207fd
WD
29 * register
30 */
49cad547 31#define EXPORT_FUNC(f, a, x, ...) \
27b207fd
WD
32 asm volatile ( \
33" .globl " #x "\n" \
34#x ":\n" \
e7670f6c 35" lwz %%r11, %0(%%r2)\n" \
27b207fd
WD
36" lwz %%r11, %1(%%r11)\n" \
37" mtctr %%r11\n" \
38" bctr\n" \
49cad547 39 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11");
27b207fd 40#elif defined(CONFIG_ARM)
0ae76531
DF
41#ifdef CONFIG_ARM64
42/*
43 * x18 holds the pointer to the global_data, x9 is a call-clobbered
44 * register
45 */
49cad547 46#define EXPORT_FUNC(f, a, x, ...) \
0ae76531
DF
47 asm volatile ( \
48" .globl " #x "\n" \
49#x ":\n" \
50" ldr x9, [x18, %0]\n" \
51" ldr x9, [x9, %1]\n" \
52" br x9\n" \
49cad547 53 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9");
0ae76531 54#else
27b207fd 55/*
a5a42eec 56 * r9 holds the pointer to the global_data, ip is a call-clobbered
27b207fd
WD
57 * register
58 */
49cad547 59#define EXPORT_FUNC(f, a, x, ...) \
27b207fd
WD
60 asm volatile ( \
61" .globl " #x "\n" \
62#x ":\n" \
a5a42eec 63" ldr ip, [r9, %0]\n" \
27b207fd 64" ldr pc, [ip, %1]\n" \
49cad547 65 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip");
0ae76531 66#endif
27b207fd 67#elif defined(CONFIG_MIPS)
4a48cfc4
SG
68#ifdef CONFIG_CPU_MIPS64
69/*
70 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
71 * clobbered register that is also used to set gp ($26). Note that the
72 * jr instruction also executes the instruction immediately following
73 * it; however, GCC/mips generates an additional `nop' after each asm
74 * statement
75 */
76#define EXPORT_FUNC(f, a, x, ...) \
77 asm volatile ( \
78" .globl " #x "\n" \
79#x ":\n" \
80" ld $25, %0($26)\n" \
81" ld $25, %1($25)\n" \
82" jr $25\n" \
83 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
84#else
27b207fd
WD
85/*
86 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
87 * clobbered register that is also used to set gp ($26). Note that the
88 * jr instruction also executes the instruction immediately following
89 * it; however, GCC/mips generates an additional `nop' after each asm
90 * statement
91 */
49cad547 92#define EXPORT_FUNC(f, a, x, ...) \
27b207fd
WD
93 asm volatile ( \
94" .globl " #x "\n" \
95#x ":\n" \
96" lw $25, %0($26)\n" \
97" lw $25, %1($25)\n" \
98" jr $25\n" \
49cad547 99 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
4a48cfc4 100#endif
5c952cf0
WD
101#elif defined(CONFIG_NIOS2)
102/*
0df01fd3 103 * gp holds the pointer to the global_data, r8 is call-clobbered
5c952cf0 104 */
49cad547 105#define EXPORT_FUNC(f, a, x, ...) \
5c952cf0
WD
106 asm volatile ( \
107" .globl " #x "\n" \
108#x ":\n" \
109" movhi r8, %%hi(%0)\n" \
110" ori r8, r0, %%lo(%0)\n" \
0df01fd3 111" add r8, r8, gp\n" \
5c952cf0
WD
112" ldw r8, 0(r8)\n" \
113" ldw r8, %1(r8)\n" \
114" jmp r8\n" \
49cad547 115 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp");
bf9e3b38
WD
116#elif defined(CONFIG_M68K)
117/*
118 * d7 holds the pointer to the global_data, a0 is a call-clobbered
119 * register
120 */
49cad547 121#define EXPORT_FUNC(f, a, x, ...) \
bf9e3b38
WD
122 asm volatile ( \
123" .globl " #x "\n" \
124#x ":\n" \
125" move.l %%d7, %%a0\n" \
126" adda.l %0, %%a0\n" \
127" move.l (%%a0), %%a0\n" \
128" adda.l %1, %%a0\n" \
129" move.l (%%a0), %%a0\n" \
130" jmp (%%a0)\n" \
49cad547 131 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0");
857cad37 132#elif defined(CONFIG_MICROBLAZE)
507bbe3e
WD
133/*
134 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
135 */
49cad547 136#define EXPORT_FUNC(f, a, x, ...) \
507bbe3e
WD
137 asm volatile ( \
138" .globl " #x "\n" \
139#x ":\n" \
140" lwi r5, r31, %0\n" \
141" lwi r5, r5, %1\n" \
142" bra r5\n" \
49cad547 143 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5");
0afe519a
WD
144#elif defined(CONFIG_BLACKFIN)
145/*
c4db335c 146 * P3 holds the pointer to the global_data, P0 is a call-clobbered
0afe519a
WD
147 * register
148 */
49cad547 149#define EXPORT_FUNC(f, a, x, ...) \
8e7b703a 150 asm volatile ( \
61fb15c5 151" .globl _" #x "\n_" \
0afe519a 152#x ":\n" \
c4db335c 153" P0 = [P3 + %0]\n" \
0afe519a
WD
154" P0 = [P0 + %1]\n" \
155" JUMP (P0)\n" \
49cad547 156 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "P0");
7b64fef3
WD
157#elif defined(CONFIG_AVR32)
158/*
159 * r6 holds the pointer to the global_data. r8 is call clobbered.
160 */
49cad547 161#define EXPORT_FUNC(f, a, x, ...) \
7b64fef3
WD
162 asm volatile( \
163 " .globl\t" #x "\n" \
164 #x ":\n" \
165 " ld.w r8, r6[%0]\n" \
166 " ld.w pc, r8[%1]\n" \
167 : \
49cad547 168 : "i"(offsetof(gd_t, jt)), "i"(FO(x)) \
7b64fef3 169 : "r8");
0b135cfc
NI
170#elif defined(CONFIG_SH)
171/*
172 * r13 holds the pointer to the global_data. r1 is a call clobbered.
173 */
49cad547 174#define EXPORT_FUNC(f, a, x, ...) \
61fb15c5
WD
175 asm volatile ( \
176 " .align 2\n" \
177 " .globl " #x "\n" \
178 #x ":\n" \
179 " mov r13, r1\n" \
180 " add %0, r1\n" \
cae6f909
NI
181 " mov.l @r1, r2\n" \
182 " add %1, r2\n" \
183 " mov.l @r2, r1\n" \
61fb15c5
WD
184 " jmp @r1\n" \
185 " nop\n" \
186 " nop\n" \
49cad547 187 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2");
c2f02da2
DH
188#elif defined(CONFIG_SPARC)
189/*
190 * g7 holds the pointer to the global_data. g1 is call clobbered.
191 */
49cad547 192#define EXPORT_FUNC(f, a, x, ...) \
c2f02da2
DH
193 asm volatile( \
194" .globl\t" #x "\n" \
195#x ":\n" \
196" set %0, %%g1\n" \
197" or %%g1, %%g7, %%g1\n" \
198" ld [%%g1], %%g1\n" \
199" ld [%%g1 + %1], %%g1\n" \
2c0c58b9 200" jmp %%g1\n" \
c2f02da2 201" nop\n" \
49cad547 202 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "g1");
72c73dde
ML
203#elif defined(CONFIG_NDS32)
204/*
205 * r16 holds the pointer to the global_data. gp is call clobbered.
206 * not support reduced register (16 GPR).
207 */
49cad547 208#define EXPORT_FUNC(f, a, x, ...) \
72c73dde
ML
209 asm volatile ( \
210" .globl " #x "\n" \
211#x ":\n" \
212" lwi $r16, [$gp + (%0)]\n" \
213" lwi $r16, [$r16 + (%1)]\n" \
214" jr $r16\n" \
49cad547 215 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "$r16");
3553493d
SK
216#elif defined(CONFIG_OPENRISC)
217/*
218 * r10 holds the pointer to the global_data, r13 is a call-clobbered
219 * register
220 */
49cad547 221#define EXPORT_FUNC(f, a, x, ...) \
3553493d
SK
222 asm volatile ( \
223" .globl " #x "\n" \
224#x ":\n" \
225" l.lwz r13, %0(r10)\n" \
226" l.lwz r13, %1(r13)\n" \
227" l.jr r13\n" \
228" l.nop\n" \
49cad547 229 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r13");
794ab574
AB
230#elif defined(CONFIG_ARC)
231/*
232 * r25 holds the pointer to the global_data. r10 is call clobbered.
233 */
49cad547 234#define EXPORT_FUNC(f, a, x, ...) \
794ab574
AB
235 asm volatile( \
236" .align 4\n" \
237" .globl " #x "\n" \
238#x ":\n" \
239" ld r10, [r25, %0]\n" \
240" ld r10, [r10, %1]\n" \
241" j [r10]\n" \
49cad547 242 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10");
de5e5cea
CZ
243#elif defined(CONFIG_XTENSA)
244/*
245 * Global data ptr is in global_data, jump table ptr is in jt.
246 * Windowed ABI: Jump just past 'entry' in target and adjust stack frame
247 * (extract stack frame size from target 'entry' instruction).
248 */
249
250static void **jt;
251
252#if defined(__XTENSA_CALL0_ABI__)
253#define EXPORT_FUNC(f, a, x, ...) \
254 asm volatile ( \
255" .extern jt\n" \
256" .globl " #x "\n" \
257" .align 4\n" \
258#x ":\n" \
259" l32i a8, %0, 0\n" \
260" l32i a8, a8, %1\n" \
261" jx a8\n" \
262 : : "r"(jt), "i" (FO(x)) : "a8");
263#elif defined(__XTENSA_WINDOWED_ABI__)
264#if XCHAL_HAVE_BE
265# define SFT "8"
266#else
267# define SFT "12"
268#endif
269#define EXPORT_FUNC(f, a, x, ...) \
270 asm volatile ( \
271" .extern jt\n" \
272" .globl " #x "\n" \
273" .align 4\n" \
274#x ":\n" \
275" entry sp, 16\n" \
276" l32i a8, %0, 0\n" \
277" l32i a8, a8, %1\n" \
278" l32i a9, a8, 0\n" \
279" extui a9, a9, " SFT ", 12\n" \
280" subx8 a9, a9, sp\n" \
281" movi a10, 16\n" \
282" sub a9, a10, a9\n" \
283" movsp sp, a9\n" \
284" addi a8, a8, 3\n" \
285" jx a8\n" \
286 : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10");
287#else
288#error Unsupported Xtensa ABI
289#endif
27b207fd 290#else
72c73dde
ML
291/*" addi $sp, $sp, -24\n" \
292" br $r16\n" \*/
293
27b207fd
WD
294#error stubs definition missing for this architecture
295#endif
296
297/* This function is necessary to prevent the compiler from
298 * generating prologue/epilogue, preparing stack frame etc.
299 * The stub functions are special, they do not use the stack
300 * frame passed to them, but pass it intact to the actual
301 * implementation. On the other hand, asm() statements with
302 * arguments can be used only inside the functions (gcc limitation)
303 */
2d5db193 304#if GCC_VERSION < 30400
93f6a677
WD
305static
306#endif /* GCC_VERSION */
307void __attribute__((unused)) dummy(void)
27b207fd
WD
308{
309#include <_exports.h>
310}
311
716cc8cc 312#include <asm/sections.h>
d716b126 313
54841ab5 314void app_startup(char * const *argv)
27b207fd 315{
716cc8cc 316 char *cp = __bss_start;
d716b126
WD
317
318 /* Zero out BSS */
716cc8cc 319 while (cp < _end)
d716b126 320 *cp++ = 0;
d716b126 321
fea25720 322#if defined(CONFIG_X86)
27b207fd 323 /* x86 does not have a dedicated register for passing global_data */
77846748
WD
324 global_data = (gd_t *)argv[-1];
325 jt = global_data->jt;
27b207fd
WD
326#endif
327}
328
329#undef EXPORT_FUNC