1 #include <exports.h>
2 #include <linux/compiler.h>
3
4 struct cmd_tbl;
5
6 #define FO(x) offsetof(struct jt_funcs, x)
7
8 #if defined(CONFIG_X86)
9 /*
10 * x86 does not have a dedicated register to store the pointer to
11 * the global_data. Thus the jump table address is stored in a
12 * global variable, but such approach does not allow for execution
13 * from flash memory. The global_data address is passed as argv[-1]
14 * to the application program.
15 */
16 struct jt_funcs *jt;
17 gd_t *global_data;
18
19 #define EXPORT_FUNC(f, a, x, ...) \
20 asm volatile ( \
21 " .globl " #x "\n" \
22 #x ":\n" \
23 " movl %0, %%eax\n" \
24 " movl jt, %%ecx\n" \
25 " jmp *(%%ecx, %%eax)\n" \
26 : : "i"(FO(x)) : "eax", "ecx");
27 #elif defined(CONFIG_PPC)
28 /*
29 * r2 holds the pointer to the global_data, r11 is a call-clobbered
30 * register
31 */
32 #define EXPORT_FUNC(f, a, x, ...) \
33 asm volatile ( \
34 " .globl " #x "\n" \
35 #x ":\n" \
36 " lwz %%r11, %0(%%r2)\n" \
37 " lwz %%r11, %1(%%r11)\n" \
38 " mtctr %%r11\n" \
39 " bctr\n" \
40 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11");
41 #elif defined(CONFIG_ARM)
42 #ifdef CONFIG_ARM64
43 /*
44 * x18 holds the pointer to the global_data, x9 is a call-clobbered
45 * register
46 */
47 #define EXPORT_FUNC(f, a, x, ...) \
48 asm volatile ( \
49 " .globl " #x "\n" \
50 #x ":\n" \
51 " ldr x9, [x18, %0]\n" \
52 " ldr x9, [x9, %1]\n" \
53 " br x9\n" \
54 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9");
55 #else
56 /*
57 * r9 holds the pointer to the global_data, ip is a call-clobbered
58 * register
59 */
60 #define EXPORT_FUNC(f, a, x, ...) \
61 asm volatile ( \
62 " .globl " #x "\n" \
63 #x ":\n" \
64 " ldr ip, [r9, %0]\n" \
65 " ldr pc, [ip, %1]\n" \
66 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip");
67 #endif
68 #elif defined(CONFIG_MIPS)
69 #ifdef CONFIG_CPU_MIPS64
70 /*
71 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
72 * clobbered register that is also used to set gp ($26). Note that the
73 * jr instruction also executes the instruction immediately following
74 * it; however, GCC/mips generates an additional `nop' after each asm
75 * statement
76 */
77 #define EXPORT_FUNC(f, a, x, ...) \
78 asm volatile ( \
79 " .globl " #x "\n" \
80 #x ":\n" \
81 " ld $25, %0($26)\n" \
82 " ld $25, %1($25)\n" \
83 " jr $25\n" \
84 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
85 #else
86 /*
87 * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
88 * clobbered register that is also used to set gp ($26). Note that the
89 * jr instruction also executes the instruction immediately following
90 * it; however, GCC/mips generates an additional `nop' after each asm
91 * statement
92 */
93 #define EXPORT_FUNC(f, a, x, ...) \
94 asm volatile ( \
95 " .globl " #x "\n" \
96 #x ":\n" \
97 " lw $25, %0($26)\n" \
98 " lw $25, %1($25)\n" \
99 " jr $25\n" \
100 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
101 #endif
102 #elif defined(CONFIG_NIOS2)
103 /*
104 * gp holds the pointer to the global_data, r8 is call-clobbered
105 */
106 #define EXPORT_FUNC(f, a, x, ...) \
107 asm volatile ( \
108 " .globl " #x "\n" \
109 #x ":\n" \
110 " movhi r8, %%hi(%0)\n" \
111 " ori r8, r0, %%lo(%0)\n" \
112 " add r8, r8, gp\n" \
113 " ldw r8, 0(r8)\n" \
114 " ldw r8, %1(r8)\n" \
115 " jmp r8\n" \
116 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp");
117 #elif defined(CONFIG_M68K)
118 /*
119 * d7 holds the pointer to the global_data, a0 is a call-clobbered
120 * register
121 */
122 #define EXPORT_FUNC(f, a, x, ...) \
123 asm volatile ( \
124 " .globl " #x "\n" \
125 #x ":\n" \
126 " move.l %%d7, %%a0\n" \
127 " adda.l %0, %%a0\n" \
128 " move.l (%%a0), %%a0\n" \
129 " adda.l %1, %%a0\n" \
130 " move.l (%%a0), %%a0\n" \
131 " jmp (%%a0)\n" \
132 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0");
133 #elif defined(CONFIG_MICROBLAZE)
134 /*
135 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
136 */
137 #define EXPORT_FUNC(f, a, x, ...) \
138 asm volatile ( \
139 " .globl " #x "\n" \
140 #x ":\n" \
141 " lwi r5, r31, %0\n" \
142 " lwi r5, r5, %1\n" \
143 " bra r5\n" \
144 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5");
145 #elif defined(CONFIG_SH)
146 /*
147 * r13 holds the pointer to the global_data. r1 is a call clobbered.
148 */
149 #define EXPORT_FUNC(f, a, x, ...) \
150 asm volatile ( \
151 " .align 2\n" \
152 " .globl " #x "\n" \
153 #x ":\n" \
154 " mov r13, r1\n" \
155 " add %0, r1\n" \
156 " mov.l @r1, r2\n" \
157 " add %1, r2\n" \
158 " mov.l @r2, r1\n" \
159 " jmp @r1\n" \
160 " nop\n" \
161 " nop\n" \
162 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2");
163 #elif defined(CONFIG_RISCV)
164 /*
165 * gp holds the pointer to the global_data. t0 is call clobbered.
166 */
167 #ifdef CONFIG_ARCH_RV64I
168 #define EXPORT_FUNC(f, a, x, ...) \
169 asm volatile ( \
170 " .globl " #x "\n" \
171 #x ":\n" \
172 " ld t0, %0(gp)\n" \
173 " ld t0, %1(t0)\n" \
174 " jr t0\n" \
175 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
176 #else
177 #define EXPORT_FUNC(f, a, x, ...) \
178 asm volatile ( \
179 " .globl " #x "\n" \
180 #x ":\n" \
181 " lw t0, %0(gp)\n" \
182 " lw t0, %1(t0)\n" \
183 " jr t0\n" \
184 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
185 #endif
186 #elif defined(CONFIG_ARC)
187 /*
188 * r25 holds the pointer to the global_data. r10 is call clobbered.
189 */
190 #define EXPORT_FUNC(f, a, x, ...) \
191 asm volatile( \
192 " .align 4\n" \
193 " .globl " #x "\n" \
194 #x ":\n" \
195 " ld r10, [r25, %0]\n" \
196 " ld r10, [r10, %1]\n" \
197 " j [r10]\n" \
198 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10");
199 #elif defined(CONFIG_XTENSA)
200 /*
201 * Global data ptr is in global_data, jump table ptr is in jt.
202 * Windowed ABI: Jump just past 'entry' in target and adjust stack frame
203 * (extract stack frame size from target 'entry' instruction).
204 */
205
206 static void **jt;
207
208 #if defined(__XTENSA_CALL0_ABI__)
209 #define EXPORT_FUNC(f, a, x, ...) \
210 asm volatile ( \
211 " .extern jt\n" \
212 " .globl " #x "\n" \
213 " .align 4\n" \
214 #x ":\n" \
215 " l32i a8, %0, 0\n" \
216 " l32i a8, a8, %1\n" \
217 " jx a8\n" \
218 : : "r"(jt), "i" (FO(x)) : "a8");
219 #elif defined(__XTENSA_WINDOWED_ABI__)
220 #if XCHAL_HAVE_BE
221 # define SFT "8"
222 #else
223 # define SFT "12"
224 #endif
225 #define EXPORT_FUNC(f, a, x, ...) \
226 asm volatile ( \
227 " .extern jt\n" \
228 " .globl " #x "\n" \
229 " .align 4\n" \
230 #x ":\n" \
231 " entry sp, 16\n" \
232 " l32i a8, %0, 0\n" \
233 " l32i a8, a8, %1\n" \
234 " l32i a9, a8, 0\n" \
235 " extui a9, a9, " SFT ", 12\n" \
236 " subx8 a9, a9, sp\n" \
237 " movi a10, 16\n" \
238 " sub a9, a10, a9\n" \
239 " movsp sp, a9\n" \
240 " addi a8, a8, 3\n" \
241 " jx a8\n" \
242 : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10");
243 #else
244 #error Unsupported Xtensa ABI
245 #endif
246 #else
247 /*" addi $sp, $sp, -24\n" \
248 " br $r16\n" \*/
249
250 #error stubs definition missing for this architecture
251 #endif
252
253 /* This function is necessary to prevent the compiler from
254 * generating prologue/epilogue, preparing stack frame etc.
255 * The stub functions are special, they do not use the stack
256 * frame passed to them, but pass it intact to the actual
257 * implementation. On the other hand, asm() statements with
258 * arguments can be used only inside the functions (gcc limitation)
259 */
260 #if GCC_VERSION < 30400
261 static
262 #endif /* GCC_VERSION */
dummy(void)263 void __attribute__((unused)) dummy(void)
264 {
265 #include <_exports.h>
266 }
267
268 #include <asm/sections.h>
269
app_startup(char * const * argv)270 void app_startup(char * const *argv)
271 {
272 char *cp = __bss_start;
273
274 /* Zero out BSS */
275 while (cp < _end)
276 *cp++ = 0;
277
278 #if defined(CONFIG_X86)
279 /* x86 does not have a dedicated register for passing global_data */
280 global_data = (gd_t *)argv[-1];
281 jt = global_data->jt;
282 #endif
283 }
284
285 #undef EXPORT_FUNC
286