dl-sysdep.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #include <tls.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 "sh"
  22. struct elf_resolve;
  23. extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
  24. static __always_inline unsigned int
  25. _dl_urem(unsigned int n, unsigned int base)
  26. {
  27. int res;
  28. __asm__ (""\
  29. "mov #0, r0\n\t" \
  30. "div0u\n\t" \
  31. "" \
  32. "! get one bit from the msb of the numerator into the T\n\t" \
  33. "! bit and divide it by whats in %2. Put the answer bit\n\t" \
  34. "! into the T bit so it can come out again at the bottom\n\t" \
  35. "" \
  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. "rotcl %1 ; div1 %2, r0\n\t" \
  44. "" \
  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. "rotcl %1 ; div1 %2, r0\n\t" \
  53. "" \
  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. "rotcl %1 ; div1 %2, r0\n\t" \
  62. "" \
  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 ; div1 %2, r0\n\t" \
  71. "rotcl %1\n\t"
  72. : "=r" (res)
  73. : "0" (n), "r" (base)
  74. : "r0","cc");
  75. return n - (base * res);
  76. }
  77. #define do_rem(result, n, base) ((result) = _dl_urem((n), (base)))
  78. /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
  79. TLS variable, so undefined references should not be allowed to
  80. define the value.
  81. ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
  82. of the main executable's symbols, as for a COPY reloc. */
  83. #if defined USE_TLS
  84. # define elf_machine_type_class(type) \
  85. ((((type) == R_SH_JMP_SLOT || (type) == R_SH_TLS_DTPMOD32 \
  86. || (type) == R_SH_TLS_DTPOFF32 || (type) == R_SH_TLS_TPOFF32) \
  87. * ELF_RTYPE_CLASS_PLT) \
  88. | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
  89. #else
  90. #define elf_machine_type_class(type) \
  91. ((((type) == R_SH_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
  92. | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
  93. #endif
  94. /* Return the link-time address of _DYNAMIC. Conveniently, this is the
  95. first element of the GOT. This must be inlined in a function which
  96. uses global data. */
  97. static __always_inline Elf32_Addr __attribute__ ((unused))
  98. elf_machine_dynamic (void)
  99. {
  100. register Elf32_Addr *got;
  101. __asm__ ("mov r12,%0" :"=r" (got));
  102. return *got;
  103. }
  104. /* Return the run-time load address of the shared object. */
  105. static __always_inline Elf32_Addr __attribute__ ((unused))
  106. elf_machine_load_address (void)
  107. {
  108. Elf32_Addr addr;
  109. __asm__ ("mov.l 1f,r0\n\
  110. mov.l 3f,r2\n\
  111. add r12,r2\n\
  112. mov.l @(r0,r12),r0\n\
  113. bra 2f\n\
  114. sub r0,r2\n\
  115. .align 2\n\
  116. 1: .long _dl_start@GOT\n\
  117. 3: .long _dl_start@GOTOFF\n\
  118. 2: mov r2,%0"
  119. : "=r" (addr) : : "r0", "r1", "r2");
  120. return addr;
  121. }
  122. #define COPY_UNALIGNED_WORD(swp, twp, align) \
  123. { \
  124. void *__s = (swp), *__t = (twp); \
  125. unsigned char *__s1 = __s, *__t1 = __t; \
  126. unsigned short *__s2 = __s, *__t2 = __t; \
  127. unsigned long *__s4 = __s, *__t4 = __t; \
  128. switch ((align)) \
  129. { \
  130. case 0: \
  131. *__t4 = *__s4; \
  132. break; \
  133. case 2: \
  134. *__t2++ = *__s2++; \
  135. *__t2 = *__s2; \
  136. break; \
  137. default: \
  138. *__t1++ = *__s1++; \
  139. *__t1++ = *__s1++; \
  140. *__t1++ = *__s1++; \
  141. *__t1 = *__s1; \
  142. break; \
  143. } \
  144. }
  145. static __always_inline void
  146. elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
  147. Elf32_Word relative_count)
  148. {
  149. Elf32_Addr value;
  150. Elf32_Rela * rpnt = (void *)rel_addr;
  151. do {
  152. Elf32_Addr *const reloc_addr = (void *) (load_off + rpnt->r_offset);
  153. if (rpnt->r_addend)
  154. value = load_off + rpnt->r_addend;
  155. else {
  156. COPY_UNALIGNED_WORD (reloc_addr, &value, (int) reloc_addr & 3);
  157. value += load_off;
  158. }
  159. COPY_UNALIGNED_WORD (&value, reloc_addr, (int) reloc_addr & 3);
  160. rpnt++;
  161. } while (--relative_count);
  162. #undef COPY_UNALIGNED_WORD
  163. }