]> git.ipfire.org Git - people/ms/u-boot.git/blame - examples/stubs.c
* Allow crc32 to be used at address 0x000
[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");
64#else
65#error stubs definition missing for this architecture
66#endif
67
68/* This function is necessary to prevent the compiler from
69 * generating prologue/epilogue, preparing stack frame etc.
70 * The stub functions are special, they do not use the stack
71 * frame passed to them, but pass it intact to the actual
72 * implementation. On the other hand, asm() statements with
73 * arguments can be used only inside the functions (gcc limitation)
74 */
75static void __attribute__((unused)) dummy(void)
76{
77#include <_exports.h>
78}
79
80void app_startup(char **argv)
81{
82#if defined(CONFIG_I386)
83 /* x86 does not have a dedicated register for passing global_data */
77846748
WD
84 global_data = (gd_t *)argv[-1];
85 jt = global_data->jt;
27b207fd
WD
86#endif
87}
88
89#undef EXPORT_FUNC