dl-startup.h 4.9 KB

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