dl-startup.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Architecture specific code used by dl-startup.c
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <features.h>
  9. #if !defined(__thumb__)
  10. __asm__(
  11. " .text\n"
  12. " .globl _start\n"
  13. " .type _start,%function\n"
  14. "_start:\n"
  15. " @ at start time, all the args are on the stack\n"
  16. " mov r0, sp\n"
  17. " bl _dl_start\n"
  18. " @ returns user entry point in r0\n"
  19. " mov r6, r0\n"
  20. " @ we are PIC code, so get global offset table\n"
  21. " ldr sl, .L_GET_GOT\n"
  22. " add sl, pc, sl\n"
  23. ".L_GOT_GOT:\n"
  24. " @ See if we were run as a command with the executable file\n"
  25. " @ name as an extra leading argument.\n"
  26. " ldr r4, .L_SKIP_ARGS\n"
  27. " ldr r4, [sl, r4]\n"
  28. " @ get the original arg count\n"
  29. " ldr r1, [sp]\n"
  30. " @ subtract _dl_skip_args from it\n"
  31. " sub r1, r1, r4\n"
  32. " @ adjust the stack pointer to skip them\n"
  33. " add sp, sp, r4, lsl #2\n"
  34. " @ get the argv address\n"
  35. " add r2, sp, #4\n"
  36. " @ store the new argc in the new stack location\n"
  37. " str r1, [sp]\n"
  38. " @ compute envp\n"
  39. " add r3, r2, r1, lsl #2\n"
  40. " add r3, r3, #4\n"
  41. "\n\n"
  42. " @ load the finalizer function\n"
  43. " ldr r0, .L_FINI_PROC\n"
  44. " ldr r0, [sl, r0]\n"
  45. " @ jump to the user_s entry point\n"
  46. #if defined(__USE_BX__)
  47. " bx r6\n"
  48. #else
  49. " mov pc, r6\n"
  50. #endif
  51. ".L_GET_GOT:\n"
  52. " .word _GLOBAL_OFFSET_TABLE_ - .L_GOT_GOT - 4\n"
  53. ".L_SKIP_ARGS:\n"
  54. " .word _dl_skip_args(GOTOFF)\n"
  55. ".L_FINI_PROC:\n"
  56. " .word _dl_fini(GOT)\n"
  57. "\n\n"
  58. " .size _start,.-_start\n"
  59. ".previous\n"
  60. );
  61. #else
  62. __asm__(
  63. " .text\n"
  64. " .arm\n"
  65. " .globl _start\n"
  66. " .type _start,%function\n"
  67. "_start:\n"
  68. " @ dumb: can't persuade the linker to make the start address\n"
  69. " @ odd, so use an arm function and change to thumb (_dl_start\n"
  70. " @ is thumb)\n"
  71. " adr r0, __dl_thumb_start+1\n"
  72. " bx r0\n"
  73. "\n\n"
  74. " .thumb\n"
  75. " .globl __dl_thumb_start\n"
  76. " .thumb_func\n"
  77. " .type __dl_thumb_start,%function\n"
  78. "__dl_thumb_start:\n"
  79. " @ at start time, all the args are on the stack\n"
  80. " mov r0, sp\n"
  81. " bl _dl_start\n"
  82. " @ returns user entry point in r0\n"
  83. " mov r6, r0\n"
  84. " @ we are PIC code, so get global offset table\n"
  85. " ldr r7, .L_GET_GOT\n"
  86. ".L_GOT_GOT:\n"
  87. " add r7, pc\n"
  88. " @ See if we were run as a command with the executable file\n"
  89. " @ name as an extra leading argument.\n"
  90. " ldr r4, .L_SKIP_ARGS\n"
  91. " ldr r4, [r7, r4]\n"
  92. " @ get the original arg count\n"
  93. " ldr r1, [sp]\n"
  94. " @ subtract _dl_skip_args from it\n"
  95. " sub r1, r1, r4\n"
  96. " @ adjust the stack pointer to skip them\n"
  97. " lsl r4, r4, #2\n"
  98. " add sp, r4\n"
  99. " @ get the argv address\n"
  100. " add r2, sp, #4\n"
  101. " @ store the new argc in the new stack location\n"
  102. " str r1, [sp]\n"
  103. " @ compute envp\n"
  104. " lsl r3, r1, #2\n"
  105. " add r3, r3, r2\n"
  106. " add r3, #4\n"
  107. "\n\n"
  108. " @ load the finalizer function\n"
  109. " ldr r0, .L_FINI_PROC\n"
  110. " ldr r0, [r7, r0]\n"
  111. " @ jump to the user_s entry point\n"
  112. #if defined(__USE_BX__)
  113. " bx r6\n"
  114. #else
  115. " mov pc, r6\n"
  116. #endif
  117. "\n\n"
  118. ".L_GET_GOT:\n"
  119. " .word _GLOBAL_OFFSET_TABLE_ - .L_GOT_GOT - 4\n"
  120. ".L_SKIP_ARGS:\n"
  121. " .word _dl_skip_args(GOTOFF)\n"
  122. ".L_FINI_PROC:\n"
  123. " .word _dl_fini(GOT)\n"
  124. "\n\n"
  125. " .size _start,.-_start\n"
  126. ".previous\n"
  127. );
  128. #endif
  129. /* Get a pointer to the argv array. On many platforms this can be just
  130. * the address if the first argument, on other platforms we need to
  131. * do something a little more subtle here. */
  132. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*)ARGS)+1)
  133. /* Handle relocation of the symbols in the dynamic loader. */
  134. static inline
  135. void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr,
  136. unsigned long symbol_addr, unsigned long load_addr, Elf32_Sym *symtab)
  137. {
  138. switch (ELF32_R_TYPE(rpnt->r_info)) {
  139. case R_ARM_NONE:
  140. break;
  141. case R_ARM_ABS32:
  142. *reloc_addr += symbol_addr;
  143. break;
  144. case R_ARM_PC24:
  145. {
  146. unsigned long addend;
  147. long newvalue, topbits;
  148. addend = *reloc_addr & 0x00ffffff;
  149. if (addend & 0x00800000) addend |= 0xff000000;
  150. newvalue = symbol_addr - (unsigned long)reloc_addr + (addend << 2);
  151. topbits = newvalue & 0xfe000000;
  152. if (topbits != 0xfe000000 && topbits != 0x00000000)
  153. {
  154. #if 0
  155. /* Don't bother with this during ldso initilization... */
  156. newvalue = fix_bad_pc24(reloc_addr, symbol_addr)
  157. - (unsigned long)reloc_addr + (addend << 2);
  158. topbits = newvalue & 0xfe000000;
  159. if (unlikely(topbits != 0xfe000000 && topbits != 0x00000000))
  160. {
  161. SEND_STDERR("R_ARM_PC24 relocation out of range\n");
  162. _dl_exit(1);
  163. }
  164. #else
  165. SEND_STDERR("R_ARM_PC24 relocation out of range\n");
  166. _dl_exit(1);
  167. #endif
  168. }
  169. newvalue >>= 2;
  170. symbol_addr = (*reloc_addr & 0xff000000) | (newvalue & 0x00ffffff);
  171. *reloc_addr = symbol_addr;
  172. break;
  173. }
  174. case R_ARM_GLOB_DAT:
  175. case R_ARM_JUMP_SLOT:
  176. *reloc_addr = symbol_addr;
  177. break;
  178. case R_ARM_RELATIVE:
  179. *reloc_addr += load_addr;
  180. break;
  181. case R_ARM_COPY:
  182. break;
  183. default:
  184. SEND_STDERR("Unsupported relocation type\n");
  185. _dl_exit(1);
  186. }
  187. }