stubs.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #include <exports.h>
  2. #ifndef GCC_VERSION
  3. #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  4. #endif /* GCC_VERSION */
  5. #if defined(CONFIG_I386)
  6. /*
  7. * x86 does not have a dedicated register to store the pointer to
  8. * the global_data. Thus the jump table address is stored in a
  9. * global variable, but such approach does not allow for execution
  10. * from flash memory. The global_data address is passed as argv[-1]
  11. * to the application program.
  12. */
  13. static void **jt;
  14. gd_t *global_data;
  15. #define EXPORT_FUNC(x) \
  16. asm volatile ( \
  17. " .globl " #x "\n" \
  18. #x ":\n" \
  19. " movl %0, %%eax\n" \
  20. " movl jt, %%ecx\n" \
  21. " jmp *(%%ecx, %%eax)\n" \
  22. : : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx");
  23. #elif defined(CONFIG_PPC)
  24. /*
  25. * r29 holds the pointer to the global_data, r11 is a call-clobbered
  26. * register
  27. */
  28. #define EXPORT_FUNC(x) \
  29. asm volatile ( \
  30. " .globl " #x "\n" \
  31. #x ":\n" \
  32. " lwz %%r11, %0(%%r29)\n" \
  33. " lwz %%r11, %1(%%r11)\n" \
  34. " mtctr %%r11\n" \
  35. " bctr\n" \
  36. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
  37. #elif defined(CONFIG_ARM)
  38. /*
  39. * r8 holds the pointer to the global_data, ip is a call-clobbered
  40. * register
  41. */
  42. #define EXPORT_FUNC(x) \
  43. asm volatile ( \
  44. " .globl " #x "\n" \
  45. #x ":\n" \
  46. " ldr ip, [r8, %0]\n" \
  47. " ldr pc, [ip, %1]\n" \
  48. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
  49. #elif defined(CONFIG_MIPS)
  50. /*
  51. * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
  52. * clobbered register that is also used to set gp ($26). Note that the
  53. * jr instruction also executes the instruction immediately following
  54. * it; however, GCC/mips generates an additional `nop' after each asm
  55. * statement
  56. */
  57. #define EXPORT_FUNC(x) \
  58. asm volatile ( \
  59. " .globl " #x "\n" \
  60. #x ":\n" \
  61. " lw $25, %0($26)\n" \
  62. " lw $25, %1($25)\n" \
  63. " jr $25\n" \
  64. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9");
  65. #elif defined(CONFIG_NIOS)
  66. /*
  67. * %g7 holds the pointer to the global_data. %g0 is call clobbered.
  68. */
  69. #define EXPORT_FUNC(x) \
  70. asm volatile ( \
  71. " .globl " #x "\n" \
  72. #x ":\n" \
  73. " pfx %%hi(%0)\n" \
  74. " movi %%g0, %%lo(%0)\n" \
  75. " add %%g0, %%g7\n" \
  76. " ld %%g0, [%%g0]\n" \
  77. " pfx %1\n" \
  78. " ld %%g0, [%%g0]\n" \
  79. " jmp %%g0\n" \
  80. " nop \n" \
  81. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x) : "r0");
  82. #elif defined(CONFIG_NIOS2)
  83. /*
  84. * r15 holds the pointer to the global_data, r8 is call-clobbered
  85. */
  86. #define EXPORT_FUNC(x) \
  87. asm volatile ( \
  88. " .globl " #x "\n" \
  89. #x ":\n" \
  90. " movhi r8, %%hi(%0)\n" \
  91. " ori r8, r0, %%lo(%0)\n" \
  92. " add r8, r0, r15\n" \
  93. " ldw r8, 0(r8)\n" \
  94. " ldw r8, %1(r8)\n" \
  95. " jmp r8\n" \
  96. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r15");
  97. #elif defined(CONFIG_M68K)
  98. /*
  99. * d7 holds the pointer to the global_data, a0 is a call-clobbered
  100. * register
  101. */
  102. #define EXPORT_FUNC(x) \
  103. asm volatile ( \
  104. " .globl " #x "\n" \
  105. #x ":\n" \
  106. " move.l %%d7, %%a0\n" \
  107. " adda.l %0, %%a0\n" \
  108. " move.l (%%a0), %%a0\n" \
  109. " adda.l %1, %%a0\n" \
  110. " move.l (%%a0), %%a0\n" \
  111. " jmp (%%a0)\n" \
  112. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
  113. #elif defined(CONFIG_MICROBLAZE)
  114. /*
  115. * r31 holds the pointer to the global_data. r5 is a call-clobbered.
  116. */
  117. #define EXPORT_FUNC(x) \
  118. asm volatile ( \
  119. " .globl " #x "\n" \
  120. #x ":\n" \
  121. " lwi r5, r31, %0\n" \
  122. " lwi r5, r5, %1\n" \
  123. " bra r5\n" \
  124. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5");
  125. #else
  126. #error stubs definition missing for this architecture
  127. #endif
  128. /* This function is necessary to prevent the compiler from
  129. * generating prologue/epilogue, preparing stack frame etc.
  130. * The stub functions are special, they do not use the stack
  131. * frame passed to them, but pass it intact to the actual
  132. * implementation. On the other hand, asm() statements with
  133. * arguments can be used only inside the functions (gcc limitation)
  134. */
  135. #if GCC_VERSION < 3004
  136. static
  137. #endif /* GCC_VERSION */
  138. void __attribute__((unused)) dummy(void)
  139. {
  140. #include <_exports.h>
  141. }
  142. extern unsigned long __bss_start, _end;
  143. void app_startup(char **argv)
  144. {
  145. unsigned long * cp = &__bss_start;
  146. /* Zero out BSS */
  147. while (cp < &_end) {
  148. *cp++ = 0;
  149. }
  150. #if defined(CONFIG_I386)
  151. /* x86 does not have a dedicated register for passing global_data */
  152. global_data = (gd_t *)argv[-1];
  153. jt = global_data->jt;
  154. #endif
  155. }
  156. #undef EXPORT_FUNC