stubs.c 2.9 KB

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