2 * Various assembly language/system dependent hacks that are required
3 * so that we can minimize the amount of platform specific code.
6 /* Define this if the system uses RELOCA. */
7 #define ELF_USES_RELOCA
11 * Initialization sequence for a GOT.
13 #define INIT_GOT(GOT_BASE,MODULE) \
15 GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
16 GOT_BASE[1] = (unsigned long) (MODULE); \
19 /* Here we define the magic numbers that this dynamic loader should accept */
23 /* Used for error messages */
24 #define ELF_TARGET "sh"
27 extern unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
29 static __always_inline unsigned int
30 _dl_urem(unsigned int n, unsigned int base)
38 "! get one bit from the msb of the numerator into the T\n\t" \
39 "! bit and divide it by whats in %2. Put the answer bit\n\t" \
40 "! into the T bit so it can come out again at the bottom\n\t" \
42 "rotcl %1 ; div1 %2, r0\n\t" \
43 "rotcl %1 ; div1 %2, r0\n\t" \
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" \
51 "rotcl %1 ; div1 %2, r0\n\t" \
52 "rotcl %1 ; div1 %2, r0\n\t" \
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" \
60 "rotcl %1 ; div1 %2, r0\n\t" \
61 "rotcl %1 ; div1 %2, r0\n\t" \
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" \
69 "rotcl %1 ; div1 %2, r0\n\t" \
70 "rotcl %1 ; div1 %2, r0\n\t" \
71 "rotcl %1 ; div1 %2, r0\n\t" \
72 "rotcl %1 ; div1 %2, r0\n\t" \
73 "rotcl %1 ; div1 %2, r0\n\t" \
74 "rotcl %1 ; div1 %2, r0\n\t" \
75 "rotcl %1 ; div1 %2, r0\n\t" \
76 "rotcl %1 ; div1 %2, r0\n\t" \
82 return n - (base * res);
85 #define do_rem(result, n, base) ((result) = _dl_urem((n), (base)))
87 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
88 TLS variable, so undefined references should not be allowed to
90 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
91 of the main executable's symbols, as for a COPY reloc. */
93 # define elf_machine_type_class(type) \
94 ((((type) == R_SH_JMP_SLOT || (type) == R_SH_TLS_DTPMOD32 \
95 || (type) == R_SH_TLS_DTPOFF32 || (type) == R_SH_TLS_TPOFF32) \
96 * ELF_RTYPE_CLASS_PLT) \
97 | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
99 #define elf_machine_type_class(type) \
100 ((((type) == R_SH_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
101 | (((type) == R_SH_COPY) * ELF_RTYPE_CLASS_COPY))
104 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
105 first element of the GOT. This must be inlined in a function which
107 static __always_inline Elf32_Addr __attribute__ ((unused))
108 elf_machine_dynamic (void)
110 register Elf32_Addr *got;
111 __asm__ ("mov r12,%0" :"=r" (got));
115 /* Return the run-time load address of the shared object. */
116 static __always_inline Elf32_Addr __attribute__ ((unused))
117 elf_machine_load_address (void)
120 __asm__ ("mov.l 1f,r0\n\
123 mov.l @(r0,r12),r0\n\
127 1: .long _dl_start@GOT\n\
128 3: .long _dl_start@GOTOFF\n\
130 : "=r" (addr) : : "r0", "r1", "r2");
134 #define COPY_UNALIGNED_WORD(swp, twp, align) \
136 void *__s = (swp), *__t = (twp); \
137 unsigned char *__s1 = __s, *__t1 = __t; \
138 unsigned short *__s2 = __s, *__t2 = __t; \
139 unsigned long *__s4 = __s, *__t4 = __t; \
158 static __always_inline void
159 elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
160 Elf32_Word relative_count)
163 Elf32_Rela * rpnt = (void *)rel_addr;
166 Elf32_Addr *const reloc_addr = (void *) (load_off + rpnt->r_offset);
169 value = load_off + rpnt->r_addend;
171 COPY_UNALIGNED_WORD (reloc_addr, &value, (int) reloc_addr & 3);
174 COPY_UNALIGNED_WORD (&value, reloc_addr, (int) reloc_addr & 3);
176 } while (--relative_count);
177 #undef COPY_UNALIGNED_WORD