2 #include <linux/compiler.h>
6 #define FO(x) offsetof(struct jt_funcs, x)
8 #if defined(CONFIG_X86)
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.
19 #define EXPORT_FUNC(f, a, x, ...) \
25 " jmp *(%%ecx, %%eax)\n" \
26 : : "i"(FO(x)) : "eax", "ecx");
27 #elif defined(CONFIG_PPC)
29 * r2 holds the pointer to the global_data, r11 is a call-clobbered
32 #define EXPORT_FUNC(f, a, x, ...) \
36 " lwz %%r11, %0(%%r2)\n" \
37 " lwz %%r11, %1(%%r11)\n" \
40 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11");
41 #elif defined(CONFIG_ARM)
44 * x18 holds the pointer to the global_data, x9 is a call-clobbered
47 #define EXPORT_FUNC(f, a, x, ...) \
51 " ldr x9, [x18, %0]\n" \
52 " ldr x9, [x9, %1]\n" \
54 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9");
57 * r9 holds the pointer to the global_data, ip is a call-clobbered
60 #define EXPORT_FUNC(f, a, x, ...) \
64 " ldr ip, [r9, %0]\n" \
65 " ldr pc, [ip, %1]\n" \
66 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip");
68 #elif defined(CONFIG_MIPS)
69 #ifdef CONFIG_CPU_MIPS64
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
77 #define EXPORT_FUNC(f, a, x, ...) \
81 " ld $25, %0($26)\n" \
82 " ld $25, %1($25)\n" \
84 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
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
93 #define EXPORT_FUNC(f, a, x, ...) \
97 " lw $25, %0($26)\n" \
98 " lw $25, %1($25)\n" \
100 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
102 #elif defined(CONFIG_NIOS2)
104 * gp holds the pointer to the global_data, r8 is call-clobbered
106 #define EXPORT_FUNC(f, a, x, ...) \
110 " movhi r8, %%hi(%0)\n" \
111 " ori r8, r0, %%lo(%0)\n" \
112 " add r8, r8, gp\n" \
114 " ldw r8, %1(r8)\n" \
116 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp");
117 #elif defined(CONFIG_M68K)
119 * d7 holds the pointer to the global_data, a0 is a call-clobbered
122 #define EXPORT_FUNC(f, a, x, ...) \
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" \
132 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0");
133 #elif defined(CONFIG_MICROBLAZE)
135 * r31 holds the pointer to the global_data. r5 is a call-clobbered.
137 #define EXPORT_FUNC(f, a, x, ...) \
141 " lwi r5, r31, %0\n" \
142 " lwi r5, r5, %1\n" \
144 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5");
145 #elif defined(CONFIG_SH)
147 * r13 holds the pointer to the global_data. r1 is a call clobbered.
149 #define EXPORT_FUNC(f, a, x, ...) \
162 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2");
163 #elif defined(CONFIG_RISCV)
165 * gp holds the pointer to the global_data. t0 is call clobbered.
167 #ifdef CONFIG_ARCH_RV64I
168 #define EXPORT_FUNC(f, a, x, ...) \
175 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
177 #define EXPORT_FUNC(f, a, x, ...) \
184 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t0");
186 #elif defined(CONFIG_ARC)
188 * r25 holds the pointer to the global_data. r10 is call clobbered.
190 #define EXPORT_FUNC(f, a, x, ...) \
195 " ld r10, [r25, %0]\n" \
196 " ld r10, [r10, %1]\n" \
198 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10");
199 #elif defined(CONFIG_XTENSA)
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).
208 #if defined(__XTENSA_CALL0_ABI__)
209 #define EXPORT_FUNC(f, a, x, ...) \
215 " l32i a8, %0, 0\n" \
216 " l32i a8, a8, %1\n" \
218 : : "r"(jt), "i" (FO(x)) : "a8");
219 #elif defined(__XTENSA_WINDOWED_ABI__)
225 #define EXPORT_FUNC(f, a, x, ...) \
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" \
238 " sub a9, a10, a9\n" \
240 " addi a8, a8, 3\n" \
242 : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10");
244 #error Unsupported Xtensa ABI
247 /*" addi $sp, $sp, -24\n" \
250 #error stubs definition missing for this architecture
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)
260 #if GCC_VERSION < 30400
262 #endif /* GCC_VERSION */
263 void __attribute__((unused)) dummy(void)
265 #include <_exports.h>
268 #include <asm/sections.h>
270 void app_startup(char * const *argv)
272 char *cp = __bss_start;
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;