stubs.c 6.7 KB

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