stubs.c 7.1 KB

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