blob: 04e8acb8abe9e8554f4bac5b0b4a0538f0751845 [file] [log] [blame]
wdenk874ac262003-07-24 23:38:38 +00001#include <exports.h>
Masahiro Yamada84002752014-09-04 02:40:59 +09002#include <linux/compiler.h>
wdenk3337af42004-07-01 20:28:03 +00003
Simon Glassed38aef2020-05-10 11:40:03 -06004struct cmd_tbl;
5
Martin Dorwigcb2c2862015-01-26 15:22:54 -07006#define FO(x) offsetof(struct jt_funcs, x)
7
Graeme Russcbfce1d2011-04-13 19:43:28 +10008#if defined(CONFIG_X86)
wdenk874ac262003-07-24 23:38:38 +00009/*
10 * x86 does not have a dedicated register to store the pointer to
11 * the global_data. Thus the jump table address is stored in a
12 * global variable, but such approach does not allow for execution
13 * from flash memory. The global_data address is passed as argv[-1]
14 * to the application program.
15 */
Alistair Delva02a695c2022-09-26 20:47:10 +000016struct jt_funcs *jt;
wdenkb8463562003-07-26 08:08:08 +000017gd_t *global_data;
wdenk874ac262003-07-24 23:38:38 +000018
Martin Dorwigcb2c2862015-01-26 15:22:54 -070019#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000020 asm volatile ( \
21" .globl " #x "\n" \
22#x ":\n" \
23" movl %0, %%eax\n" \
24" movl jt, %%ecx\n" \
25" jmp *(%%ecx, %%eax)\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070026 : : "i"(FO(x)) : "eax", "ecx");
wdenk874ac262003-07-24 23:38:38 +000027#elif defined(CONFIG_PPC)
28/*
Wolfgang Denk69c09642008-02-14 22:43:22 +010029 * r2 holds the pointer to the global_data, r11 is a call-clobbered
wdenk874ac262003-07-24 23:38:38 +000030 * register
31 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070032#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000033 asm volatile ( \
34" .globl " #x "\n" \
35#x ":\n" \
Wolfgang Denk69c09642008-02-14 22:43:22 +010036" lwz %%r11, %0(%%r2)\n" \
wdenk874ac262003-07-24 23:38:38 +000037" lwz %%r11, %1(%%r11)\n" \
38" mtctr %%r11\n" \
39" bctr\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070040 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11");
wdenk874ac262003-07-24 23:38:38 +000041#elif defined(CONFIG_ARM)
David Feng85fd5f12013-12-14 11:47:35 +080042#ifdef CONFIG_ARM64
43/*
44 * x18 holds the pointer to the global_data, x9 is a call-clobbered
45 * register
46 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070047#define EXPORT_FUNC(f, a, x, ...) \
David Feng85fd5f12013-12-14 11:47:35 +080048 asm volatile ( \
49" .globl " #x "\n" \
50#x ":\n" \
51" ldr x9, [x18, %0]\n" \
52" ldr x9, [x9, %1]\n" \
53" br x9\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070054 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9");
David Feng85fd5f12013-12-14 11:47:35 +080055#else
wdenk874ac262003-07-24 23:38:38 +000056/*
Jeroen Hofsteeb00867b2013-11-21 22:32:51 +010057 * r9 holds the pointer to the global_data, ip is a call-clobbered
wdenk874ac262003-07-24 23:38:38 +000058 * register
59 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070060#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000061 asm volatile ( \
62" .globl " #x "\n" \
63#x ":\n" \
Jeroen Hofsteeb00867b2013-11-21 22:32:51 +010064" ldr ip, [r9, %0]\n" \
wdenk874ac262003-07-24 23:38:38 +000065" ldr pc, [ip, %1]\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070066 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip");
David Feng85fd5f12013-12-14 11:47:35 +080067#endif
wdenk874ac262003-07-24 23:38:38 +000068#elif defined(CONFIG_MIPS)
Stanislav Galabov26f182d2016-02-17 15:23:33 +020069#ifdef CONFIG_CPU_MIPS64
wdenk874ac262003-07-24 23:38:38 +000070/*
71 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
72 * clobbered register that is also used to set gp ($26). Note that the
73 * jr instruction also executes the instruction immediately following
74 * it; however, GCC/mips generates an additional `nop' after each asm
75 * statement
76 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070077#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000078 asm volatile ( \
79" .globl " #x "\n" \
80#x ":\n" \
Stanislav Galabov26f182d2016-02-17 15:23:33 +020081" ld $25, %0($26)\n" \
82" ld $25, %1($25)\n" \
83" jr $25\n" \
84 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
85#else
86/*
87 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
88 * clobbered register that is also used to set gp ($26). Note that the
89 * jr instruction also executes the instruction immediately following
90 * it; however, GCC/mips generates an additional `nop' after each asm
91 * statement
92 */
93#define EXPORT_FUNC(f, a, x, ...) \
94 asm volatile ( \
95" .globl " #x "\n" \
96#x ":\n" \
wdenk874ac262003-07-24 23:38:38 +000097" lw $25, %0($26)\n" \
98" lw $25, %1($25)\n" \
99" jr $25\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700100 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
Stanislav Galabov26f182d2016-02-17 15:23:33 +0200101#endif
wdenkef3386f2004-10-10 21:27:30 +0000102#elif defined(CONFIG_NIOS2)
103/*
Thomas Chou8fa38582010-05-21 11:08:03 +0800104 * gp holds the pointer to the global_data, r8 is call-clobbered
wdenkef3386f2004-10-10 21:27:30 +0000105 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700106#define EXPORT_FUNC(f, a, x, ...) \
wdenkef3386f2004-10-10 21:27:30 +0000107 asm volatile ( \
108" .globl " #x "\n" \
109#x ":\n" \
110" movhi r8, %%hi(%0)\n" \
111" ori r8, r0, %%lo(%0)\n" \
Thomas Chou8fa38582010-05-21 11:08:03 +0800112" add r8, r8, gp\n" \
wdenkef3386f2004-10-10 21:27:30 +0000113" ldw r8, 0(r8)\n" \
114" ldw r8, %1(r8)\n" \
115" jmp r8\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700116 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp");
wdenke65527f2004-02-12 00:47:09 +0000117#elif defined(CONFIG_M68K)
118/*
119 * d7 holds the pointer to the global_data, a0 is a call-clobbered
120 * register
121 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700122#define EXPORT_FUNC(f, a, x, ...) \
wdenke65527f2004-02-12 00:47:09 +0000123 asm volatile ( \
124" .globl " #x "\n" \
125#x ":\n" \
126" move.l %%d7, %%a0\n" \
127" adda.l %0, %%a0\n" \
128" move.l (%%a0), %%a0\n" \
129" adda.l %1, %%a0\n" \
130" move.l (%%a0), %%a0\n" \
131" jmp (%%a0)\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700132 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0");
wdenk20a61222004-07-10 23:48:41 +0000133#elif defined(CONFIG_MICROBLAZE)
wdenk12490652004-04-18 21:13:41 +0000134/*
135 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
136 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700137#define EXPORT_FUNC(f, a, x, ...) \
wdenk12490652004-04-18 21:13:41 +0000138 asm volatile ( \
139" .globl " #x "\n" \
140#x ":\n" \
141" lwi r5, r31, %0\n" \
142" lwi r5, r5, %1\n" \
143" bra r5\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700144 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5");
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900145#elif defined(CONFIG_SH)
146/*
147 * r13 holds the pointer to the global_data. r1 is a call clobbered.
148 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700149#define EXPORT_FUNC(f, a, x, ...) \
Wolfgang Denk0a5c2142007-12-27 01:52:50 +0100150 asm volatile ( \
151 " .align 2\n" \
152 " .globl " #x "\n" \
153 #x ":\n" \
154 " mov r13, r1\n" \
155 " add %0, r1\n" \
Nobuhiro Iwamatsud1d18502008-10-09 13:54:33 +0900156 " mov.l @r1, r2\n" \
157 " add %1, r2\n" \
158 " mov.l @r2, r1\n" \
Wolfgang Denk0a5c2142007-12-27 01:52:50 +0100159 " jmp @r1\n" \
160 " nop\n" \
161 " nop\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700162 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2");
Rick Chenba06a9a2017-12-26 13:55:57 +0800163#elif defined(CONFIG_RISCV)
164/*
Lukas Aueraf68f822019-01-04 01:37:32 +0100165 * gp holds the pointer to the global_data. t0 is call clobbered.
Rick Chenba06a9a2017-12-26 13:55:57 +0800166 */
Lukas Auerdb2fea22019-01-04 01:37:33 +0100167#ifdef CONFIG_ARCH_RV64I
Rick Chenba06a9a2017-12-26 13:55:57 +0800168#define EXPORT_FUNC(f, a, x, ...) \
169 asm volatile ( \
170" .globl " #x "\n" \
171#x ":\n" \
Lukas Auerdb2fea22019-01-04 01:37:33 +0100172" ld t0, %0(gp)\n" \
173" ld t0, %1(t0)\n" \
174" jr t0\n" \
175 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
176#else
177#define EXPORT_FUNC(f, a, x, ...) \
178 asm volatile ( \
179" .globl " #x "\n" \
180#x ":\n" \
Lukas Aueraf68f822019-01-04 01:37:32 +0100181" lw t0, %0(gp)\n" \
182" lw t0, %1(t0)\n" \
183" jr t0\n" \
184 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
Lukas Auerdb2fea22019-01-04 01:37:33 +0100185#endif
Alexey Brodkincb25a732014-02-04 12:56:17 +0400186#elif defined(CONFIG_ARC)
187/*
188 * r25 holds the pointer to the global_data. r10 is call clobbered.
189 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700190#define EXPORT_FUNC(f, a, x, ...) \
Alexey Brodkincb25a732014-02-04 12:56:17 +0400191 asm volatile( \
192" .align 4\n" \
193" .globl " #x "\n" \
194#x ":\n" \
195" ld r10, [r25, %0]\n" \
196" ld r10, [r10, %1]\n" \
197" j [r10]\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700198 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10");
Chris Zankel41e37372016-08-10 18:36:43 +0300199#elif defined(CONFIG_XTENSA)
200/*
201 * Global data ptr is in global_data, jump table ptr is in jt.
202 * Windowed ABI: Jump just past 'entry' in target and adjust stack frame
203 * (extract stack frame size from target 'entry' instruction).
204 */
205
206static void **jt;
207
208#if defined(__XTENSA_CALL0_ABI__)
209#define EXPORT_FUNC(f, a, x, ...) \
210 asm volatile ( \
211" .extern jt\n" \
212" .globl " #x "\n" \
213" .align 4\n" \
214#x ":\n" \
215" l32i a8, %0, 0\n" \
216" l32i a8, a8, %1\n" \
217" jx a8\n" \
218 : : "r"(jt), "i" (FO(x)) : "a8");
219#elif defined(__XTENSA_WINDOWED_ABI__)
220#if XCHAL_HAVE_BE
221# define SFT "8"
222#else
223# define SFT "12"
224#endif
225#define EXPORT_FUNC(f, a, x, ...) \
226 asm volatile ( \
227" .extern jt\n" \
228" .globl " #x "\n" \
229" .align 4\n" \
230#x ":\n" \
231" entry sp, 16\n" \
232" l32i a8, %0, 0\n" \
233" l32i a8, a8, %1\n" \
234" l32i a9, a8, 0\n" \
235" extui a9, a9, " SFT ", 12\n" \
236" subx8 a9, a9, sp\n" \
237" movi a10, 16\n" \
238" sub a9, a10, a9\n" \
239" movsp sp, a9\n" \
240" addi a8, a8, 3\n" \
241" jx a8\n" \
242 : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10");
243#else
244#error Unsupported Xtensa ABI
245#endif
wdenk874ac262003-07-24 23:38:38 +0000246#else
Macpaul Lin394c76a2011-10-11 22:33:20 +0000247/*" addi $sp, $sp, -24\n" \
248" br $r16\n" \*/
249
wdenk874ac262003-07-24 23:38:38 +0000250#error stubs definition missing for this architecture
251#endif
252
253/* This function is necessary to prevent the compiler from
254 * generating prologue/epilogue, preparing stack frame etc.
255 * The stub functions are special, they do not use the stack
256 * frame passed to them, but pass it intact to the actual
257 * implementation. On the other hand, asm() statements with
258 * arguments can be used only inside the functions (gcc limitation)
259 */
Masahiro Yamada84002752014-09-04 02:40:59 +0900260#if GCC_VERSION < 30400
wdenk3337af42004-07-01 20:28:03 +0000261static
262#endif /* GCC_VERSION */
263void __attribute__((unused)) dummy(void)
wdenk874ac262003-07-24 23:38:38 +0000264{
265#include <_exports.h>
266}
267
Simon Glass5b928202013-03-05 14:39:39 +0000268#include <asm/sections.h>
wdenk2fb73902004-04-12 16:12:49 +0000269
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200270void app_startup(char * const *argv)
wdenk874ac262003-07-24 23:38:38 +0000271{
Simon Glass5b928202013-03-05 14:39:39 +0000272 char *cp = __bss_start;
wdenk2fb73902004-04-12 16:12:49 +0000273
274 /* Zero out BSS */
Simon Glass5b928202013-03-05 14:39:39 +0000275 while (cp < _end)
wdenk2fb73902004-04-12 16:12:49 +0000276 *cp++ = 0;
wdenk2fb73902004-04-12 16:12:49 +0000277
Graeme Russcbfce1d2011-04-13 19:43:28 +1000278#if defined(CONFIG_X86)
wdenk874ac262003-07-24 23:38:38 +0000279 /* x86 does not have a dedicated register for passing global_data */
wdenkb8463562003-07-26 08:08:08 +0000280 global_data = (gd_t *)argv[-1];
281 jt = global_data->jt;
wdenk874ac262003-07-24 23:38:38 +0000282#endif
283}
284
285#undef EXPORT_FUNC