dl-startup.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright (C) 2003 Red Hat, Inc.
  2. * Contributed by Alexandre Oliva <aoliva@redhat.com>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. /* Any assembly language/system dependent hacks needed to setup
  7. * boot1.c so it will work as expected and cope with whatever platform
  8. * specific wierdness is needed for this architecture.
  9. * We override the default _dl_boot function, and replace it with a
  10. * bit of asm. Then call the real _dl_boot function, which is now
  11. * named _dl_boot2. */
  12. /* At program start-up, gr16 contains a pointer to a
  13. elf32_fdpic_loadmap that describes how the executable was loaded
  14. into memory. gr17 contains a pointer to the interpreter (our!)
  15. loadmap, if there is an interpreter, or 0 if we're being run as an
  16. executable. gr18 holds a pointer to the interpreter's dynamic
  17. section, if there is an interpreter, or to the executable's dynamic
  18. section, otherwise. If the executable is not dynamic, gr18 is 0.
  19. We rely on the fact that the linker adds a pointer to the
  20. _GLOBAL_OFFSET_TABLE_ as the last ROFIXUP entry, and that
  21. __self_reloc returns the relocated pointer to us, so that we can
  22. use this value to initialize the PIC register. */
  23. __asm__("" \
  24. " .text\n" \
  25. " .global _dl_boot\n" \
  26. " .type _dl_boot,@function\n" \
  27. "_dl_boot:\n" \
  28. " call .Lcall\n" \
  29. ".Lcall:\n" \
  30. " movsg lr, gr4\n" \
  31. " sethi.p #gprelhi(.Lcall), gr5\n"\
  32. " setlo #gprello(.Lcall), gr5\n"\
  33. " mov.p gr17, gr8\n" \
  34. " cmp gr17, gr0, icc0\n" \
  35. " sub.p gr4, gr5, gr4\n" \
  36. " ckeq icc0, cc4\n" \
  37. " cmov.p gr16, gr8, cc4, 1\n" \
  38. " sethi #gprelhi(__ROFIXUP_LIST__), gr9\n" \
  39. " sethi.p #gprelhi(__ROFIXUP_END__), gr10\n" \
  40. " setlo #gprello(__ROFIXUP_LIST__), gr9\n" \
  41. " setlo.p #gprello(__ROFIXUP_END__), gr10\n" \
  42. " add gr9, gr4, gr9\n" \
  43. " add.p gr10, gr4, gr10\n" \
  44. " call __self_reloc\n" \
  45. " mov.p gr8, gr15\n" \
  46. " mov gr16, gr9\n" \
  47. " mov.p gr17, gr10\n" \
  48. " mov gr18, gr11\n" \
  49. " addi.p sp, #4, gr13\n" \
  50. " addi sp, #-8, sp\n" \
  51. " mov.p sp, gr12\n" \
  52. " call _dl_boot2\n" \
  53. " ldd.p @(sp, gr0), gr14\n" \
  54. " addi sp, #8, sp\n" \
  55. " movgs gr0, lr\n" \
  56. " jmpl @(gr14, gr0)\n" \
  57. " .size _dl_boot,.-_dl_boot\n" \
  58. );
  59. #define _dl_boot _dl_boot2
  60. #define DL_BOOT(X) \
  61. static void __attribute__ ((used)) \
  62. _dl_boot (void *dl_boot_got_pointer, \
  63. struct elf32_fdpic_loadmap *dl_boot_progmap, \
  64. struct elf32_fdpic_loadmap *dl_boot_ldsomap, \
  65. Elf32_Dyn *dl_boot_ldso_dyn_pointer, \
  66. struct funcdesc_value *dl_main_funcdesc, \
  67. X)
  68. struct elf32_fdpic_loadmap;
  69. /*
  70. * Get a pointer to the argv array. On many platforms this can be just
  71. * the address of the first argument, on other platforms we need to
  72. * do something a little more subtle here.
  73. */
  74. #define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long*) ARGS)
  75. /*
  76. * Compute the GOT address. On several platforms, we use assembly
  77. * here. on FR-V FDPIC, there's no way to compute the GOT address,
  78. * since the offset between text and data is not fixed, so we arrange
  79. * for the assembly _dl_boot to pass this value as an argument to
  80. * _dl_boot. */
  81. #define DL_BOOT_COMPUTE_GOT(got) ((got) = dl_boot_got_pointer)
  82. #define DL_BOOT_COMPUTE_DYN(dpnt, got, load_addr) \
  83. ((dpnt) = dl_boot_ldso_dyn_pointer)
  84. /*
  85. * Here is a macro to perform a relocation. This is only used when
  86. * bootstrapping the dynamic loader. RELP is the relocation that we
  87. * are performing, REL is the pointer to the address we are relocating.
  88. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  89. * load address.
  90. */
  91. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  92. switch(ELF32_R_TYPE((RELP)->r_info)){ \
  93. case R_FRV_32: \
  94. *(REL) += (SYMBOL); \
  95. break; \
  96. case R_FRV_FUNCDESC_VALUE: \
  97. { \
  98. struct funcdesc_value fv = { \
  99. (void*)((SYMBOL) + *(REL)), \
  100. (LOAD).got_value \
  101. }; \
  102. *(struct funcdesc_value volatile *)(REL) = fv; \
  103. break; \
  104. } \
  105. default: \
  106. _dl_exit(1); \
  107. }
  108. /*
  109. * Transfer control to the user's application, once the dynamic loader
  110. * is done. We return the address of the function's entry point to
  111. * _dl_boot, see boot1_arch.h.
  112. */
  113. #define START() do { \
  114. struct elf_resolve *exec_mod = _dl_loaded_modules; \
  115. dl_main_funcdesc->entry_point = _dl_elf_main; \
  116. while (exec_mod->libtype != elf_executable) \
  117. exec_mod = exec_mod->next; \
  118. dl_main_funcdesc->got_value = exec_mod->loadaddr.got_value; \
  119. /* _dl_dprintf(2, "entry point is (%x,%x)\n", dl_main_funcdesc->entry_point, dl_main_funcdesc->got_value); */ \
  120. return; \
  121. } while (0)