dl-startup.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Copyright (C) 2003 Red Hat, Inc.
  2. Contributed by Alexandre Oliva <aoliva@redhat.com>
  3. This file is part of uClibc.
  4. uClibc is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. License, or (at your option) any later version.
  8. uClibc is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with uClibc; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  15. USA. */
  16. /* Any assembly language/system dependent hacks needed to setup
  17. * boot1.c so it will work as expected and cope with whatever platform
  18. * specific wierdness is needed for this architecture.
  19. * We override the default _dl_boot function, and replace it with a
  20. * bit of asm. Then call the real _dl_boot function, which is now
  21. * named _dl_boot2. */
  22. /* At program start-up, p0 contains a pointer to a
  23. elf32_fdpic_loadmap that describes how the executable was loaded
  24. into memory. p1 contains a pointer to the interpreter (our!)
  25. loadmap, if there is an interpreter, or 0 if we're being run as an
  26. executable. p2 holds a pointer to the interpreter's dynamic
  27. section, if there is an interpreter, or to the executable's dynamic
  28. section, otherwise. If the executable is not dynamic, gr18 is 0.
  29. We rely on the fact that the linker adds a pointer to the
  30. _GLOBAL_OFFSET_TABLE_ as the last ROFIXUP entry, and that
  31. __self_reloc returns the relocated pointer to us, so that we can
  32. use this value to initialize the PIC register. */
  33. __asm__(
  34. " .text\n" \
  35. " .global __dl_boot\n" \
  36. " .type __dl_boot,@function\n" \
  37. "__dl_boot:\n" \
  38. " call .Lcall\n" \
  39. ".Lcall:\n" \
  40. " R4 = RETS;\n" \
  41. " SP += -32;\n" \
  42. " R5 = P0;\n" \
  43. " R6 = P1;\n" \
  44. " R7 = P2;\n" \
  45. " R0.L = .Lcall;\n" \
  46. " R0.H = .Lcall;\n" \
  47. " R1.L = __ROFIXUP_LIST__;\n" \
  48. " R1.H = __ROFIXUP_LIST__;\n" \
  49. " R2.L = __ROFIXUP_END__;\n" \
  50. " R2.H = __ROFIXUP_END__;\n" \
  51. " R1 = R1 - R0;\n" \
  52. " R1 = R1 + R4;\n" \
  53. " R2 = R2 - R0;\n" \
  54. " R2 = R2 + R4;\n" \
  55. " R0 = P1;\n" \
  56. " CC = R0 == 0;\n" \
  57. " IF CC R0 = P0;\n" \
  58. " CALL ___self_reloc;\n" \
  59. " P3 = R0;\n" \
  60. " P5 = R0;\n" \
  61. " R1 = R5;\n" \
  62. " R2 = R6;\n" \
  63. " [SP + 12] = R7;\n" \
  64. " P0 = SP;\n" \
  65. " P0 += 24;\n" \
  66. " [SP + 16] = P0;\n" \
  67. " P0 += 8;\n" \
  68. " [SP + 20] = P0;\n" \
  69. " CALL __dl_start;\n" \
  70. " /* Pass our FINI ptr() to the user in P1 */\n" \
  71. " R7 = [P5 + __dl_fini@FUNCDESC_GOT17M4];\n" \
  72. " P4 = [SP + 24];\n" \
  73. " P3 = [SP + 28];\n" \
  74. " P0 = R5;\n" \
  75. " SP += 32;\n" \
  76. " JUMP (P4);\n" \
  77. " .size __dl_boot,.-__dl_boot\n"
  78. );
  79. #undef DL_START
  80. #define DL_START(X) \
  81. static void __attribute__ ((used)) \
  82. _dl_start (Elf32_Addr dl_boot_got_pointer, \
  83. struct elf32_fdpic_loadmap *dl_boot_progmap, \
  84. struct elf32_fdpic_loadmap *dl_boot_ldsomap, \
  85. Elf32_Dyn *dl_boot_ldso_dyn_pointer, \
  86. struct funcdesc_value *dl_main_funcdesc, \
  87. X)
  88. struct elf32_fdpic_loadmap;
  89. /*
  90. * Get a pointer to the argv array. On many platforms this can be just
  91. * the address of the first argument, on other platforms we need to
  92. * do something a little more subtle here.
  93. */
  94. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS) + 1)
  95. /*
  96. * Here is a macro to perform a relocation. This is only used when
  97. * bootstrapping the dynamic loader. RELP is the relocation that we
  98. * are performing, REL is the pointer to the address we are relocating.
  99. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  100. * load address.
  101. */
  102. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  103. switch(ELF32_R_TYPE((RELP)->r_info)){ \
  104. case R_BFIN_byte4_data: \
  105. *(REL) += (SYMBOL); \
  106. break; \
  107. case R_BFIN_FUNCDESC_VALUE: \
  108. { \
  109. struct funcdesc_value fv = { \
  110. (void*)((SYMBOL) + *(REL)), \
  111. (LOAD).got_value \
  112. }; \
  113. *(struct funcdesc_value volatile *)(REL) = fv; \
  114. break; \
  115. } \
  116. default: \
  117. _dl_exit(1); \
  118. }
  119. /*
  120. * Transfer control to the user's application, once the dynamic loader
  121. * is done. We return the address of the function's entry point to
  122. * _dl_boot, see boot1_arch.h.
  123. */
  124. #define START() do { \
  125. struct elf_resolve *exec_mod = _dl_loaded_modules; \
  126. dl_main_funcdesc->entry_point = _dl_elf_main; \
  127. while (exec_mod->libtype != elf_executable) \
  128. exec_mod = exec_mod->next; \
  129. dl_main_funcdesc->got_value = exec_mod->loadaddr.got_value; \
  130. return; \
  131. } while (0)