dl-sysdep.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* vi: set sw=8 ts=8: */
  2. /*
  3. * Various assmbly language/system dependent hacks that are required
  4. * so that we can minimize the amount of platform specific code.
  5. */
  6. /* Define this if the system uses RELOCA. */
  7. #define ELF_USES_RELOCA
  8. #include <elf.h>
  9. /*
  10. * Initialization sequence for a GOT.
  11. */
  12. #define INIT_GOT(GOT_BASE,MODULE) \
  13. { \
  14. GOT_BASE[2] = (unsigned long)_dl_linux_resolve; \
  15. GOT_BASE[1] = (unsigned long)(MODULE); \
  16. }
  17. /* Here we define the magic numbers that this dynamic loader should accept */
  18. #define MAGIC1 EM_SH
  19. #undef MAGIC2
  20. /* Used for error messages */
  21. #define ELF_TARGET "sh64"
  22. struct elf_resolve;
  23. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  24. #define do_rem(result, n, base) ((result) = (n) % (base))
  25. /* 4096 bytes alignment */
  26. #define PAGE_ALIGN 0xfffff000
  27. #define ADDR_ALIGN 0xfff
  28. #define OFFS_ALIGN 0x7ffff000
  29. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  30. TLS variable, so undefined references should not be allowed to
  31. define the value.
  32. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  33. of the main executable's symbols, as for a COPY reloc. */
  34. #define elf_machine_type_class(type) \
  35. ((((type) == R_SH_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
  36. | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
  37. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  38. first element of the GOT. This must be inlined in a function which
  39. uses global data. */
  40. static inline Elf32_Addr __attribute__ ((unused))
  41. elf_machine_dynamic (void)
  42. {
  43. register Elf32_Addr *got;
  44. asm ("mov r12,%0" :"=r" (got));
  45. return *got;
  46. }
  47. /* Return the run-time load address of the shared object. */
  48. static inline Elf32_Addr __attribute__ ((unused))
  49. elf_machine_load_address (void)
  50. {
  51. Elf32_Addr addr;
  52. asm ("mov.l 1f,r0\n\
  53. mov.l 3f,r2\n\
  54. add r12,r2\n\
  55. mov.l @(r0,r12),r0\n\
  56. bra 2f\n\
  57. sub r0,r2\n\
  58. .align 2\n\
  59. 1: .long _dl_boot@GOT\n\
  60. 3: .long _dl_boot@GOTOFF\n\
  61. 2: mov r2,%0"
  62. : "=r" (addr) : : "r0", "r1", "r2");
  63. return addr;
  64. }
  65. #define COPY_UNALIGNED_WORD(swp, twp, align) \
  66. { \
  67. void *__s = (swp), *__t = (twp); \
  68. unsigned char *__s1 = __s, *__t1 = __t; \
  69. unsigned short *__s2 = __s, *__t2 = __t; \
  70. unsigned long *__s4 = __s, *__t4 = __t; \
  71. switch ((align)) \
  72. { \
  73. case 0: \
  74. *__t4 = *__s4; \
  75. break; \
  76. case 2: \
  77. *__t2++ = *__s2++; \
  78. *__t2 = *__s2; \
  79. break; \
  80. default: \
  81. *__t1++ = *__s1++; \
  82. *__t1++ = *__s1++; \
  83. *__t1++ = *__s1++; \
  84. *__t1 = *__s1; \
  85. break; \
  86. } \
  87. }
  88. static inline void
  89. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  90. Elf32_Word relative_count)
  91. {
  92. Elf32_Addr value;
  93. Elf32_Rela * rpnt = (void *) (rel_addr + load_off);
  94. do {
  95. Elf32_Addr *const reloc_addr = (void *) (load_off + rpnt->r_offset);
  96. if (rpnt->r_addend)
  97. value = load_off + rpnt->r_addend;
  98. else {
  99. COPY_UNALIGNED_WORD (reloc_addr, &value, (int) reloc_addr & 3);
  100. value += load_off;
  101. }
  102. COPY_UNALIGNED_WORD (&value, reloc_addr, (int) reloc_addr & 3);
  103. rpnt++;
  104. } while (--relative_count);
  105. #undef COPY_UNALIGNED_WORD
  106. }