dl-startup.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Any assembly language/system dependent hacks needed to setup boot1.c so it
  2. * will work as expected and cope with whatever platform specific wierdness is
  3. * needed for this architecture.
  4. */
  5. __asm__("" \
  6. " .section .text..SHmedia32,\"ax\"\n" \
  7. " .globl _start\n" \
  8. " .type _start, @function\n" \
  9. " .align 5\n" \
  10. "_start:\n" \
  11. " ! Set r12 to point to GOT\n" \
  12. " movi (((datalabel _GLOBAL_OFFSET_TABLE_-(.LZZZ3-.)) >> 16) & 0xffff), r12\n" \
  13. " shori ((datalabel _GLOBAL_OFFSET_TABLE_-(.LZZZ3-.)) & 0xffff), r12\n" \
  14. ".LZZZ3:\n" \
  15. " ptrel/u r12, tr0\n" \
  16. " gettr tr0, r12 ! GOT address\n" \
  17. " add r18, r63, r11 ! save return address - needed?\n" \
  18. " add r15, r63, r2 ! arg = stack pointer\n" \
  19. " pt _dl_start, tr0 ! should work even if PIC\n" \
  20. " blink tr0, r18 ! call _dl_start - user EP is in r2\n" \
  21. " add r2, r63, r28\n" \
  22. " movi (((_dl_fini@GOT) >> 16) & 0xffff), r1\n" \
  23. " shori ((_dl_fini@GOT) & 0xffff), r1\n" \
  24. " ldx.l r1, r12, r2\n" \
  25. " add r11, r63, r18\n" \
  26. " ptabs/l r28, tr0\n" \
  27. " blink tr0, r63\n" \
  28. " .size _start,.-_start\n"
  29. " .previous\n"
  30. );
  31. /*
  32. * Get a pointer to the argv array. On many platforms this can be just
  33. * the address of the first argument, on other platforms we need to
  34. * do something a little more subtle here.
  35. */
  36. #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *)ARGS)+1)
  37. /*
  38. * Here is a macro to perform a relocation. This is only used when
  39. * bootstrapping the dynamic loader. RELP is the relocation that we
  40. * are performing, REL is the pointer to the address we are relocating.
  41. * SYMBOL is the symbol involved in the relocation, and LOAD is the
  42. * load address.
  43. */
  44. #include <elf.h>
  45. #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
  46. const unsigned int r_type = ELF32_R_TYPE((RELP)->r_info); \
  47. int lsb = !!((SYMTAB)->st_other & STO_SH5_ISA32); \
  48. \
  49. switch (r_type) { \
  50. case R_SH_REL32: \
  51. *(REL) = (SYMBOL) + (RELP)->r_addend \
  52. - (unsigned long)(REL); \
  53. break; \
  54. case R_SH_DIR32: \
  55. case R_SH_GLOB_DAT: \
  56. case R_SH_JMP_SLOT: \
  57. *(REL) = ((SYMBOL) + (RELP)->r_addend) | lsb; \
  58. break; \
  59. case R_SH_RELATIVE: \
  60. *(REL) = (LOAD) + (RELP)->r_addend; \
  61. break; \
  62. case R_SH_RELATIVE_LOW16: \
  63. case R_SH_RELATIVE_MEDLOW16: \
  64. { \
  65. unsigned long word, value; \
  66. \
  67. word = (unsigned long)(REL) & ~0x3fffc00; \
  68. value = (LOAD) + (RELP)->r_addend; \
  69. \
  70. if (r_type == R_SH_RELATIVE_MEDLOW16) \
  71. value >>= 16; \
  72. \
  73. word |= (value & 0xffff) << 10; \
  74. *(REL) = word; \
  75. break; \
  76. } \
  77. case R_SH_IMM_LOW16: \
  78. case R_SH_IMM_MEDLOW16: \
  79. { \
  80. unsigned long word, value; \
  81. \
  82. word = (unsigned long)(REL) & ~0x3fffc00; \
  83. value = ((SYMBOL) + (RELP)->r_addend) | lsb; \
  84. \
  85. if (r_type == R_SH_IMM_MEDLOW16) \
  86. value >>= 16; \
  87. \
  88. word |= (value & 0xffff) << 10; \
  89. *(REL) = word; \
  90. break; \
  91. } \
  92. case R_SH_IMM_LOW16_PCREL: \
  93. case R_SH_IMM_MEDLOW16_PCREL: \
  94. { \
  95. unsigned long word, value; \
  96. \
  97. word = (unsigned long)(REL) & ~0x3fffc00; \
  98. value = (SYMBOL) + (RELP)->r_addend \
  99. - (unsigned long)(REL); \
  100. \
  101. if (r_type == R_SH_IMM_MEDLOW16_PCREL) \
  102. value >>= 16; \
  103. \
  104. word |= (value & 0xffff) << 10; \
  105. *(REL) = word; \
  106. break; \
  107. } \
  108. case R_SH_NONE: \
  109. break; \
  110. default: \
  111. _dl_exit(1); \
  112. }