dl-startup.h 5.1 KB

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