]>
Commit | Line | Data |
---|---|---|
27b207fd WD |
1 | #include <exports.h> |
2 | ||
93f6a677 WD |
3 | #ifndef GCC_VERSION |
4 | #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) | |
5 | #endif /* GCC_VERSION */ | |
6 | ||
27b207fd WD |
7 | #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 | */ | |
15 | static void **jt; | |
77846748 | 16 | gd_t *global_data; |
27b207fd WD |
17 | |
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 | /* | |
28 | * r29 holds the pointer to the global_data, r11 is a call-clobbered | |
29 | * register | |
30 | */ | |
31 | #define EXPORT_FUNC(x) \ | |
32 | asm volatile ( \ | |
33 | " .globl " #x "\n" \ | |
34 | #x ":\n" \ | |
35 | " lwz %%r11, %0(%%r29)\n" \ | |
36 | " 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"); | |
4a551709 WD |
68 | #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"); | |
bf9e3b38 WD |
85 | #elif defined(CONFIG_M68K) |
86 | /* | |
87 | * d7 holds the pointer to the global_data, a0 is a call-clobbered | |
88 | * register | |
89 | */ | |
90 | #define EXPORT_FUNC(x) \ | |
91 | asm volatile ( \ | |
92 | " .globl " #x "\n" \ | |
93 | #x ":\n" \ | |
94 | " move.l %%d7, %%a0\n" \ | |
95 | " adda.l %0, %%a0\n" \ | |
96 | " move.l (%%a0), %%a0\n" \ | |
97 | " adda.l %1, %%a0\n" \ | |
98 | " move.l (%%a0), %%a0\n" \ | |
99 | " jmp (%%a0)\n" \ | |
100 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0"); | |
857cad37 | 101 | #elif defined(CONFIG_MICROBLAZE) |
507bbe3e WD |
102 | /* |
103 | * r31 holds the pointer to the global_data. r5 is a call-clobbered. | |
104 | */ | |
105 | #define EXPORT_FUNC(x) \ | |
106 | asm volatile ( \ | |
107 | " .globl " #x "\n" \ | |
108 | #x ":\n" \ | |
109 | " lwi r5, r31, %0\n" \ | |
110 | " lwi r5, r5, %1\n" \ | |
111 | " bra r5\n" \ | |
112 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5"); | |
27b207fd WD |
113 | #else |
114 | #error stubs definition missing for this architecture | |
115 | #endif | |
116 | ||
117 | /* This function is necessary to prevent the compiler from | |
118 | * generating prologue/epilogue, preparing stack frame etc. | |
119 | * The stub functions are special, they do not use the stack | |
120 | * frame passed to them, but pass it intact to the actual | |
121 | * implementation. On the other hand, asm() statements with | |
122 | * arguments can be used only inside the functions (gcc limitation) | |
123 | */ | |
93f6a677 WD |
124 | #if GCC_VERSION < 3004 |
125 | static | |
126 | #endif /* GCC_VERSION */ | |
127 | void __attribute__((unused)) dummy(void) | |
27b207fd WD |
128 | { |
129 | #include <_exports.h> | |
130 | } | |
131 | ||
d716b126 WD |
132 | extern unsigned long __bss_start, _end; |
133 | ||
27b207fd WD |
134 | void app_startup(char **argv) |
135 | { | |
d716b126 WD |
136 | unsigned long * cp = &__bss_start; |
137 | ||
138 | /* Zero out BSS */ | |
139 | while (cp < &_end) { | |
140 | *cp++ = 0; | |
141 | } | |
142 | ||
27b207fd WD |
143 | #if defined(CONFIG_I386) |
144 | /* x86 does not have a dedicated register for passing global_data */ | |
77846748 WD |
145 | global_data = (gd_t *)argv[-1]; |
146 | jt = global_data->jt; | |
27b207fd WD |
147 | #endif |
148 | } | |
149 | ||
150 | #undef EXPORT_FUNC |