blob: 0bf690e73d157fffa65d423060227aced9865fe3 [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
Graeme Russfea25722011-04-13 19:43:28 +10005#if defined(CONFIG_X86)
wdenk27b207f2003-07-24 23:38:38 +00006/*
7 * x86 does not have a dedicated register to store the pointer to
8 * the global_data. Thus the jump table address is stored in a
9 * global variable, but such approach does not allow for execution
10 * from flash memory. The global_data address is passed as argv[-1]
11 * to the application program.
12 */
13static void **jt;
wdenk77846742003-07-26 08:08:08 +000014gd_t *global_data;
wdenk27b207f2003-07-24 23:38:38 +000015
16#define EXPORT_FUNC(x) \
17 asm volatile ( \
18" .globl " #x "\n" \
19#x ":\n" \
20" movl %0, %%eax\n" \
21" movl jt, %%ecx\n" \
22" jmp *(%%ecx, %%eax)\n" \
23 : : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx");
24#elif defined(CONFIG_PPC)
25/*
Wolfgang Denke7670f62008-02-14 22:43:22 +010026 * r2 holds the pointer to the global_data, r11 is a call-clobbered
wdenk27b207f2003-07-24 23:38:38 +000027 * register
28 */
29#define EXPORT_FUNC(x) \
30 asm volatile ( \
31" .globl " #x "\n" \
32#x ":\n" \
Wolfgang Denke7670f62008-02-14 22:43:22 +010033" lwz %%r11, %0(%%r2)\n" \
wdenk27b207f2003-07-24 23:38:38 +000034" lwz %%r11, %1(%%r11)\n" \
35" mtctr %%r11\n" \
36" bctr\n" \
37 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
38#elif defined(CONFIG_ARM)
David Feng0ae76532013-12-14 11:47:35 +080039#ifdef CONFIG_ARM64
40/*
41 * x18 holds the pointer to the global_data, x9 is a call-clobbered
42 * register
43 */
44#define EXPORT_FUNC(x) \
45 asm volatile ( \
46" .globl " #x "\n" \
47#x ":\n" \
48" ldr x9, [x18, %0]\n" \
49" ldr x9, [x9, %1]\n" \
50" br x9\n" \
51 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "x9");
52#else
wdenk27b207f2003-07-24 23:38:38 +000053/*
Jeroen Hofsteea5a42ee2013-11-21 22:32:51 +010054 * r9 holds the pointer to the global_data, ip is a call-clobbered
wdenk27b207f2003-07-24 23:38:38 +000055 * register
56 */
57#define EXPORT_FUNC(x) \
58 asm volatile ( \
59" .globl " #x "\n" \
60#x ":\n" \
Jeroen Hofsteea5a42ee2013-11-21 22:32:51 +010061" ldr ip, [r9, %0]\n" \
wdenk27b207f2003-07-24 23:38:38 +000062" ldr pc, [ip, %1]\n" \
63 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
David Feng0ae76532013-12-14 11:47:35 +080064#endif
wdenk27b207f2003-07-24 23:38:38 +000065#elif defined(CONFIG_MIPS)
66/*
67 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
68 * clobbered register that is also used to set gp ($26). Note that the
69 * jr instruction also executes the instruction immediately following
70 * it; however, GCC/mips generates an additional `nop' after each asm
71 * statement
72 */
73#define EXPORT_FUNC(x) \
74 asm volatile ( \
75" .globl " #x "\n" \
76#x ":\n" \
77" lw $25, %0($26)\n" \
78" lw $25, %1($25)\n" \
79" jr $25\n" \
80 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9");
wdenk5c952cf2004-10-10 21:27:30 +000081#elif defined(CONFIG_NIOS2)
82/*
Thomas Chou0df01fd2010-05-21 11:08:03 +080083 * gp holds the pointer to the global_data, r8 is call-clobbered
wdenk5c952cf2004-10-10 21:27:30 +000084 */
85#define EXPORT_FUNC(x) \
86 asm volatile ( \
87" .globl " #x "\n" \
88#x ":\n" \
89" movhi r8, %%hi(%0)\n" \
90" ori r8, r0, %%lo(%0)\n" \
Thomas Chou0df01fd2010-05-21 11:08:03 +080091" add r8, r8, gp\n" \
wdenk5c952cf2004-10-10 21:27:30 +000092" ldw r8, 0(r8)\n" \
93" ldw r8, %1(r8)\n" \
94" jmp r8\n" \
Thomas Chou0df01fd2010-05-21 11:08:03 +080095 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "gp");
wdenkbf9e3b32004-02-12 00:47:09 +000096#elif defined(CONFIG_M68K)
97/*
98 * d7 holds the pointer to the global_data, a0 is a call-clobbered
99 * register
100 */
101#define EXPORT_FUNC(x) \
102 asm volatile ( \
103" .globl " #x "\n" \
104#x ":\n" \
105" move.l %%d7, %%a0\n" \
106" adda.l %0, %%a0\n" \
107" move.l (%%a0), %%a0\n" \
108" adda.l %1, %%a0\n" \
109" move.l (%%a0), %%a0\n" \
110" jmp (%%a0)\n" \
111 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
wdenk857cad32004-07-10 23:48:41 +0000112#elif defined(CONFIG_MICROBLAZE)
wdenk507bbe32004-04-18 21:13:41 +0000113/*
114 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
115 */
116#define EXPORT_FUNC(x) \
117 asm volatile ( \
118" .globl " #x "\n" \
119#x ":\n" \
120" lwi r5, r31, %0\n" \
121" lwi r5, r5, %1\n" \
122" bra r5\n" \
123 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5");
Wolfgang Denk0afe5192006-03-12 02:10:00 +0100124#elif defined(CONFIG_BLACKFIN)
125/*
Robin Getzc4db3352009-08-17 15:23:02 +0000126 * P3 holds the pointer to the global_data, P0 is a call-clobbered
Wolfgang Denk0afe5192006-03-12 02:10:00 +0100127 * register
128 */
129#define EXPORT_FUNC(x) \
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100130 asm volatile ( \
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100131" .globl _" #x "\n_" \
Wolfgang Denk0afe5192006-03-12 02:10:00 +0100132#x ":\n" \
Robin Getzc4db3352009-08-17 15:23:02 +0000133" P0 = [P3 + %0]\n" \
Wolfgang Denk0afe5192006-03-12 02:10:00 +0100134" P0 = [P0 + %1]\n" \
135" JUMP (P0)\n" \
136 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "P0");
Wolfgang Denk7b64fef2006-10-24 14:21:16 +0200137#elif defined(CONFIG_AVR32)
138/*
139 * r6 holds the pointer to the global_data. r8 is call clobbered.
140 */
141#define EXPORT_FUNC(x) \
142 asm volatile( \
143 " .globl\t" #x "\n" \
144 #x ":\n" \
145 " ld.w r8, r6[%0]\n" \
146 " ld.w pc, r8[%1]\n" \
147 : \
148 : "i"(offsetof(gd_t, jt)), "i"(XF_ ##x) \
149 : "r8");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900150#elif defined(CONFIG_SH)
151/*
152 * r13 holds the pointer to the global_data. r1 is a call clobbered.
153 */
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100154#define EXPORT_FUNC(x) \
155 asm volatile ( \
156 " .align 2\n" \
157 " .globl " #x "\n" \
158 #x ":\n" \
159 " mov r13, r1\n" \
160 " add %0, r1\n" \
Nobuhiro Iwamatsucae6f902008-10-09 13:54:33 +0900161 " mov.l @r1, r2\n" \
162 " add %1, r2\n" \
163 " mov.l @r2, r1\n" \
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100164 " jmp @r1\n" \
165 " nop\n" \
166 " nop\n" \
Nobuhiro Iwamatsucae6f902008-10-09 13:54:33 +0900167 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r1", "r2");
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100168#elif defined(CONFIG_SPARC)
169/*
170 * g7 holds the pointer to the global_data. g1 is call clobbered.
171 */
172#define EXPORT_FUNC(x) \
173 asm volatile( \
174" .globl\t" #x "\n" \
175#x ":\n" \
176" set %0, %%g1\n" \
177" or %%g1, %%g7, %%g1\n" \
178" ld [%%g1], %%g1\n" \
179" ld [%%g1 + %1], %%g1\n" \
Sergey Mironov2c0c58b2009-09-23 16:47:38 +0400180" jmp %%g1\n" \
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100181" nop\n" \
Sergey Mironov2c0c58b2009-09-23 16:47:38 +0400182 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "g1" );
Macpaul Lin72c73dd2011-10-11 22:33:20 +0000183#elif defined(CONFIG_NDS32)
184/*
185 * r16 holds the pointer to the global_data. gp is call clobbered.
186 * not support reduced register (16 GPR).
187 */
188#define EXPORT_FUNC(x) \
189 asm volatile ( \
190" .globl " #x "\n" \
191#x ":\n" \
192" lwi $r16, [$gp + (%0)]\n" \
193" lwi $r16, [$r16 + (%1)]\n" \
194" jr $r16\n" \
195 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "$r16");
Stefan Kristiansson35534932011-11-18 19:21:35 +0000196#elif defined(CONFIG_OPENRISC)
197/*
198 * r10 holds the pointer to the global_data, r13 is a call-clobbered
199 * register
200 */
201#define EXPORT_FUNC(x) \
202 asm volatile ( \
203" .globl " #x "\n" \
204#x ":\n" \
205" l.lwz r13, %0(r10)\n" \
206" l.lwz r13, %1(r13)\n" \
207" l.jr r13\n" \
208" l.nop\n" \
209 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r13");
Alexey Brodkin794ab572014-02-04 12:56:17 +0400210#elif defined(CONFIG_ARC)
211/*
212 * r25 holds the pointer to the global_data. r10 is call clobbered.
213 */
214#define EXPORT_FUNC(x) \
215 asm volatile( \
216" .align 4\n" \
217" .globl " #x "\n" \
218#x ":\n" \
219" ld r10, [r25, %0]\n" \
220" ld r10, [r10, %1]\n" \
221" j [r10]\n" \
222 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r10");
wdenk27b207f2003-07-24 23:38:38 +0000223#else
Macpaul Lin72c73dd2011-10-11 22:33:20 +0000224/*" addi $sp, $sp, -24\n" \
225" br $r16\n" \*/
226
wdenk27b207f2003-07-24 23:38:38 +0000227#error stubs definition missing for this architecture
228#endif
229
230/* This function is necessary to prevent the compiler from
231 * generating prologue/epilogue, preparing stack frame etc.
232 * The stub functions are special, they do not use the stack
233 * frame passed to them, but pass it intact to the actual
234 * implementation. On the other hand, asm() statements with
235 * arguments can be used only inside the functions (gcc limitation)
236 */
Masahiro Yamada2d5db192014-09-04 02:40:59 +0900237#if GCC_VERSION < 30400
wdenk93f6a672004-07-01 20:28:03 +0000238static
239#endif /* GCC_VERSION */
240void __attribute__((unused)) dummy(void)
wdenk27b207f2003-07-24 23:38:38 +0000241{
242#include <_exports.h>
243}
244
Simon Glass716cc8c2013-03-05 14:39:39 +0000245#include <asm/sections.h>
wdenkd716b122004-04-12 16:12:49 +0000246
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200247void app_startup(char * const *argv)
wdenk27b207f2003-07-24 23:38:38 +0000248{
Simon Glass716cc8c2013-03-05 14:39:39 +0000249 char *cp = __bss_start;
wdenkd716b122004-04-12 16:12:49 +0000250
251 /* Zero out BSS */
Simon Glass716cc8c2013-03-05 14:39:39 +0000252 while (cp < _end)
wdenkd716b122004-04-12 16:12:49 +0000253 *cp++ = 0;
wdenkd716b122004-04-12 16:12:49 +0000254
Graeme Russfea25722011-04-13 19:43:28 +1000255#if defined(CONFIG_X86)
wdenk27b207f2003-07-24 23:38:38 +0000256 /* x86 does not have a dedicated register for passing global_data */
wdenk77846742003-07-26 08:08:08 +0000257 global_data = (gd_t *)argv[-1];
258 jt = global_data->jt;
wdenk27b207f2003-07-24 23:38:38 +0000259#endif
260}
261
262#undef EXPORT_FUNC