dl-startup.h 5.1 KB

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