dl-sysdep.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Various assembly language/system dependent hacks that are required
  3. * so that we can minimize the amount of platform specific code.
  4. */
  5. /* Define this if the system uses RELOCA. */
  6. #define ELF_USES_RELOCA
  7. #include <elf.h>
  8. /*
  9. * Initialization sequence for a GOT.
  10. */
  11. #define INIT_GOT(GOT_BASE,MODULE) \
  12. { \
  13. GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
  14. GOT_BASE[1] = (unsigned long) (MODULE); \
  15. }
  16. /* Here we define the magic numbers that this dynamic loader should accept */
  17. #define MAGIC1 EM_SH
  18. #undef MAGIC2
  19. /* Used for error messages */
  20. #define ELF_TARGET "sh"
  21. struct elf_resolve;
  22. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  23. static __always_inline unsigned int
  24. _dl_urem(unsigned int n, unsigned int base)
  25. {
  26. int res;
  27. __asm__ (""\
  28. "mov #0, r0\n\t" \
  29. "div0u\n\t" \
  30. "" \
  31. "! get one bit from the msb of the numerator into the T\n\t" \
  32. "! bit and divide it by whats in %2. Put the answer bit\n\t" \
  33. "! into the T bit so it can come out again at the bottom\n\t" \
  34. "" \
  35. "rotcl %1 ; div1 %2, r0\n\t" \
  36. "rotcl %1 ; div1 %2, r0\n\t" \
  37. "rotcl %1 ; div1 %2, r0\n\t" \
  38. "rotcl %1 ; div1 %2, r0\n\t" \
  39. "rotcl %1 ; div1 %2, r0\n\t" \
  40. "rotcl %1 ; div1 %2, r0\n\t" \
  41. "rotcl %1 ; div1 %2, r0\n\t" \
  42. "rotcl %1 ; div1 %2, r0\n\t" \
  43. "" \
  44. "rotcl %1 ; div1 %2, r0\n\t" \
  45. "rotcl %1 ; div1 %2, r0\n\t" \
  46. "rotcl %1 ; div1 %2, r0\n\t" \
  47. "rotcl %1 ; div1 %2, r0\n\t" \
  48. "rotcl %1 ; div1 %2, r0\n\t" \
  49. "rotcl %1 ; div1 %2, r0\n\t" \
  50. "rotcl %1 ; div1 %2, r0\n\t" \
  51. "rotcl %1 ; div1 %2, r0\n\t" \
  52. "" \
  53. "rotcl %1 ; div1 %2, r0\n\t" \
  54. "rotcl %1 ; div1 %2, r0\n\t" \
  55. "rotcl %1 ; div1 %2, r0\n\t" \
  56. "rotcl %1 ; div1 %2, r0\n\t" \
  57. "rotcl %1 ; div1 %2, r0\n\t" \
  58. "rotcl %1 ; div1 %2, r0\n\t" \
  59. "rotcl %1 ; div1 %2, r0\n\t" \
  60. "rotcl %1 ; div1 %2, r0\n\t" \
  61. "" \
  62. "rotcl %1 ; div1 %2, r0\n\t" \
  63. "rotcl %1 ; div1 %2, r0\n\t" \
  64. "rotcl %1 ; div1 %2, r0\n\t" \
  65. "rotcl %1 ; div1 %2, r0\n\t" \
  66. "rotcl %1 ; div1 %2, r0\n\t" \
  67. "rotcl %1 ; div1 %2, r0\n\t" \
  68. "rotcl %1 ; div1 %2, r0\n\t" \
  69. "rotcl %1 ; div1 %2, r0\n\t" \
  70. "rotcl %1\n\t"
  71. : "=r" (res)
  72. : "0" (n), "r" (base)
  73. : "r0","cc");
  74. return n - (base * res);
  75. }
  76. #define do_rem(result, n, base) ((result) = _dl_urem((n), (base)))
  77. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  78. TLS variable, so undefined references should not be allowed to
  79. define the value.
  80. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  81. of the main executable's symbols, as for a COPY reloc. */
  82. # define elf_machine_type_class(type) \
  83. ((((type) == R_SH_JMP_SLOT || (type) == R_SH_TLS_DTPMOD32 \
  84. || (type) == R_SH_TLS_DTPOFF32 || (type) == R_SH_TLS_TPOFF32) \
  85. * ELF_RTYPE_CLASS_PLT) \
  86. | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
  87. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  88. first element of the GOT. This must be inlined in a function which
  89. uses global data. */
  90. static __always_inline Elf32_Addr __attribute__ ((unused))
  91. elf_machine_dynamic (void)
  92. {
  93. register Elf32_Addr *got;
  94. __asm__ ("mov r12,%0" :"=r" (got));
  95. return *got;
  96. }
  97. /* Return the run-time load address of the shared object. */
  98. static __always_inline Elf32_Addr __attribute__ ((unused))
  99. elf_machine_load_address (void)
  100. {
  101. Elf32_Addr addr;
  102. __asm__ ("mov.l 1f,r0\n\
  103. mov.l 3f,r2\n\
  104. add r12,r2\n\
  105. mov.l @(r0,r12),r0\n\
  106. bra 2f\n\
  107. sub r0,r2\n\
  108. .align 2\n\
  109. 1: .long _dl_start@GOT\n\
  110. 3: .long _dl_start@GOTOFF\n\
  111. 2: mov r2,%0"
  112. : "=r" (addr) : : "r0", "r1", "r2");
  113. return addr;
  114. }
  115. #define COPY_UNALIGNED_WORD(swp, twp, align) \
  116. { \
  117. void *__s = (swp), *__t = (twp); \
  118. unsigned char *__s1 = __s, *__t1 = __t; \
  119. unsigned short *__s2 = __s, *__t2 = __t; \
  120. unsigned long *__s4 = __s, *__t4 = __t; \
  121. switch ((align)) \
  122. { \
  123. case 0: \
  124. *__t4 = *__s4; \
  125. break; \
  126. case 2: \
  127. *__t2++ = *__s2++; \
  128. *__t2 = *__s2; \
  129. break; \
  130. default: \
  131. *__t1++ = *__s1++; \
  132. *__t1++ = *__s1++; \
  133. *__t1++ = *__s1++; \
  134. *__t1 = *__s1; \
  135. break; \
  136. } \
  137. }
  138. static __always_inline void
  139. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  140. Elf32_Word relative_count)
  141. {
  142. Elf32_Addr value;
  143. Elf32_Rela * rpnt = (void *)rel_addr;
  144. do {
  145. Elf32_Addr *const reloc_addr = (void *) (load_off + rpnt->r_offset);
  146. if (rpnt->r_addend)
  147. value = load_off + rpnt->r_addend;
  148. else {
  149. COPY_UNALIGNED_WORD (reloc_addr, &value, (int) reloc_addr & 3);
  150. value += load_off;
  151. }
  152. COPY_UNALIGNED_WORD (&value, reloc_addr, (int) reloc_addr & 3);
  153. rpnt++;
  154. } while (--relative_count);
  155. #undef COPY_UNALIGNED_WORD
  156. }