Blame view
examples/standalone/stubs.c
7.15 KB
d41ce506b Initial Release, ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
#include <common.h> #include <exports.h> #include <linux/compiler.h> #define FO(x) offsetof(struct jt_funcs, x) #if defined(CONFIG_X86) /* * x86 does not have a dedicated register to store the pointer to * the global_data. Thus the jump table address is stored in a * global variable, but such approach does not allow for execution * from flash memory. The global_data address is passed as argv[-1] * to the application program. */ static struct jt_funcs *jt; gd_t *global_data; #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " movl %0, %%eax " \ " movl jt, %%ecx " \ " jmp *(%%ecx, %%eax) " \ : : "i"(FO(x)) : "eax", "ecx"); #elif defined(CONFIG_PPC) /* * r2 holds the pointer to the global_data, r11 is a call-clobbered * register */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " lwz %%r11, %0(%%r2) " \ " lwz %%r11, %1(%%r11) " \ " mtctr %%r11 " \ " bctr " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r11"); #elif defined(CONFIG_ARM) #ifdef CONFIG_ARM64 /* * x18 holds the pointer to the global_data, x9 is a call-clobbered * register */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " ldr x9, [x18, %0] " \ " ldr x9, [x9, %1] " \ " br x9 " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x9"); #else /* * r9 holds the pointer to the global_data, ip is a call-clobbered * register */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " ldr ip, [r9, %0] " \ " ldr pc, [ip, %1] " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "ip"); #endif #elif defined(CONFIG_MIPS) #ifdef CONFIG_CPU_MIPS64 /* * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call- * clobbered register that is also used to set gp ($26). Note that the * jr instruction also executes the instruction immediately following * it; however, GCC/mips generates an additional `nop' after each asm * statement */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " ld $25, %0($26) " \ " ld $25, %1($25) " \ " jr $25 " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9"); #else /* * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call- * clobbered register that is also used to set gp ($26). Note that the * jr instruction also executes the instruction immediately following * it; however, GCC/mips generates an additional `nop' after each asm * statement */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " lw $25, %0($26) " \ " lw $25, %1($25) " \ " jr $25 " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "t9"); #endif #elif defined(CONFIG_NIOS2) /* * gp holds the pointer to the global_data, r8 is call-clobbered */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " movhi r8, %%hi(%0) " \ " ori r8, r0, %%lo(%0) " \ " add r8, r8, gp " \ " ldw r8, 0(r8) " \ " ldw r8, %1(r8) " \ " jmp r8 " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "gp"); #elif defined(CONFIG_M68K) /* * d7 holds the pointer to the global_data, a0 is a call-clobbered * register */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " move.l %%d7, %%a0 " \ " adda.l %0, %%a0 " \ " move.l (%%a0), %%a0 " \ " adda.l %1, %%a0 " \ " move.l (%%a0), %%a0 " \ " jmp (%%a0) " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "a0"); #elif defined(CONFIG_MICROBLAZE) /* * r31 holds the pointer to the global_data. r5 is a call-clobbered. */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " lwi r5, r31, %0 " \ " lwi r5, r5, %1 " \ " bra r5 " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r5"); #elif defined(CONFIG_SH) /* * r13 holds the pointer to the global_data. r1 is a call clobbered. */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .align 2 " \ " .globl " #x " " \ #x ": " \ " mov r13, r1 " \ " add %0, r1 " \ " mov.l @r1, r2 " \ " add %1, r2 " \ " mov.l @r2, r1 " \ " jmp @r1 " \ " nop " \ " nop " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r1", "r2"); #elif defined(CONFIG_NDS32) /* * r16 holds the pointer to the global_data. gp is call clobbered. * not support reduced register (16 GPR). */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " lwi $r16, [$gp + (%0)] " \ " lwi $r16, [$r16 + (%1)] " \ " jr $r16 " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "$r16"); #elif defined(CONFIG_RISCV) /* * t7 holds the pointer to the global_data. gp is call clobbered. */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .globl " #x " " \ #x ": " \ " lw x19, %0(gp) " \ " lw x19, %1(x19) " \ " jr x19 " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "x19"); #elif defined(CONFIG_ARC) /* * r25 holds the pointer to the global_data. r10 is call clobbered. */ #define EXPORT_FUNC(f, a, x, ...) \ asm volatile( \ " .align 4 " \ " .globl " #x " " \ #x ": " \ " ld r10, [r25, %0] " \ " ld r10, [r10, %1] " \ " j [r10] " \ : : "i"(offsetof(gd_t, jt)), "i"(FO(x)) : "r10"); #elif defined(CONFIG_XTENSA) /* * Global data ptr is in global_data, jump table ptr is in jt. * Windowed ABI: Jump just past 'entry' in target and adjust stack frame * (extract stack frame size from target 'entry' instruction). */ static void **jt; #if defined(__XTENSA_CALL0_ABI__) #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .extern jt " \ " .globl " #x " " \ " .align 4 " \ #x ": " \ " l32i a8, %0, 0 " \ " l32i a8, a8, %1 " \ " jx a8 " \ : : "r"(jt), "i" (FO(x)) : "a8"); #elif defined(__XTENSA_WINDOWED_ABI__) #if XCHAL_HAVE_BE # define SFT "8" #else # define SFT "12" #endif #define EXPORT_FUNC(f, a, x, ...) \ asm volatile ( \ " .extern jt " \ " .globl " #x " " \ " .align 4 " \ #x ": " \ " entry sp, 16 " \ " l32i a8, %0, 0 " \ " l32i a8, a8, %1 " \ " l32i a9, a8, 0 " \ " extui a9, a9, " SFT ", 12 " \ " subx8 a9, a9, sp " \ " movi a10, 16 " \ " sub a9, a10, a9 " \ " movsp sp, a9 " \ " addi a8, a8, 3 " \ " jx a8 " \ : : "r"(jt), "i" (FO(x)) : "a8", "a9", "a10"); #else #error Unsupported Xtensa ABI #endif #else /*" addi $sp, $sp, -24 " \ " br $r16 " \*/ #error stubs definition missing for this architecture #endif /* This function is necessary to prevent the compiler from * generating prologue/epilogue, preparing stack frame etc. * The stub functions are special, they do not use the stack * frame passed to them, but pass it intact to the actual * implementation. On the other hand, asm() statements with * arguments can be used only inside the functions (gcc limitation) */ #if GCC_VERSION < 30400 static #endif /* GCC_VERSION */ void __attribute__((unused)) dummy(void) { #include <_exports.h> } #include <asm/sections.h> void app_startup(char * const *argv) { char *cp = __bss_start; /* Zero out BSS */ while (cp < _end) *cp++ = 0; #if defined(CONFIG_X86) /* x86 does not have a dedicated register for passing global_data */ global_data = (gd_t *)argv[-1]; jt = global_data->jt; #endif } #undef EXPORT_FUNC |