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