dl-startup.h 5.0 KB

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