]> git.ipfire.org Git - people/ms/u-boot.git/blame - examples/stubs.c
* Configure PPChameleon board to use redundand environment in flash
[people/ms/u-boot.git] / examples / stubs.c
CommitLineData
27b207fd
WD
1#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;
77846748 12gd_t *global_data;
27b207fd
WD
13
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");
4a551709
WD
64#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");
bf9e3b38
WD
81#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");
27b207fd
WD
97#else
98#error stubs definition missing for this architecture
99#endif
100
101/* This function is necessary to prevent the compiler from
102 * generating prologue/epilogue, preparing stack frame etc.
103 * The stub functions are special, they do not use the stack
104 * frame passed to them, but pass it intact to the actual
105 * implementation. On the other hand, asm() statements with
106 * arguments can be used only inside the functions (gcc limitation)
107 */
108static void __attribute__((unused)) dummy(void)
109{
110#include <_exports.h>
111}
112
d716b126
WD
113extern unsigned long __bss_start, _end;
114
27b207fd
WD
115void app_startup(char **argv)
116{
d716b126
WD
117 unsigned long * cp = &__bss_start;
118
119 /* Zero out BSS */
120 while (cp < &_end) {
121 *cp++ = 0;
122 }
123
27b207fd
WD
124#if defined(CONFIG_I386)
125 /* x86 does not have a dedicated register for passing global_data */
77846748
WD
126 global_data = (gd_t *)argv[-1];
127 jt = global_data->jt;
27b207fd
WD
128#endif
129}
130
131#undef EXPORT_FUNC