blob: 65115570e8eb537892a6e4dfe375b03325f42ad1 [file] [log] [blame]
Mike Partington46f387d2010-10-27 10:31:09 +00001#include <common.h>
wdenk874ac262003-07-24 23:38:38 +00002#include <exports.h>
Masahiro Yamada84002752014-09-04 02:40:59 +09003#include <linux/compiler.h>
wdenk3337af42004-07-01 20:28:03 +00004
Simon Glassed38aef2020-05-10 11:40:03 -06005struct cmd_tbl;
6
Martin Dorwigcb2c2862015-01-26 15:22:54 -07007#define FO(x) offsetof(struct jt_funcs, x)
8
Graeme Russcbfce1d2011-04-13 19:43:28 +10009#if defined(CONFIG_X86)
wdenk874ac262003-07-24 23:38:38 +000010/*
11 * x86 does not have a dedicated register to store the pointer to
12 * the global_data. Thus the jump table address is stored in a
13 * global variable, but such approach does not allow for execution
14 * from flash memory. The global_data address is passed as argv[-1]
15 * to the application program.
16 */
Alistair Delva02a695c2022-09-26 20:47:10 +000017struct jt_funcs *jt;
wdenkb8463562003-07-26 08:08:08 +000018gd_t *global_data;
wdenk874ac262003-07-24 23:38:38 +000019
Martin Dorwigcb2c2862015-01-26 15:22:54 -070020#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000021 asm volatile ( \
22" .globl " #x "\n" \
23#x ":\n" \
24" movl %0, %%eax\n" \
25" movl jt, %%ecx\n" \
26" jmp *(%%ecx, %%eax)\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070027 : : "i"(FO(x)) : "eax", "ecx");
wdenk874ac262003-07-24 23:38:38 +000028#elif defined(CONFIG_PPC)
29/*
Wolfgang Denk69c09642008-02-14 22:43:22 +010030 * r2 holds the pointer to the global_data, r11 is a call-clobbered
wdenk874ac262003-07-24 23:38:38 +000031 * register
32 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070033#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000034 asm volatile ( \
35" .globl " #x "\n" \
36#x ":\n" \
Wolfgang Denk69c09642008-02-14 22:43:22 +010037" lwz %%r11, %0(%%r2)\n" \
wdenk874ac262003-07-24 23:38:38 +000038" lwz %%r11, %1(%%r11)\n" \
39" mtctr %%r11\n" \
40" bctr\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070041 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11");
wdenk874ac262003-07-24 23:38:38 +000042#elif defined(CONFIG_ARM)
David Feng85fd5f12013-12-14 11:47:35 +080043#ifdef CONFIG_ARM64
44/*
45 * x18 holds the pointer to the global_data, x9 is a call-clobbered
46 * register
47 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070048#define EXPORT_FUNC(f, a, x, ...) \
David Feng85fd5f12013-12-14 11:47:35 +080049 asm volatile ( \
50" .globl " #x "\n" \
51#x ":\n" \
52" ldr x9, [x18, %0]\n" \
53" ldr x9, [x9, %1]\n" \
54" br x9\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070055 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9");
David Feng85fd5f12013-12-14 11:47:35 +080056#else
wdenk874ac262003-07-24 23:38:38 +000057/*
Jeroen Hofsteeb00867b2013-11-21 22:32:51 +010058 * r9 holds the pointer to the global_data, ip is a call-clobbered
wdenk874ac262003-07-24 23:38:38 +000059 * register
60 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070061#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000062 asm volatile ( \
63" .globl " #x "\n" \
64#x ":\n" \
Jeroen Hofsteeb00867b2013-11-21 22:32:51 +010065" ldr ip, [r9, %0]\n" \
wdenk874ac262003-07-24 23:38:38 +000066" ldr pc, [ip, %1]\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -070067 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip");
David Feng85fd5f12013-12-14 11:47:35 +080068#endif
wdenk874ac262003-07-24 23:38:38 +000069#elif defined(CONFIG_MIPS)
Stanislav Galabov26f182d2016-02-17 15:23:33 +020070#ifdef CONFIG_CPU_MIPS64
wdenk874ac262003-07-24 23:38:38 +000071/*
72 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
73 * clobbered register that is also used to set gp ($26). Note that the
74 * jr instruction also executes the instruction immediately following
75 * it; however, GCC/mips generates an additional `nop' after each asm
76 * statement
77 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -070078#define EXPORT_FUNC(f, a, x, ...) \
wdenk874ac262003-07-24 23:38:38 +000079 asm volatile ( \
80" .globl " #x "\n" \
81#x ":\n" \
Stanislav Galabov26f182d2016-02-17 15:23:33 +020082" ld $25, %0($26)\n" \
83" ld $25, %1($25)\n" \
84" jr $25\n" \
85 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
86#else
87/*
88 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
89 * clobbered register that is also used to set gp ($26). Note that the
90 * jr instruction also executes the instruction immediately following
91 * it; however, GCC/mips generates an additional `nop' after each asm
92 * statement
93 */
94#define EXPORT_FUNC(f, a, x, ...) \
95 asm volatile ( \
96" .globl " #x "\n" \
97#x ":\n" \
wdenk874ac262003-07-24 23:38:38 +000098" lw $25, %0($26)\n" \
99" lw $25, %1($25)\n" \
100" jr $25\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700101 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
Stanislav Galabov26f182d2016-02-17 15:23:33 +0200102#endif
wdenkef3386f2004-10-10 21:27:30 +0000103#elif defined(CONFIG_NIOS2)
104/*
Thomas Chou8fa38582010-05-21 11:08:03 +0800105 * gp holds the pointer to the global_data, r8 is call-clobbered
wdenkef3386f2004-10-10 21:27:30 +0000106 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700107#define EXPORT_FUNC(f, a, x, ...) \
wdenkef3386f2004-10-10 21:27:30 +0000108 asm volatile ( \
109" .globl " #x "\n" \
110#x ":\n" \
111" movhi r8, %%hi(%0)\n" \
112" ori r8, r0, %%lo(%0)\n" \
Thomas Chou8fa38582010-05-21 11:08:03 +0800113" add r8, r8, gp\n" \
wdenkef3386f2004-10-10 21:27:30 +0000114" ldw r8, 0(r8)\n" \
115" ldw r8, %1(r8)\n" \
116" jmp r8\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700117 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp");
wdenke65527f2004-02-12 00:47:09 +0000118#elif defined(CONFIG_M68K)
119/*
120 * d7 holds the pointer to the global_data, a0 is a call-clobbered
121 * register
122 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700123#define EXPORT_FUNC(f, a, x, ...) \
wdenke65527f2004-02-12 00:47:09 +0000124 asm volatile ( \
125" .globl " #x "\n" \
126#x ":\n" \
127" move.l %%d7, %%a0\n" \
128" adda.l %0, %%a0\n" \
129" move.l (%%a0), %%a0\n" \
130" adda.l %1, %%a0\n" \
131" move.l (%%a0), %%a0\n" \
132" jmp (%%a0)\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700133 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0");
wdenk20a61222004-07-10 23:48:41 +0000134#elif defined(CONFIG_MICROBLAZE)
wdenk12490652004-04-18 21:13:41 +0000135/*
136 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
137 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700138#define EXPORT_FUNC(f, a, x, ...) \
wdenk12490652004-04-18 21:13:41 +0000139 asm volatile ( \
140" .globl " #x "\n" \
141#x ":\n" \
142" lwi r5, r31, %0\n" \
143" lwi r5, r5, %1\n" \
144" bra r5\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700145 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5");
Nobuhiro Iwamatsu970dc332007-05-13 20:58:00 +0900146#elif defined(CONFIG_SH)
147/*
148 * r13 holds the pointer to the global_data. r1 is a call clobbered.
149 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700150#define EXPORT_FUNC(f, a, x, ...) \
Wolfgang Denk0a5c2142007-12-27 01:52:50 +0100151 asm volatile ( \
152 " .align 2\n" \
153 " .globl " #x "\n" \
154 #x ":\n" \
155 " mov r13, r1\n" \
156 " add %0, r1\n" \
Nobuhiro Iwamatsud1d18502008-10-09 13:54:33 +0900157 " mov.l @r1, r2\n" \
158 " add %1, r2\n" \
159 " mov.l @r2, r1\n" \
Wolfgang Denk0a5c2142007-12-27 01:52:50 +0100160 " jmp @r1\n" \
161 " nop\n" \
162 " nop\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700163 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2");
Rick Chenba06a9a2017-12-26 13:55:57 +0800164#elif defined(CONFIG_RISCV)
165/*
Lukas Aueraf68f822019-01-04 01:37:32 +0100166 * gp holds the pointer to the global_data. t0 is call clobbered.
Rick Chenba06a9a2017-12-26 13:55:57 +0800167 */
Lukas Auerdb2fea22019-01-04 01:37:33 +0100168#ifdef CONFIG_ARCH_RV64I
Rick Chenba06a9a2017-12-26 13:55:57 +0800169#define EXPORT_FUNC(f, a, x, ...) \
170 asm volatile ( \
171" .globl " #x "\n" \
172#x ":\n" \
Lukas Auerdb2fea22019-01-04 01:37:33 +0100173" ld t0, %0(gp)\n" \
174" ld t0, %1(t0)\n" \
175" jr t0\n" \
176 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
177#else
178#define EXPORT_FUNC(f, a, x, ...) \
179 asm volatile ( \
180" .globl " #x "\n" \
181#x ":\n" \
Lukas Aueraf68f822019-01-04 01:37:32 +0100182" lw t0, %0(gp)\n" \
183" lw t0, %1(t0)\n" \
184" jr t0\n" \
185 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
Lukas Auerdb2fea22019-01-04 01:37:33 +0100186#endif
Alexey Brodkincb25a732014-02-04 12:56:17 +0400187#elif defined(CONFIG_ARC)
188/*
189 * r25 holds the pointer to the global_data. r10 is call clobbered.
190 */
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700191#define EXPORT_FUNC(f, a, x, ...) \
Alexey Brodkincb25a732014-02-04 12:56:17 +0400192 asm volatile( \
193" .align 4\n" \
194" .globl " #x "\n" \
195#x ":\n" \
196" ld r10, [r25, %0]\n" \
197" ld r10, [r10, %1]\n" \
198" j [r10]\n" \
Martin Dorwigcb2c2862015-01-26 15:22:54 -0700199 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10");
Chris Zankel41e37372016-08-10 18:36:43 +0300200#elif defined(CONFIG_XTENSA)
201/*
202 * Global data ptr is in global_data, jump table ptr is in jt.
203 * Windowed ABI: Jump just past 'entry' in target and adjust stack frame
204 * (extract stack frame size from target 'entry' instruction).
205 */
206
207static void **jt;
208
209#if defined(__XTENSA_CALL0_ABI__)
210#define EXPORT_FUNC(f, a, x, ...) \
211 asm volatile ( \
212" .extern jt\n" \
213" .globl " #x "\n" \
214" .align 4\n" \
215#x ":\n" \
216" l32i a8, %0, 0\n" \
217" l32i a8, a8, %1\n" \
218" jx a8\n" \
219 : : "r"(jt), "i" (FO(x)) : "a8");
220#elif defined(__XTENSA_WINDOWED_ABI__)
221#if XCHAL_HAVE_BE
222# define SFT "8"
223#else
224# define SFT "12"
225#endif
226#define EXPORT_FUNC(f, a, x, ...) \
227 asm volatile ( \
228" .extern jt\n" \
229" .globl " #x "\n" \
230" .align 4\n" \
231#x ":\n" \
232" entry sp, 16\n" \
233" l32i a8, %0, 0\n" \
234" l32i a8, a8, %1\n" \
235" l32i a9, a8, 0\n" \
236" extui a9, a9, " SFT ", 12\n" \
237" subx8 a9, a9, sp\n" \
238" movi a10, 16\n" \
239" sub a9, a10, a9\n" \
240" movsp sp, a9\n" \
241" addi a8, a8, 3\n" \
242" jx a8\n" \
243 : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10");
244#else
245#error Unsupported Xtensa ABI
246#endif
wdenk874ac262003-07-24 23:38:38 +0000247#else
Macpaul Lin394c76a2011-10-11 22:33:20 +0000248/*" addi $sp, $sp, -24\n" \
249" br $r16\n" \*/
250
wdenk874ac262003-07-24 23:38:38 +0000251#error stubs definition missing for this architecture
252#endif
253
254/* This function is necessary to prevent the compiler from
255 * generating prologue/epilogue, preparing stack frame etc.
256 * The stub functions are special, they do not use the stack
257 * frame passed to them, but pass it intact to the actual
258 * implementation. On the other hand, asm() statements with
259 * arguments can be used only inside the functions (gcc limitation)
260 */
Masahiro Yamada84002752014-09-04 02:40:59 +0900261#if GCC_VERSION < 30400
wdenk3337af42004-07-01 20:28:03 +0000262static
263#endif /* GCC_VERSION */
264void __attribute__((unused)) dummy(void)
wdenk874ac262003-07-24 23:38:38 +0000265{
266#include <_exports.h>
267}
268
Simon Glass5b928202013-03-05 14:39:39 +0000269#include <asm/sections.h>
wdenk2fb73902004-04-12 16:12:49 +0000270
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200271void app_startup(char * const *argv)
wdenk874ac262003-07-24 23:38:38 +0000272{
Simon Glass5b928202013-03-05 14:39:39 +0000273 char *cp = __bss_start;
wdenk2fb73902004-04-12 16:12:49 +0000274
275 /* Zero out BSS */
Simon Glass5b928202013-03-05 14:39:39 +0000276 while (cp < _end)
wdenk2fb73902004-04-12 16:12:49 +0000277 *cp++ = 0;
wdenk2fb73902004-04-12 16:12:49 +0000278
Graeme Russcbfce1d2011-04-13 19:43:28 +1000279#if defined(CONFIG_X86)
wdenk874ac262003-07-24 23:38:38 +0000280 /* x86 does not have a dedicated register for passing global_data */
wdenkb8463562003-07-26 08:08:08 +0000281 global_data = (gd_t *)argv[-1];
282 jt = global_data->jt;
wdenk874ac262003-07-24 23:38:38 +0000283#endif
284}
285
286#undef EXPORT_FUNC