blob: 6f563ed9ba865f7745f0a31e220d815238f0f185 [file] [log] [blame]
wdenk27b207f2003-07-24 23:38:38 +00001#include <exports.h>
2
3#if defined(CONFIG_I386)
4/*
5 * x86 does not have a dedicated register to store the pointer to
6 * the global_data. Thus the jump table address is stored in a
7 * global variable, but such approach does not allow for execution
8 * from flash memory. The global_data address is passed as argv[-1]
9 * to the application program.
10 */
11static void **jt;
wdenk77846742003-07-26 08:08:08 +000012gd_t *global_data;
wdenk27b207f2003-07-24 23:38:38 +000013
14#define EXPORT_FUNC(x) \
15 asm volatile ( \
16" .globl " #x "\n" \
17#x ":\n" \
18" movl %0, %%eax\n" \
19" movl jt, %%ecx\n" \
20" jmp *(%%ecx, %%eax)\n" \
21 : : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx");
22#elif defined(CONFIG_PPC)
23/*
24 * r29 holds the pointer to the global_data, r11 is a call-clobbered
25 * register
26 */
27#define EXPORT_FUNC(x) \
28 asm volatile ( \
29" .globl " #x "\n" \
30#x ":\n" \
31" lwz %%r11, %0(%%r29)\n" \
32" lwz %%r11, %1(%%r11)\n" \
33" mtctr %%r11\n" \
34" bctr\n" \
35 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
36#elif defined(CONFIG_ARM)
37/*
38 * r8 holds the pointer to the global_data, ip is a call-clobbered
39 * register
40 */
41#define EXPORT_FUNC(x) \
42 asm volatile ( \
43" .globl " #x "\n" \
44#x ":\n" \
45" ldr ip, [r8, %0]\n" \
46" ldr pc, [ip, %1]\n" \
47 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
48#elif defined(CONFIG_MIPS)
49/*
50 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
51 * clobbered register that is also used to set gp ($26). Note that the
52 * jr instruction also executes the instruction immediately following
53 * it; however, GCC/mips generates an additional `nop' after each asm
54 * statement
55 */
56#define EXPORT_FUNC(x) \
57 asm volatile ( \
58" .globl " #x "\n" \
59#x ":\n" \
60" lw $25, %0($26)\n" \
61" lw $25, %1($25)\n" \
62" jr $25\n" \
63 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9");
wdenk4a551702003-10-08 23:26:14 +000064#elif defined(CONFIG_NIOS)
65/*
66 * %g7 holds the pointer to the global_data. %g0 is call clobbered.
67 */
68#define EXPORT_FUNC(x) \
69 asm volatile ( \
70" .globl " #x "\n" \
71#x ":\n" \
72" pfx %%hi(%0)\n" \
73" movi %%g0, %%lo(%0)\n" \
74" add %%g0, %%g7\n" \
75" ld %%g0, [%%g0]\n" \
76" pfx %1\n" \
77" ld %%g0, [%%g0]\n" \
78" jmp %%g0\n" \
79" nop \n" \
80 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x) : "r0");
wdenkbf9e3b32004-02-12 00:47:09 +000081#elif defined(CONFIG_M68K)
82/*
83 * d7 holds the pointer to the global_data, a0 is a call-clobbered
84 * register
85 */
86#define EXPORT_FUNC(x) \
87 asm volatile ( \
88" .globl " #x "\n" \
89#x ":\n" \
90" move.l %%d7, %%a0\n" \
91" adda.l %0, %%a0\n" \
92" move.l (%%a0), %%a0\n" \
93" adda.l %1, %%a0\n" \
94" move.l (%%a0), %%a0\n" \
95" jmp (%%a0)\n" \
96 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
wdenk507bbe32004-04-18 21:13:41 +000097#elif defined(CONFIG_MICROBLZE)
98/*
99 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
100 */
101#define EXPORT_FUNC(x) \
102 asm volatile ( \
103" .globl " #x "\n" \
104#x ":\n" \
105" lwi r5, r31, %0\n" \
106" lwi r5, r5, %1\n" \
107" bra r5\n" \
108 : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5");
wdenk27b207f2003-07-24 23:38:38 +0000109#else
110#error stubs definition missing for this architecture
111#endif
112
113/* This function is necessary to prevent the compiler from
114 * generating prologue/epilogue, preparing stack frame etc.
115 * The stub functions are special, they do not use the stack
116 * frame passed to them, but pass it intact to the actual
117 * implementation. On the other hand, asm() statements with
118 * arguments can be used only inside the functions (gcc limitation)
119 */
120static void __attribute__((unused)) dummy(void)
121{
122#include <_exports.h>
123}
124
wdenkd716b122004-04-12 16:12:49 +0000125extern unsigned long __bss_start, _end;
126
wdenk27b207f2003-07-24 23:38:38 +0000127void app_startup(char **argv)
128{
wdenkd716b122004-04-12 16:12:49 +0000129 unsigned long * cp = &__bss_start;
130
131 /* Zero out BSS */
132 while (cp < &_end) {
133 *cp++ = 0;
134 }
135
wdenk27b207f2003-07-24 23:38:38 +0000136#if defined(CONFIG_I386)
137 /* x86 does not have a dedicated register for passing global_data */
wdenk77846742003-07-26 08:08:08 +0000138 global_data = (gd_t *)argv[-1];
139 jt = global_data->jt;
wdenk27b207f2003-07-24 23:38:38 +0000140#endif
141}
142
143#undef EXPORT_FUNC