stubs.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. * r2 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(%%r2)\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_NIOS2)
  66. /*
  67. * gp holds the pointer to the global_data, r8 is call-clobbered
  68. */
  69. #define EXPORT_FUNC(x) \
  70. asm volatile ( \
  71. " .globl " #x "\n" \
  72. #x ":\n" \
  73. " movhi r8, %%hi(%0)\n" \
  74. " ori r8, r0, %%lo(%0)\n" \
  75. " add r8, r8, gp\n" \
  76. " ldw r8, 0(r8)\n" \
  77. " ldw r8, %1(r8)\n" \
  78. " jmp r8\n" \
  79. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "gp");
  80. #elif defined(CONFIG_M68K)
  81. /*
  82. * d7 holds the pointer to the global_data, a0 is a call-clobbered
  83. * register
  84. */
  85. #define EXPORT_FUNC(x) \
  86. asm volatile ( \
  87. " .globl " #x "\n" \
  88. #x ":\n" \
  89. " move.l %%d7, %%a0\n" \
  90. " adda.l %0, %%a0\n" \
  91. " move.l (%%a0), %%a0\n" \
  92. " adda.l %1, %%a0\n" \
  93. " move.l (%%a0), %%a0\n" \
  94. " jmp (%%a0)\n" \
  95. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "a0");
  96. #elif defined(CONFIG_MICROBLAZE)
  97. /*
  98. * r31 holds the pointer to the global_data. r5 is a call-clobbered.
  99. */
  100. #define EXPORT_FUNC(x) \
  101. asm volatile ( \
  102. " .globl " #x "\n" \
  103. #x ":\n" \
  104. " lwi r5, r31, %0\n" \
  105. " lwi r5, r5, %1\n" \
  106. " bra r5\n" \
  107. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r5");
  108. #elif defined(CONFIG_BLACKFIN)
  109. /*
  110. * P3 holds the pointer to the global_data, P0 is a call-clobbered
  111. * register
  112. */
  113. #define EXPORT_FUNC(x) \
  114. asm volatile ( \
  115. " .globl _" #x "\n_" \
  116. #x ":\n" \
  117. " P0 = [P3 + %0]\n" \
  118. " P0 = [P0 + %1]\n" \
  119. " JUMP (P0)\n" \
  120. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "P0");
  121. #elif defined(CONFIG_AVR32)
  122. /*
  123. * r6 holds the pointer to the global_data. r8 is call clobbered.
  124. */
  125. #define EXPORT_FUNC(x) \
  126. asm volatile( \
  127. " .globl\t" #x "\n" \
  128. #x ":\n" \
  129. " ld.w r8, r6[%0]\n" \
  130. " ld.w pc, r8[%1]\n" \
  131. : \
  132. : "i"(offsetof(gd_t, jt)), "i"(XF_ ##x) \
  133. : "r8");
  134. #elif defined(CONFIG_SH)
  135. /*
  136. * r13 holds the pointer to the global_data. r1 is a call clobbered.
  137. */
  138. #define EXPORT_FUNC(x) \
  139. asm volatile ( \
  140. " .align 2\n" \
  141. " .globl " #x "\n" \
  142. #x ":\n" \
  143. " mov r13, r1\n" \
  144. " add %0, r1\n" \
  145. " mov.l @r1, r2\n" \
  146. " add %1, r2\n" \
  147. " mov.l @r2, r1\n" \
  148. " jmp @r1\n" \
  149. " nop\n" \
  150. " nop\n" \
  151. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "r1", "r2");
  152. #elif defined(CONFIG_SPARC)
  153. /*
  154. * g7 holds the pointer to the global_data. g1 is call clobbered.
  155. */
  156. #define EXPORT_FUNC(x) \
  157. asm volatile( \
  158. " .globl\t" #x "\n" \
  159. #x ":\n" \
  160. " set %0, %%g1\n" \
  161. " or %%g1, %%g7, %%g1\n" \
  162. " ld [%%g1], %%g1\n" \
  163. " ld [%%g1 + %1], %%g1\n" \
  164. " jmp %%g1\n" \
  165. " nop\n" \
  166. : : "i"(offsetof(gd_t, jt)), "i"(XF_ ## x * sizeof(void *)) : "g1" );
  167. #else
  168. #error stubs definition missing for this architecture
  169. #endif
  170. /* This function is necessary to prevent the compiler from
  171. * generating prologue/epilogue, preparing stack frame etc.
  172. * The stub functions are special, they do not use the stack
  173. * frame passed to them, but pass it intact to the actual
  174. * implementation. On the other hand, asm() statements with
  175. * arguments can be used only inside the functions (gcc limitation)
  176. */
  177. #if GCC_VERSION < 3004
  178. static
  179. #endif /* GCC_VERSION */
  180. void __attribute__((unused)) dummy(void)
  181. {
  182. #include <_exports.h>
  183. }
  184. extern unsigned long __bss_start, _end;
  185. void app_startup(char * const *argv)
  186. {
  187. unsigned char * cp = (unsigned char *) &__bss_start;
  188. /* Zero out BSS */
  189. while (cp < (unsigned char *)&_end) {
  190. *cp++ = 0;
  191. }
  192. #if defined(CONFIG_I386)
  193. /* x86 does not have a dedicated register for passing global_data */
  194. global_data = (gd_t *)argv[-1];
  195. jt = global_data->jt;
  196. #endif
  197. }
  198. #undef EXPORT_FUNC