stubs.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #include <common.h>
  2. #include <exports.h>
  3. #ifndef GCC_VERSION
  4. #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  5. #endif /* GCC_VERSION */
  6. #if defined(CONFIG_X86)
  7. /*
  8. * x86 does not have a dedicated register to store the pointer to
  9. * the global_data. Thus the jump table address is stored in a
  10. * global variable, but such approach does not allow for execution
  11. * from flash memory. The global_data address is passed as argv[-1]
  12. * to the application program.
  13. */
  14. static void **jt;
  15. gd_t *global_data;
  16. #define EXPORT_FUNC(x) \
  17. asm volatile ( \
  18. " .globl " #x "\n" \
  19. #x ":\n" \
  20. " movl %0, %%eax\n" \
  21. " movl jt, %%ecx\n" \
  22. " jmp *(%%ecx, %%eax)\n" \
  23. : : "i"(XF_ ## x * sizeof(void *)) : "eax", "ecx");
  24. #elif defined(CONFIG_PPC)
  25. /*
  26. * r2 holds the pointer to the global_data, r11 is a call-clobbered
  27. * register
  28. */
  29. #define EXPORT_FUNC(x) \
  30. asm volatile ( \
  31. " .globl " #x "\n" \
  32. #x ":\n" \
  33. " lwz %%r11, %0(%%r2)\n" \
  34. " lwz %%r11, %1(%%r11)\n" \
  35. " mtctr %%r11\n" \
  36. " bctr\n" \
  37. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r11");
  38. #elif defined(CONFIG_ARM)
  39. #ifdef CONFIG_ARM64
  40. /*
  41. * x18 holds the pointer to the global_data, x9 is a call-clobbered
  42. * register
  43. */
  44. #define EXPORT_FUNC(x) \
  45. asm volatile ( \
  46. " .globl " #x "\n" \
  47. #x ":\n" \
  48. " ldr x9, [x18, %0]\n" \
  49. " ldr x9, [x9, %1]\n" \
  50. " br x9\n" \
  51. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "x9");
  52. #else
  53. /*
  54. * r9 holds the pointer to the global_data, ip is a call-clobbered
  55. * register
  56. */
  57. #define EXPORT_FUNC(x) \
  58. asm volatile ( \
  59. " .globl " #x "\n" \
  60. #x ":\n" \
  61. " ldr ip, [r9, %0]\n" \
  62. " ldr pc, [ip, %1]\n" \
  63. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "ip");
  64. #endif
  65. #elif defined(CONFIG_MIPS)
  66. /*
  67. * k0 ($26) holds the pointer to the global_data; t9 ($25) is a call-
  68. * clobbered register that is also used to set gp ($26). Note that the
  69. * jr instruction also executes the instruction immediately following
  70. * it; however, GCC/mips generates an additional `nop' after each asm
  71. * statement
  72. */
  73. #define EXPORT_FUNC(x) \
  74. asm volatile ( \
  75. " .globl " #x "\n" \
  76. #x ":\n" \
  77. " lw $25, %0($26)\n" \
  78. " lw $25, %1($25)\n" \
  79. " jr $25\n" \
  80. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "t9");
  81. #elif defined(CONFIG_NIOS2)
  82. /*
  83. * gp holds the pointer to the global_data, r8 is call-clobbered
  84. */
  85. #define EXPORT_FUNC(x) \
  86. asm volatile ( \
  87. " .globl " #x "\n" \
  88. #x ":\n" \
  89. " movhi r8, %%hi(%0)\n" \
  90. " ori r8, r0, %%lo(%0)\n" \
  91. " add r8, r8, gp\n" \
  92. " ldw r8, 0(r8)\n" \
  93. " ldw r8, %1(r8)\n" \
  94. " jmp r8\n" \
  95. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "gp");
  96. #elif defined(CONFIG_M68K)
  97. /*
  98. * d7 holds the pointer to the global_data, a0 is a call-clobbered
  99. * register
  100. */
  101. #define EXPORT_FUNC(x) \
  102. asm volatile ( \
  103. " .globl " #x "\n" \
  104. #x ":\n" \
  105. " move.l %%d7, %%a0\n" \
  106. " adda.l %0, %%a0\n" \
  107. " move.l (%%a0), %%a0\n" \
  108. " adda.l %1, %%a0\n" \
  109. " move.l (%%a0), %%a0\n" \
  110. " jmp (%%a0)\n" \
  111. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
  112. #elif defined(CONFIG_MICROBLAZE)
  113. /*
  114. * r31 holds the pointer to the global_data. r5 is a call-clobbered.
  115. */
  116. #define EXPORT_FUNC(x) \
  117. asm volatile ( \
  118. " .globl " #x "\n" \
  119. #x ":\n" \
  120. " lwi r5, r31, %0\n" \
  121. " lwi r5, r5, %1\n" \
  122. " bra r5\n" \
  123. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5");
  124. #elif defined(CONFIG_BLACKFIN)
  125. /*
  126. * P3 holds the pointer to the global_data, P0 is a call-clobbered
  127. * register
  128. */
  129. #define EXPORT_FUNC(x) \
  130. asm volatile ( \
  131. " .globl _" #x "\n_" \
  132. #x ":\n" \
  133. " P0 = [P3 + %0]\n" \
  134. " P0 = [P0 + %1]\n" \
  135. " JUMP (P0)\n" \
  136. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "P0");
  137. #elif defined(CONFIG_AVR32)
  138. /*
  139. * r6 holds the pointer to the global_data. r8 is call clobbered.
  140. */
  141. #define EXPORT_FUNC(x) \
  142. asm volatile( \
  143. " .globl\t" #x "\n" \
  144. #x ":\n" \
  145. " ld.w r8, r6[%0]\n" \
  146. " ld.w pc, r8[%1]\n" \
  147. : \
  148. : "i"(offsetof(gd_t, jt)), "i"(XF_ ##x) \
  149. : "r8");
  150. #elif defined(CONFIG_SH)
  151. /*
  152. * r13 holds the pointer to the global_data. r1 is a call clobbered.
  153. */
  154. #define EXPORT_FUNC(x) \
  155. asm volatile ( \
  156. " .align 2\n" \
  157. " .globl " #x "\n" \
  158. #x ":\n" \
  159. " mov r13, r1\n" \
  160. " add %0, r1\n" \
  161. " mov.l @r1, r2\n" \
  162. " add %1, r2\n" \
  163. " mov.l @r2, r1\n" \
  164. " jmp @r1\n" \
  165. " nop\n" \
  166. " nop\n" \
  167. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r1", "r2");
  168. #elif defined(CONFIG_SPARC)
  169. /*
  170. * g7 holds the pointer to the global_data. g1 is call clobbered.
  171. */
  172. #define EXPORT_FUNC(x) \
  173. asm volatile( \
  174. " .globl\t" #x "\n" \
  175. #x ":\n" \
  176. " set %0, %%g1\n" \
  177. " or %%g1, %%g7, %%g1\n" \
  178. " ld [%%g1], %%g1\n" \
  179. " ld [%%g1 + %1], %%g1\n" \
  180. " jmp %%g1\n" \
  181. " nop\n" \
  182. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "g1" );
  183. #elif defined(CONFIG_NDS32)
  184. /*
  185. * r16 holds the pointer to the global_data. gp is call clobbered.
  186. * not support reduced register (16 GPR).
  187. */
  188. #define EXPORT_FUNC(x) \
  189. asm volatile ( \
  190. " .globl " #x "\n" \
  191. #x ":\n" \
  192. " lwi $r16, [$gp + (%0)]\n" \
  193. " lwi $r16, [$r16 + (%1)]\n" \
  194. " jr $r16\n" \
  195. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "$r16");
  196. #elif defined(CONFIG_OPENRISC)
  197. /*
  198. * r10 holds the pointer to the global_data, r13 is a call-clobbered
  199. * register
  200. */
  201. #define EXPORT_FUNC(x) \
  202. asm volatile ( \
  203. " .globl " #x "\n" \
  204. #x ":\n" \
  205. " l.lwz r13, %0(r10)\n" \
  206. " l.lwz r13, %1(r13)\n" \
  207. " l.jr r13\n" \
  208. " l.nop\n" \
  209. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r13");
  210. #elif defined(CONFIG_ARC)
  211. /*
  212. * r25 holds the pointer to the global_data. r10 is call clobbered.
  213. */
  214. #define EXPORT_FUNC(x) \
  215. asm volatile( \
  216. " .align 4\n" \
  217. " .globl " #x "\n" \
  218. #x ":\n" \
  219. " ld r10, [r25, %0]\n" \
  220. " ld r10, [r10, %1]\n" \
  221. " j [r10]\n" \
  222. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r10");
  223. #else
  224. /*" addi $sp, $sp, -24\n" \
  225. " br $r16\n" \*/
  226. #error stubs definition missing for this architecture
  227. #endif
  228. /* This function is necessary to prevent the compiler from
  229. * generating prologue/epilogue, preparing stack frame etc.
  230. * The stub functions are special, they do not use the stack
  231. * frame passed to them, but pass it intact to the actual
  232. * implementation. On the other hand, asm() statements with
  233. * arguments can be used only inside the functions (gcc limitation)
  234. */
  235. #if GCC_VERSION < 3004
  236. static
  237. #endif /* GCC_VERSION */
  238. void __attribute__((unused)) dummy(void)
  239. {
  240. #include <_exports.h>
  241. }
  242. #include <asm/sections.h>
  243. void app_startup(char * const *argv)
  244. {
  245. char *cp = __bss_start;
  246. /* Zero out BSS */
  247. while (cp < _end)
  248. *cp++ = 0;
  249. #if defined(CONFIG_X86)
  250. /* x86 does not have a dedicated register for passing global_data */
  251. global_data = (gd_t *)argv[-1];
  252. jt = global_data->jt;
  253. #endif
  254. }
  255. #undef EXPORT_FUNC