stubs.c 2.4 KB

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