wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 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 | */ |
| 11 | static void **jt; |
wdenk | 7784674 | 2003-07-26 08:08:08 +0000 | [diff] [blame] | 12 | gd_t *global_data; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 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"); |
wdenk | 4a55170 | 2003-10-08 23:26:14 +0000 | [diff] [blame] | 64 | #elif defined(CONFIG_NIOS) |
| 65 | /* |
| 66 | * %g7 holds the pointer to the global_data. %g0 is call clobbered. |
| 67 | */ |
| 68 | #define EXPORT_FUNC(x) \ |
| 69 | asm volatile ( \ |
| 70 | " .globl " #x "\n" \ |
| 71 | #x ":\n" \ |
| 72 | " pfx %%hi(%0)\n" \ |
| 73 | " movi %%g0, %%lo(%0)\n" \ |
| 74 | " add %%g0, %%g7\n" \ |
| 75 | " ld %%g0, [%%g0]\n" \ |
| 76 | " pfx %1\n" \ |
| 77 | " ld %%g0, [%%g0]\n" \ |
| 78 | " jmp %%g0\n" \ |
| 79 | " nop \n" \ |
| 80 | : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x) : "r0"); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 81 | #else |
| 82 | #error stubs definition missing for this architecture |
| 83 | #endif |
| 84 | |
| 85 | /* This function is necessary to prevent the compiler from |
| 86 | * generating prologue/epilogue, preparing stack frame etc. |
| 87 | * The stub functions are special, they do not use the stack |
| 88 | * frame passed to them, but pass it intact to the actual |
| 89 | * implementation. On the other hand, asm() statements with |
| 90 | * arguments can be used only inside the functions (gcc limitation) |
| 91 | */ |
| 92 | static void __attribute__((unused)) dummy(void) |
| 93 | { |
| 94 | #include <_exports.h> |
| 95 | } |
| 96 | |
| 97 | void app_startup(char **argv) |
| 98 | { |
| 99 | #if defined(CONFIG_I386) |
| 100 | /* x86 does not have a dedicated register for passing global_data */ |
wdenk | 7784674 | 2003-07-26 08:08:08 +0000 | [diff] [blame] | 101 | global_data = (gd_t *)argv[-1]; |
| 102 | jt = global_data->jt; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 103 | #endif |
| 104 | } |
| 105 | |
| 106 | #undef EXPORT_FUNC |