stubs.c 6.6 KB

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