stubs.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include <exports.h>
  2. #if defined(CONFIG_I386)
  3. /*
  4. * x86 does not have a dedicated register to store the pointer to
  5. * the global_data. Thus the jump table address is stored in a
  6. * global variable, but such approach does not allow for execution
  7. * from flash memory. The global_data address is passed as argv[-1]
  8. * to the application program.
  9. */
  10. static void **jt;
  11. gd_t *global_data;
  12. #define EXPORT_FUNC(x) \
  13. asm volatile ( \
  14. " .globl " #x "\n" \
  15. #x ":\n" \
  16. " movl %0, %%eax\n" \
  17. " movl jt, %%ecx\n" \
  18. " jmp *(%%ecx, %%eax)\n" \
  19. : : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx");
  20. #elif defined(CONFIG_PPC)
  21. /*
  22. * r29 holds the pointer to the global_data, r11 is a call-clobbered
  23. * register
  24. */
  25. #define EXPORT_FUNC(x) \
  26. asm volatile ( \
  27. " .globl " #x "\n" \
  28. #x ":\n" \
  29. " lwz %%r11, %0(%%r29)\n" \
  30. " lwz %%r11, %1(%%r11)\n" \
  31. " mtctr %%r11\n" \
  32. " bctr\n" \
  33. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
  34. #elif defined(CONFIG_ARM)
  35. /*
  36. * r8 holds the pointer to the global_data, ip is a call-clobbered
  37. * register
  38. */
  39. #define EXPORT_FUNC(x) \
  40. asm volatile ( \
  41. " .globl " #x "\n" \
  42. #x ":\n" \
  43. " ldr ip, [r8, %0]\n" \
  44. " ldr pc, [ip, %1]\n" \
  45. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
  46. #elif defined(CONFIG_MIPS)
  47. /*
  48. * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
  49. * clobbered register that is also used to set gp ($26). Note that the
  50. * jr instruction also executes the instruction immediately following
  51. * it; however, GCC/mips generates an additional `nop' after each asm
  52. * statement
  53. */
  54. #define EXPORT_FUNC(x) \
  55. asm volatile ( \
  56. " .globl " #x "\n" \
  57. #x ":\n" \
  58. " lw $25, %0($26)\n" \
  59. " lw $25, %1($25)\n" \
  60. " jr $25\n" \
  61. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9");
  62. #else
  63. #error stubs definition missing for this architecture
  64. #endif
  65. /* This function is necessary to prevent the compiler from
  66. * generating prologue/epilogue, preparing stack frame etc.
  67. * The stub functions are special, they do not use the stack
  68. * frame passed to them, but pass it intact to the actual
  69. * implementation. On the other hand, asm() statements with
  70. * arguments can be used only inside the functions (gcc limitation)
  71. */
  72. static void __attribute__((unused)) dummy(void)
  73. {
  74. #include <_exports.h>
  75. }
  76. void app_startup(char **argv)
  77. {
  78. #if defined(CONFIG_I386)
  79. /* x86 does not have a dedicated register for passing global_data */
  80. global_data = (gd_t *)argv[-1];
  81. jt = global_data->jt;
  82. #endif
  83. }
  84. #undef EXPORT_FUNC