blob: a6a9fcf189a4dbf1ad5e0c3044a5a3f97cc9ef0c [file] [log] [blame]
Mike Partington0910d0b2010-10-27 10:31:09 +00001#include <common.h>
wdenk27b207f2003-07-24 23:38:38 +00002#include <exports.h>
Masahiro Yamada2d5db192014-09-04 02:40:59 +09003#include <linux/compiler.h>
wdenk93f6a672004-07-01 20:28:03 +00004
Martin Dorwig49cad542015-01-26 15:22:54 -07005#define FO(x) offsetof(struct jt_funcs, x)
6
Graeme Russfea25722011-04-13 19:43:28 +10007#if defined(CONFIG_X86)
wdenk27b207f2003-07-24 23:38:38 +00008/*
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 */
Martin Dorwig49cad542015-01-26 15:22:54 -070015static struct jt_funcs *jt;
wdenk77846742003-07-26 08:08:08 +000016gd_t *global_data;
wdenk27b207f2003-07-24 23:38:38 +000017
Martin Dorwig49cad542015-01-26 15:22:54 -070018#define EXPORT_FUNC(f, a, x, ...) \
wdenk27b207f2003-07-24 23:38:38 +000019 asm volatile ( \
20" .globl " #x "\n" \
21#x ":\n" \
22" movl %0, %%eax\n" \
23" movl jt, %%ecx\n" \
24" jmp *(%%ecx, %%eax)\n" \
Martin Dorwig49cad542015-01-26 15:22:54 -070025 : : "i"(FO(x)) : "eax", "ecx");
wdenk27b207f2003-07-24 23:38:38 +000026#elif defined(CONFIG_PPC)
27/*
Wolfgang Denke7670f62008-02-14 22:43:22 +010028 * r2 holds the pointer to the global_data, r11 is a call-clobbered
wdenk27b207f2003-07-24 23:38:38 +000029 * register
30 */
Martin Dorwig49cad542015-01-26 15:22:54 -070031#define EXPORT_FUNC(f, a, x, ...) \
wdenk27b207f2003-07-24 23:38:38 +000032 asm volatile ( \
33" .globl " #x "\n" \
34#x ":\n" \
Wolfgang Denke7670f62008-02-14 22:43:22 +010035" lwz %%r11, %0(%%r2)\n" \
wdenk27b207f2003-07-24 23:38:38 +000036" lwz %%r11, %1(%%r11)\n" \
37" mtctr %%r11\n" \
38" bctr\n" \
Martin Dorwig49cad542015-01-26 15:22:54 -070039 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11");
wdenk27b207f2003-07-24 23:38:38 +000040#elif defined(CONFIG_ARM)
David Feng0ae76532013-12-14 11:47:35 +080041#ifdef CONFIG_ARM64
42/*
43 * x18 holds the pointer to the global_data, x9 is a call-clobbered
44 * register
45 */
Martin Dorwig49cad542015-01-26 15:22:54 -070046#define EXPORT_FUNC(f, a, x, ...) \
David Feng0ae76532013-12-14 11:47:35 +080047 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" \
Martin Dorwig49cad542015-01-26 15:22:54 -070053 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9");
David Feng0ae76532013-12-14 11:47:35 +080054#else
wdenk27b207f2003-07-24 23:38:38 +000055/*
Jeroen Hofsteea5a42ee2013-11-21 22:32:51 +010056 * r9 holds the pointer to the global_data, ip is a call-clobbered
wdenk27b207f2003-07-24 23:38:38 +000057 * register
58 */
Martin Dorwig49cad542015-01-26 15:22:54 -070059#define EXPORT_FUNC(f, a, x, ...) \
wdenk27b207f2003-07-24 23:38:38 +000060 asm volatile ( \
61" .globl " #x "\n" \
62#x ":\n" \
Jeroen Hofsteea5a42ee2013-11-21 22:32:51 +010063" ldr ip, [r9, %0]\n" \
wdenk27b207f2003-07-24 23:38:38 +000064" ldr pc, [ip, %1]\n" \
Martin Dorwig49cad542015-01-26 15:22:54 -070065 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip");
David Feng0ae76532013-12-14 11:47:35 +080066#endif
wdenk27b207f2003-07-24 23:38:38 +000067#elif defined(CONFIG_MIPS)
Stanislav Galabov4a48cfc2016-02-17 15:23:33 +020068#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
wdenk27b207f2003-07-24 23:38:38 +000085/*
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 */
Martin Dorwig49cad542015-01-26 15:22:54 -070092#define EXPORT_FUNC(f, a, x, ...) \
wdenk27b207f2003-07-24 23:38:38 +000093 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" \
Martin Dorwig49cad542015-01-26 15:22:54 -070099 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
Stanislav Galabov4a48cfc2016-02-17 15:23:33 +0200100#endif
wdenk5c952cf2004-10-10 21:27:30 +0000101#elif defined(CONFIG_NIOS2)
102/*
Thomas Chou0df01fd2010-05-21 11:08:03 +0800103 * gp holds the pointer to the global_data, r8 is call-clobbered
wdenk5c952cf2004-10-10 21:27:30 +0000104 */
Martin Dorwig49cad542015-01-26 15:22:54 -0700105#define EXPORT_FUNC(f, a, x, ...) \
wdenk5c952cf2004-10-10 21:27:30 +0000106 asm volatile ( \
107" .globl " #x "\n" \
108#x ":\n" \
109" movhi r8, %%hi(%0)\n" \
110" ori r8, r0, %%lo(%0)\n" \
Thomas Chou0df01fd2010-05-21 11:08:03 +0800111" add r8, r8, gp\n" \
wdenk5c952cf2004-10-10 21:27:30 +0000112" ldw r8, 0(r8)\n" \
113" ldw r8, %1(r8)\n" \
114" jmp r8\n" \
Martin Dorwig49cad542015-01-26 15:22:54 -0700115 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp");
wdenkbf9e3b32004-02-12 00:47:09 +0000116#elif defined(CONFIG_M68K)
117/*
118 * d7 holds the pointer to the global_data, a0 is a call-clobbered
119 * register
120 */
Martin Dorwig49cad542015-01-26 15:22:54 -0700121#define EXPORT_FUNC(f, a, x, ...) \
wdenkbf9e3b32004-02-12 00:47:09 +0000122 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" \
Martin Dorwig49cad542015-01-26 15:22:54 -0700131 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0");
wdenk857cad32004-07-10 23:48:41 +0000132#elif defined(CONFIG_MICROBLAZE)
wdenk507bbe32004-04-18 21:13:41 +0000133/*
134 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
135 */
Martin Dorwig49cad542015-01-26 15:22:54 -0700136#define EXPORT_FUNC(f, a, x, ...) \
wdenk507bbe32004-04-18 21:13:41 +0000137 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" \
Martin Dorwig49cad542015-01-26 15:22:54 -0700143 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5");
Wolfgang Denk7b64fef2006-10-24 14:21:16 +0200144#elif defined(CONFIG_AVR32)
145/*
146 * r6 holds the pointer to the global_data. r8 is call clobbered.
147 */
Martin Dorwig49cad542015-01-26 15:22:54 -0700148#define EXPORT_FUNC(f, a, x, ...) \
Wolfgang Denk7b64fef2006-10-24 14:21:16 +0200149 asm volatile( \
150 " .globl\t" #x "\n" \
151 #x ":\n" \
152 " ld.w r8, r6[%0]\n" \
153 " ld.w pc, r8[%1]\n" \
154 : \
Martin Dorwig49cad542015-01-26 15:22:54 -0700155 : "i"(offsetof(gd_t, jt)), "i"(FO(x)) \
Wolfgang Denk7b64fef2006-10-24 14:21:16 +0200156 : "r8");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900157#elif defined(CONFIG_SH)
158/*
159 * r13 holds the pointer to the global_data. r1 is a call clobbered.
160 */
Martin Dorwig49cad542015-01-26 15:22:54 -0700161#define EXPORT_FUNC(f, a, x, ...) \
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100162 asm volatile ( \
163 " .align 2\n" \
164 " .globl " #x "\n" \
165 #x ":\n" \
166 " mov r13, r1\n" \
167 " add %0, r1\n" \
Nobuhiro Iwamatsucae6f902008-10-09 13:54:33 +0900168 " mov.l @r1, r2\n" \
169 " add %1, r2\n" \
170 " mov.l @r2, r1\n" \
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100171 " jmp @r1\n" \
172 " nop\n" \
173 " nop\n" \
Martin Dorwig49cad542015-01-26 15:22:54 -0700174 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2");
Macpaul Lin72c73dd2011-10-11 22:33:20 +0000175#elif defined(CONFIG_NDS32)
176/*
177 * r16 holds the pointer to the global_data. gp is call clobbered.
178 * not support reduced register (16 GPR).
179 */
Martin Dorwig49cad542015-01-26 15:22:54 -0700180#define EXPORT_FUNC(f, a, x, ...) \
Macpaul Lin72c73dd2011-10-11 22:33:20 +0000181 asm volatile ( \
182" .globl " #x "\n" \
183#x ":\n" \
184" lwi $r16, [$gp + (%0)]\n" \
185" lwi $r16, [$r16 + (%1)]\n" \
186" jr $r16\n" \
Martin Dorwig49cad542015-01-26 15:22:54 -0700187 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "$r16");
Alexey Brodkin794ab572014-02-04 12:56:17 +0400188#elif defined(CONFIG_ARC)
189/*
190 * r25 holds the pointer to the global_data. r10 is call clobbered.
191 */
Martin Dorwig49cad542015-01-26 15:22:54 -0700192#define EXPORT_FUNC(f, a, x, ...) \
Alexey Brodkin794ab572014-02-04 12:56:17 +0400193 asm volatile( \
194" .align 4\n" \
195" .globl " #x "\n" \
196#x ":\n" \
197" ld r10, [r25, %0]\n" \
198" ld r10, [r10, %1]\n" \
199" j [r10]\n" \
Martin Dorwig49cad542015-01-26 15:22:54 -0700200 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10");
Chris Zankelde5e5ce2016-08-10 18:36:43 +0300201#elif defined(CONFIG_XTENSA)
202/*
203 * Global data ptr is in global_data, jump table ptr is in jt.
204 * Windowed ABI: Jump just past 'entry' in target and adjust stack frame
205 * (extract stack frame size from target 'entry' instruction).
206 */
207
208static void **jt;
209
210#if defined(__XTENSA_CALL0_ABI__)
211#define EXPORT_FUNC(f, a, x, ...) \
212 asm volatile ( \
213" .extern jt\n" \
214" .globl " #x "\n" \
215" .align 4\n" \
216#x ":\n" \
217" l32i a8, %0, 0\n" \
218" l32i a8, a8, %1\n" \
219" jx a8\n" \
220 : : "r"(jt), "i" (FO(x)) : "a8");
221#elif defined(__XTENSA_WINDOWED_ABI__)
222#if XCHAL_HAVE_BE
223# define SFT "8"
224#else
225# define SFT "12"
226#endif
227#define EXPORT_FUNC(f, a, x, ...) \
228 asm volatile ( \
229" .extern jt\n" \
230" .globl " #x "\n" \
231" .align 4\n" \
232#x ":\n" \
233" entry sp, 16\n" \
234" l32i a8, %0, 0\n" \
235" l32i a8, a8, %1\n" \
236" l32i a9, a8, 0\n" \
237" extui a9, a9, " SFT ", 12\n" \
238" subx8 a9, a9, sp\n" \
239" movi a10, 16\n" \
240" sub a9, a10, a9\n" \
241" movsp sp, a9\n" \
242" addi a8, a8, 3\n" \
243" jx a8\n" \
244 : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10");
245#else
246#error Unsupported Xtensa ABI
247#endif
wdenk27b207f2003-07-24 23:38:38 +0000248#else
Macpaul Lin72c73dd2011-10-11 22:33:20 +0000249/*" addi $sp, $sp, -24\n" \
250" br $r16\n" \*/
251
wdenk27b207f2003-07-24 23:38:38 +0000252#error stubs definition missing for this architecture
253#endif
254
255/* This function is necessary to prevent the compiler from
256 * generating prologue/epilogue, preparing stack frame etc.
257 * The stub functions are special, they do not use the stack
258 * frame passed to them, but pass it intact to the actual
259 * implementation. On the other hand, asm() statements with
260 * arguments can be used only inside the functions (gcc limitation)
261 */
Masahiro Yamada2d5db192014-09-04 02:40:59 +0900262#if GCC_VERSION < 30400
wdenk93f6a672004-07-01 20:28:03 +0000263static
264#endif /* GCC_VERSION */
265void __attribute__((unused)) dummy(void)
wdenk27b207f2003-07-24 23:38:38 +0000266{
267#include <_exports.h>
268}
269
Simon Glass716cc8c2013-03-05 14:39:39 +0000270#include <asm/sections.h>
wdenkd716b122004-04-12 16:12:49 +0000271
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200272void app_startup(char * const *argv)
wdenk27b207f2003-07-24 23:38:38 +0000273{
Simon Glass716cc8c2013-03-05 14:39:39 +0000274 char *cp = __bss_start;
wdenkd716b122004-04-12 16:12:49 +0000275
276 /* Zero out BSS */
Simon Glass716cc8c2013-03-05 14:39:39 +0000277 while (cp < _end)
wdenkd716b122004-04-12 16:12:49 +0000278 *cp++ = 0;
wdenkd716b122004-04-12 16:12:49 +0000279
Graeme Russfea25722011-04-13 19:43:28 +1000280#if defined(CONFIG_X86)
wdenk27b207f2003-07-24 23:38:38 +0000281 /* x86 does not have a dedicated register for passing global_data */
wdenk77846742003-07-26 08:08:08 +0000282 global_data = (gd_t *)argv[-1];
283 jt = global_data->jt;
wdenk27b207f2003-07-24 23:38:38 +0000284#endif
285}
286
287#undef EXPORT_FUNC