dl-startup.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* Any assembly language/system dependent hacks needed to setup boot1.c so it
  2. * will work as expected and cope with whatever platform specific wierdness is
  3. * needed for this architecture.
  4. * Copyright (C) 2005 by Joakim Tjernlund
  5. * Copyright (C) 2005 by Erik Andersen
  6. */
  7. #include <sgidefs.h>
  8. #ifndef L_rcrt1
  9. __asm__(""
  10. " .text\n"
  11. " .globl _start\n"
  12. " .ent _start\n"
  13. " .type _start,@function\n"
  14. " .hidden _start\n"
  15. "_start:\n"
  16. " .set noreorder\n"
  17. " move $25, $31\n"
  18. " bal 0f\n"
  19. " nop\n"
  20. "0:\n"
  21. #if _MIPS_SIM == _MIPS_SIM_ABI32
  22. " .cpload $31\n"
  23. #else /* N32 || N64 */
  24. " .cpsetup $31, $2, 0b\n"
  25. #endif /* N32 || N64 */
  26. " move $31, $25\n"
  27. " .set reorder\n"
  28. #if _MIPS_SIM == _MIPS_SIM_ABI64
  29. " dla $4, _DYNAMIC\n"
  30. " sd $4, -0x7ff0($28)\n"
  31. #else /* O32 || N32 */
  32. " la $4, _DYNAMIC\n"
  33. " sw $4, -0x7ff0($28)\n"
  34. #endif /* O32 || N32 */
  35. " move $4, $29\n"
  36. #if _MIPS_SIM == _MIPS_SIM_ABI32
  37. " subu $29, 16\n"
  38. #endif
  39. #if _MIPS_SIM == _MIPS_SIM_ABI64
  40. " dla $8, .coff\n"
  41. #else /* O32 || N32 */
  42. " la $8, .coff\n"
  43. #endif /* O32 || N32 */
  44. # if !defined __mips_isa_rev || __mips_isa_rev < 6
  45. " bltzal $8, .coff\n"
  46. ".coff:\n"
  47. # else
  48. ".coff:\n"
  49. " lapc $31, .coff\n"
  50. # endif
  51. #if _MIPS_SIM == _MIPS_SIM_ABI64
  52. " dsubu $8, $31, $8\n"
  53. " dla $25, _dl_start\n"
  54. " daddu $25, $8\n"
  55. #else /* O32 || N32 */
  56. " subu $8, $31, $8\n"
  57. " la $25, _dl_start\n"
  58. " addu $25, $8\n"
  59. #endif /* O32 || N32 */
  60. " jalr $25\n"
  61. #if _MIPS_SIM == _MIPS_SIM_ABI32
  62. " addiu $29, 16\n"
  63. #endif
  64. " move $16, $28\n"
  65. " move $17, $2\n"
  66. #if _MIPS_SIM == _MIPS_SIM_ABI64
  67. " ld $2, _dl_skip_args\n"
  68. " beq $2, $0, 1f\n"
  69. " ld $4, 0($29)\n"
  70. " dsubu $4, $2\n"
  71. " dsll $2, 2\n"
  72. " daddu $29, $2\n"
  73. " sd $4, 0($29)\n"
  74. "1:\n"
  75. " ld $5, 0($29)\n"
  76. " dla $6, 8 ($29)\n"
  77. " dsll $7, $5, 2\n"
  78. " daddu $7, $7, $6\n"
  79. " daddu $7, $7, 4\n"
  80. " and $2, $29, -4 * 4\n"
  81. " sd $29, -8($2)\n"
  82. " dsubu $29, $2, 32\n"
  83. " ld $29, 24($29)\n"
  84. " dla $2, _dl_fini\n"
  85. #else /* O32 || N32 */
  86. " lw $2, _dl_skip_args\n"
  87. " beq $2, $0, 1f\n"
  88. " lw $4, 0($29)\n"
  89. " subu $4, $2\n"
  90. " sll $2, 2\n"
  91. " addu $29, $2\n"
  92. " sw $4, 0($29)\n"
  93. "1:\n"
  94. " lw $5, 0($29)\n"
  95. " la $6, 4 ($29)\n"
  96. " sll $7, $5, 2\n"
  97. " addu $7, $7, $6\n"
  98. " addu $7, $7, 4\n"
  99. " and $2, $29, -2 * 4\n"
  100. " sw $29, -4($2)\n"
  101. " subu $29, $2, 32\n"
  102. #if _MIPS_SIM == _MIPS_SIM_ABI32
  103. " .cprestore 16\n"
  104. #endif
  105. " lw $29, 28($29)\n"
  106. " la $2, _dl_fini\n"
  107. #endif /* O32 || N32 */
  108. " move $25, $17\n"
  109. " jr $25\n"
  110. ".end _start\n"
  111. ".size _start, . -_start\n"
  112. "\n\n"
  113. "\n\n"
  114. ".previous\n"
  115. );
  116. #endif
  117. /*
  118. * Get a pointer to the argv array. On many platforms this can be just
  119. * the address of the first argument, on other platforms we need to
  120. * do something a little more subtle here.
  121. */
  122. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS)+1)
  123. /* We can't call functions earlier in the dl startup process */
  124. #define NO_FUNCS_BEFORE_BOOTSTRAP
  125. /*
  126. * Here is a macro to perform the GOT relocation. This is only
  127. * used when bootstrapping the dynamic loader.
  128. */
  129. #define PERFORM_BOOTSTRAP_GOT(tpnt) \
  130. do { \
  131. ElfW(Sym) *sym; \
  132. ElfW(Addr) i; \
  133. register ElfW(Addr) gp __asm__ ("$28"); \
  134. ElfW(Addr) *mipsgot = elf_mips_got_from_gpreg (gp); \
  135. \
  136. /* Add load address displacement to all local GOT entries */ \
  137. i = 2; \
  138. while (i < tpnt->dynamic_info[DT_MIPS_LOCAL_GOTNO_IDX]) \
  139. mipsgot[i++] += tpnt->loadaddr; \
  140. \
  141. /* Handle global GOT entries */ \
  142. mipsgot += tpnt->dynamic_info[DT_MIPS_LOCAL_GOTNO_IDX]; \
  143. sym = (ElfW(Sym) *) tpnt->dynamic_info[DT_SYMTAB] + \
  144. tpnt->dynamic_info[DT_MIPS_GOTSYM_IDX]; \
  145. i = tpnt->dynamic_info[DT_MIPS_SYMTABNO_IDX] - tpnt->dynamic_info[DT_MIPS_GOTSYM_IDX];\
  146. \
  147. while (i--) { \
  148. if (sym->st_shndx == SHN_UNDEF || \
  149. sym->st_shndx == SHN_COMMON) \
  150. *mipsgot = tpnt->loadaddr + sym->st_value; \
  151. else if (ELF_ST_TYPE(sym->st_info) == STT_FUNC && \
  152. *mipsgot != sym->st_value) \
  153. *mipsgot += tpnt->loadaddr; \
  154. else if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) { \
  155. if (sym->st_other == 0) \
  156. *mipsgot += tpnt->loadaddr; \
  157. } \
  158. else \
  159. *mipsgot = tpnt->loadaddr + sym->st_value; \
  160. \
  161. mipsgot++; \
  162. sym++; \
  163. } \
  164. } while (0)
  165. /*
  166. * Here is a macro to perform a relocation. This is only used when
  167. * bootstrapping the dynamic loader.
  168. */
  169. #if _MIPS_SIM == _MIPS_SIM_ABI64 /* consult with glibc sysdeps/mips/dl-machine.h 1.69 */
  170. #define R_MIPS_BOOTSTRAP_RELOC ((R_MIPS_64 << 8) | R_MIPS_REL32)
  171. #else /* N32 || O32 */
  172. #define R_MIPS_BOOTSTRAP_RELOC R_MIPS_REL32
  173. #endif
  174. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  175. switch(ELF_R_TYPE((RELP)->r_info)) { \
  176. case R_MIPS_BOOTSTRAP_RELOC: \
  177. if (SYMTAB) { \
  178. if (symtab_index<tpnt->dynamic_info[DT_MIPS_GOTSYM_IDX])\
  179. *REL += SYMBOL; \
  180. } \
  181. else { \
  182. *REL += LOAD; \
  183. } \
  184. break; \
  185. case R_MIPS_NONE: \
  186. break; \
  187. default: \
  188. _dl_exit(1); \
  189. }