1#include <common.h>
2#include <exports.h>
3#include <linux/compiler.h>
4
5#define FO(x) offsetof(struct jt_funcs, x)
6
7#if defined(CONFIG_X86)
8
9
10
11
12
13
14
15static struct jt_funcs *jt;
16gd_t *global_data;
17
18#define EXPORT_FUNC(f, a, 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"(FO(x)) : "eax", "ecx");
26#elif defined(CONFIG_PPC)
27
28
29
30
31#define EXPORT_FUNC(f, a, x, ...) \
32 asm volatile ( \
33" .globl " #x "\n" \
34#x ":\n" \
35" lwz %%r11, %0(%%r2)\n" \
36" lwz %%r11, %1(%%r11)\n" \
37" mtctr %%r11\n" \
38" bctr\n" \
39 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11");
40#elif defined(CONFIG_ARM)
41#ifdef CONFIG_ARM64
42
43
44
45
46#define EXPORT_FUNC(f, a, x, ...) \
47 asm volatile ( \
48" .globl " #x "\n" \
49#x ":\n" \
50" ldr x9, [x18, %0]\n" \
51" ldr x9, [x9, %1]\n" \
52" br x9\n" \
53 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9");
54#else
55
56
57
58
59#define EXPORT_FUNC(f, a, x, ...) \
60 asm volatile ( \
61" .globl " #x "\n" \
62#x ":\n" \
63" ldr ip, [r9, %0]\n" \
64" ldr pc, [ip, %1]\n" \
65 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip");
66#endif
67#elif defined(CONFIG_MIPS)
68#ifdef CONFIG_CPU_MIPS64
69
70
71
72
73
74
75
76#define EXPORT_FUNC(f, a, x, ...) \
77 asm volatile ( \
78" .globl " #x "\n" \
79#x ":\n" \
80" ld $25, %0($26)\n" \
81" ld $25, %1($25)\n" \
82" jr $25\n" \
83 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
84#else
85
86
87
88
89
90
91
92#define EXPORT_FUNC(f, a, x, ...) \
93 asm volatile ( \
94" .globl " #x "\n" \
95#x ":\n" \
96" lw $25, %0($26)\n" \
97" lw $25, %1($25)\n" \
98" jr $25\n" \
99 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9");
100#endif
101#elif defined(CONFIG_NIOS2)
102
103
104
105#define EXPORT_FUNC(f, a, x, ...) \
106 asm volatile ( \
107" .globl " #x "\n" \
108#x ":\n" \
109" movhi r8, %%hi(%0)\n" \
110" ori r8, r0, %%lo(%0)\n" \
111" add r8, r8, gp\n" \
112" ldw r8, 0(r8)\n" \
113" ldw r8, %1(r8)\n" \
114" jmp r8\n" \
115 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp");
116#elif defined(CONFIG_M68K)
117
118
119
120
121#define EXPORT_FUNC(f, a, x, ...) \
122 asm volatile ( \
123" .globl " #x "\n" \
124#x ":\n" \
125" move.l %%d7, %%a0\n" \
126" adda.l %0, %%a0\n" \
127" move.l (%%a0), %%a0\n" \
128" adda.l %1, %%a0\n" \
129" move.l (%%a0), %%a0\n" \
130" jmp (%%a0)\n" \
131 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0");
132#elif defined(CONFIG_MICROBLAZE)
133
134
135
136#define EXPORT_FUNC(f, a, x, ...) \
137 asm volatile ( \
138" .globl " #x "\n" \
139#x ":\n" \
140" lwi r5, r31, %0\n" \
141" lwi r5, r5, %1\n" \
142" bra r5\n" \
143 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5");
144#elif defined(CONFIG_SH)
145
146
147
148#define EXPORT_FUNC(f, a, x, ...) \
149 asm volatile ( \
150 " .align 2\n" \
151 " .globl " #x "\n" \
152 #x ":\n" \
153 " mov r13, r1\n" \
154 " add %0, r1\n" \
155 " mov.l @r1, r2\n" \
156 " add %1, r2\n" \
157 " mov.l @r2, r1\n" \
158 " jmp @r1\n" \
159 " nop\n" \
160 " nop\n" \
161 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2");
162#elif defined(CONFIG_NDS32)
163
164
165
166
167#define EXPORT_FUNC(f, a, x, ...) \
168 asm volatile ( \
169" .globl " #x "\n" \
170#x ":\n" \
171" lwi $r16, [$gp + (%0)]\n" \
172" lwi $r16, [$r16 + (%1)]\n" \
173" jr $r16\n" \
174 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "$r16");
175#elif defined(CONFIG_ARC)
176
177
178
179#define EXPORT_FUNC(f, a, x, ...) \
180 asm volatile( \
181" .align 4\n" \
182" .globl " #x "\n" \
183#x ":\n" \
184" ld r10, [r25, %0]\n" \
185" ld r10, [r10, %1]\n" \
186" j [r10]\n" \
187 : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10");
188#elif defined(CONFIG_XTENSA)
189
190
191
192
193
194
195static void **jt;
196
197#if defined(__XTENSA_CALL0_ABI__)
198#define EXPORT_FUNC(f, a, x, ...) \
199 asm volatile ( \
200" .extern jt\n" \
201" .globl " #x "\n" \
202" .align 4\n" \
203#x ":\n" \
204" l32i a8, %0, 0\n" \
205" l32i a8, a8, %1\n" \
206" jx a8\n" \
207 : : "r"(jt), "i" (FO(x)) : "a8");
208#elif defined(__XTENSA_WINDOWED_ABI__)
209#if XCHAL_HAVE_BE
210# define SFT "8"
211#else
212# define SFT "12"
213#endif
214#define EXPORT_FUNC(f, a, x, ...) \
215 asm volatile ( \
216" .extern jt\n" \
217" .globl " #x "\n" \
218" .align 4\n" \
219#x ":\n" \
220" entry sp, 16\n" \
221" l32i a8, %0, 0\n" \
222" l32i a8, a8, %1\n" \
223" l32i a9, a8, 0\n" \
224" extui a9, a9, " SFT ", 12\n" \
225" subx8 a9, a9, sp\n" \
226" movi a10, 16\n" \
227" sub a9, a10, a9\n" \
228" movsp sp, a9\n" \
229" addi a8, a8, 3\n" \
230" jx a8\n" \
231 : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10");
232#else
233#error Unsupported Xtensa ABI
234#endif
235#else
236
237
238
239#error stubs definition missing for this architecture
240#endif
241
242
243
244
245
246
247
248
249#if GCC_VERSION < 30400
250static
251#endif
252void __attribute__((unused)) dummy(void)
253{
254#include <_exports.h>
255}
256
257#include <asm/sections.h>
258
259void app_startup(char * const *argv)
260{
261 char *cp = __bss_start;
262
263
264 while (cp < _end)
265 *cp++ = 0;
266
267#if defined(CONFIG_X86)
268
269 global_data = (gd_t *)argv[-1];
270 jt = global_data->jt;
271#endif
272}
273
274#undef EXPORT_FUNC
275