blob: ec5353216b54983aa95a996def7597945cc888c0 [file] [log] [blame]
wdenk27b207f2003-07-24 23:38:38 +00001#include <exports.h>
2
wdenk93f6a672004-07-01 20:28:03 +00003#ifndef GCC_VERSION
4#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
5#endif /* GCC_VERSION */
6
wdenk27b207f2003-07-24 23:38:38 +00007#if defined(CONFIG_I386)
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 */
15static void **jt;
wdenk77846742003-07-26 08:08:08 +000016gd_t *global_data;
wdenk27b207f2003-07-24 23:38:38 +000017
18#define EXPORT_FUNC(x) \
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" \
25 : : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx");
26#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 */
31#define EXPORT_FUNC(x) \
32 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" \
39 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
40#elif defined(CONFIG_ARM)
41/*
42 * r8 holds the pointer to the global_data, ip is a call-clobbered
43 * register
44 */
45#define EXPORT_FUNC(x) \
46 asm volatile ( \
47" .globl " #x "\n" \
48#x ":\n" \
49" ldr ip, [r8, %0]\n" \
50" ldr pc, [ip, %1]\n" \
51 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
52#elif defined(CONFIG_MIPS)
53/*
54 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
55 * clobbered register that is also used to set gp ($26). Note that the
56 * jr instruction also executes the instruction immediately following
57 * it; however, GCC/mips generates an additional `nop' after each asm
58 * statement
59 */
60#define EXPORT_FUNC(x) \
61 asm volatile ( \
62" .globl " #x "\n" \
63#x ":\n" \
64" lw $25, %0($26)\n" \
65" lw $25, %1($25)\n" \
66" jr $25\n" \
67 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9");
wdenk4a551702003-10-08 23:26:14 +000068#elif defined(CONFIG_NIOS)
69/*
70 * %g7 holds the pointer to the global_data. %g0 is call clobbered.
71 */
72#define EXPORT_FUNC(x) \
73 asm volatile ( \
74" .globl " #x "\n" \
75#x ":\n" \
76" pfx %%hi(%0)\n" \
77" movi %%g0, %%lo(%0)\n" \
78" add %%g0, %%g7\n" \
79" ld %%g0, [%%g0]\n" \
80" pfx %1\n" \
81" ld %%g0, [%%g0]\n" \
82" jmp %%g0\n" \
83" nop \n" \
84 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x) : "r0");
wdenk5c952cf2004-10-10 21:27:30 +000085#elif defined(CONFIG_NIOS2)
86/*
87 * r15 holds the pointer to the global_data, r8 is call-clobbered
88 */
89#define EXPORT_FUNC(x) \
90 asm volatile ( \
91" .globl " #x "\n" \
92#x ":\n" \
93" movhi r8, %%hi(%0)\n" \
94" ori r8, r0, %%lo(%0)\n" \
Scott McNuttc2ced002006-06-08 11:59:57 -040095" add r8, r8, r15\n" \
wdenk5c952cf2004-10-10 21:27:30 +000096" ldw r8, 0(r8)\n" \
97" ldw r8, %1(r8)\n" \
98" jmp r8\n" \
99 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r15");
wdenkbf9e3b32004-02-12 00:47:09 +0000100#elif defined(CONFIG_M68K)
101/*
102 * d7 holds the pointer to the global_data, a0 is a call-clobbered
103 * register
104 */
105#define EXPORT_FUNC(x) \
106 asm volatile ( \
107" .globl " #x "\n" \
108#x ":\n" \
109" move.l %%d7, %%a0\n" \
110" adda.l %0, %%a0\n" \
111" move.l (%%a0), %%a0\n" \
112" adda.l %1, %%a0\n" \
113" move.l (%%a0), %%a0\n" \
114" jmp (%%a0)\n" \
115 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
wdenk857cad32004-07-10 23:48:41 +0000116#elif defined(CONFIG_MICROBLAZE)
wdenk507bbe32004-04-18 21:13:41 +0000117/*
118 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
119 */
120#define EXPORT_FUNC(x) \
121 asm volatile ( \
122" .globl " #x "\n" \
123#x ":\n" \
124" lwi r5, r31, %0\n" \
125" lwi r5, r5, %1\n" \
126" bra r5\n" \
127 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5");
Wolfgang Denk0afe5192006-03-12 02:10:00 +0100128#elif defined(CONFIG_BLACKFIN)
129/*
130 * P5 holds the pointer to the global_data, P0 is a call-clobbered
131 * register
132 */
133#define EXPORT_FUNC(x) \
Wolfgang Denk8e7b7032006-03-12 02:55:22 +0100134 asm volatile ( \
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100135" .globl _" #x "\n_" \
Wolfgang Denk0afe5192006-03-12 02:10:00 +0100136#x ":\n" \
137" P0 = [P5 + %0]\n" \
138" P0 = [P0 + %1]\n" \
139" JUMP (P0)\n" \
140 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "P0");
Wolfgang Denk7b64fef2006-10-24 14:21:16 +0200141#elif defined(CONFIG_AVR32)
142/*
143 * r6 holds the pointer to the global_data. r8 is call clobbered.
144 */
145#define EXPORT_FUNC(x) \
146 asm volatile( \
147 " .globl\t" #x "\n" \
148 #x ":\n" \
149 " ld.w r8, r6[%0]\n" \
150 " ld.w pc, r8[%1]\n" \
151 : \
152 : "i"(offsetof(gd_t, jt)), "i"(XF_ ##x) \
153 : "r8");
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900154#elif defined(CONFIG_SH)
155/*
156 * r13 holds the pointer to the global_data. r1 is a call clobbered.
157 */
Wolfgang Denk61fb15c52007-12-27 01:52:50 +0100158#define EXPORT_FUNC(x) \
159 asm volatile ( \
160 " .align 2\n" \
161 " .globl " #x "\n" \
162 #x ":\n" \
163 " mov r13, r1\n" \
164 " add %0, r1\n" \
165 " add %1, r1\n" \
166 " jmp @r1\n" \
167 " nop\n" \
168 " nop\n" \
Nobuhiro Iwamatsu0b135cf2007-05-13 20:58:00 +0900169 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r1");
Daniel Hellstromc2f02da2008-03-28 09:47:00 +0100170#elif defined(CONFIG_SPARC)
171/*
172 * g7 holds the pointer to the global_data. g1 is call clobbered.
173 */
174#define EXPORT_FUNC(x) \
175 asm volatile( \
176" .globl\t" #x "\n" \
177#x ":\n" \
178" set %0, %%g1\n" \
179" or %%g1, %%g7, %%g1\n" \
180" ld [%%g1], %%g1\n" \
181" ld [%%g1 + %1], %%g1\n" \
182" call %%g1\n" \
183" nop\n" \
184 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x) : "g1" );
185
wdenk27b207f2003-07-24 23:38:38 +0000186#else
187#error stubs definition missing for this architecture
188#endif
189
190/* This function is necessary to prevent the compiler from
191 * generating prologue/epilogue, preparing stack frame etc.
192 * The stub functions are special, they do not use the stack
193 * frame passed to them, but pass it intact to the actual
194 * implementation. On the other hand, asm() statements with
195 * arguments can be used only inside the functions (gcc limitation)
196 */
wdenk93f6a672004-07-01 20:28:03 +0000197#if GCC_VERSION < 3004
198static
199#endif /* GCC_VERSION */
200void __attribute__((unused)) dummy(void)
wdenk27b207f2003-07-24 23:38:38 +0000201{
202#include <_exports.h>
203}
204
wdenkd716b122004-04-12 16:12:49 +0000205extern unsigned long __bss_start, _end;
206
wdenk27b207f2003-07-24 23:38:38 +0000207void app_startup(char **argv)
208{
Woodruff, Richard118978c2008-02-29 17:34:35 -0600209 unsigned char * cp = (unsigned char *) &__bss_start;
wdenkd716b122004-04-12 16:12:49 +0000210
211 /* Zero out BSS */
Woodruff, Richard118978c2008-02-29 17:34:35 -0600212 while (cp < (unsigned char *)&_end) {
wdenkd716b122004-04-12 16:12:49 +0000213 *cp++ = 0;
214 }
215
wdenk27b207f2003-07-24 23:38:38 +0000216#if defined(CONFIG_I386)
217 /* x86 does not have a dedicated register for passing global_data */
wdenk77846742003-07-26 08:08:08 +0000218 global_data = (gd_t *)argv[-1];
219 jt = global_data->jt;
wdenk27b207f2003-07-24 23:38:38 +0000220#endif
221}
222
223#undef EXPORT_FUNC