stubs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #elif defined(CONFIG_M68K)
  80. /*
  81. * d7 holds the pointer to the global_data, a0 is a call-clobbered
  82. * register
  83. */
  84. #define EXPORT_FUNC(x) \
  85. asm volatile ( \
  86. " .globl " #x "\n" \
  87. #x ":\n" \
  88. " move.l %%d7, %%a0\n" \
  89. " adda.l %0, %%a0\n" \
  90. " move.l (%%a0), %%a0\n" \
  91. " adda.l %1, %%a0\n" \
  92. " move.l (%%a0), %%a0\n" \
  93. " jmp (%%a0)\n" \
  94. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
  95. #else
  96. #error stubs definition missing for this architecture
  97. #endif
  98. /* This function is necessary to prevent the compiler from
  99. * generating prologue/epilogue, preparing stack frame etc.
  100. * The stub functions are special, they do not use the stack
  101. * frame passed to them, but pass it intact to the actual
  102. * implementation. On the other hand, asm() statements with
  103. * arguments can be used only inside the functions (gcc limitation)
  104. */
  105. static void __attribute__((unused)) dummy(void)
  106. {
  107. #include <_exports.h>
  108. }
  109. extern unsigned long __bss_start, _end;
  110. void app_startup(char **argv)
  111. {
  112. unsigned long * cp = &__bss_start;
  113. /* Zero out BSS */
  114. while (cp < &_end) {
  115. *cp++ = 0;
  116. }
  117. #if defined(CONFIG_I386)
  118. /* x86 does not have a dedicated register for passing global_data */
  119. global_data = (gd_t *)argv[-1];
  120. jt = global_data->jt;
  121. #endif
  122. }
  123. #undef EXPORT_FUNC