]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/ldso/ldso/arm/dl-sysdep.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / ldso / ldso / arm / dl-sysdep.h
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Various assembly language/system dependent hacks that are required
4  * so that we can minimize the amount of platform specific code.
5  * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
6  */
7
8 #ifndef _ARCH_DL_SYSDEP
9 #define _ARCH_DL_SYSDEP
10
11 /* Define this if the system uses RELOCA.  */
12 #undef ELF_USES_RELOCA
13 #include <elf.h>
14 /* Initialization sequence for the GOT.  */
15 #define INIT_GOT(GOT_BASE,MODULE) \
16 {                               \
17   GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \
18   GOT_BASE[1] = (unsigned long) MODULE; \
19 }
20
21 static __always_inline unsigned long arm_modulus(unsigned long m, unsigned long p)
22 {
23         unsigned long i,t,inc;
24         i=p; t=0;
25         while (!(i&(1<<31))) {
26                 i<<=1;
27                 t++;
28         }
29         t--;
30         for (inc=t;inc>2;inc--) {
31                 i=p<<inc;
32                 if (i&(1<<31))
33                         break;
34                 while (m>=i) {
35                         m-=i;
36                         i<<=1;
37                         if (i&(1<<31))
38                                 break;
39                         if (i<p)
40                                 break;
41                 }
42         }
43         while (m>=p) {
44                 m-=p;
45         }
46         return m;
47 }
48 #define do_rem(result, n, base) ((result) = arm_modulus(n, base))
49 #define do_div_10(result, remain) ((result) = (((result) - (remain)) / 2) * -(-1ul / 5ul))
50
51 /* Here we define the magic numbers that this dynamic loader should accept */
52 #define MAGIC1 EM_ARM
53 #undef  MAGIC2
54
55 /* Used for error messages */
56 #define ELF_TARGET "ARM"
57
58 struct elf_resolve;
59 unsigned long _dl_linux_resolver(struct elf_resolve * tpnt, int reloc_entry);
60
61 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
62    TLS variable, so undefined references should not be allowed to
63    define the value.
64
65    ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
66    of the main executable's symbols, as for a COPY reloc.  */
67 #define elf_machine_type_class(type)                                                                    \
68   ((((type) == R_ARM_JUMP_SLOT || (type) == R_ARM_TLS_DTPMOD32                  \
69      || (type) == R_ARM_TLS_DTPOFF32 || (type) == R_ARM_TLS_TPOFF32)    \
70     * ELF_RTYPE_CLASS_PLT)                                                                                              \
71    | (((type) == R_ARM_COPY) * ELF_RTYPE_CLASS_COPY))
72
73 /* Return the link-time address of _DYNAMIC.  Conveniently, this is the
74    first element of the GOT.  We used to use the PIC register to do this
75    without a constant pool reference, but GCC 4.2 will use a pseudo-register
76    for the PIC base, so it may not be in r10.  */
77 static __always_inline Elf32_Addr __attribute__ ((unused))
78 elf_machine_dynamic (void)
79 {
80   Elf32_Addr dynamic;
81 #if !defined __thumb__
82   __asm__ ("ldr %0, 2f\n"
83        "1: ldr %0, [pc, %0]\n"
84        "b 3f\n"
85        "2: .word _GLOBAL_OFFSET_TABLE_ - (1b+8)\n"
86        "3:" : "=r" (dynamic));
87 #else
88   int tmp;
89   __asm__ (".align 2\n"
90        "bx     pc\n"
91        "nop\n"
92        ".arm\n"
93        "ldr %0, 2f\n"
94        "1: ldr %0, [pc, %0]\n"
95        "b 3f\n"
96        "2: .word _GLOBAL_OFFSET_TABLE_ - (1b+8)\n"
97        "3:"
98        ".align  2\n"
99         "orr     %1, pc, #1\n"
100         "bx      %1\n"
101         ".force_thumb\n"
102        : "=r" (dynamic), "=&r" (tmp));
103 #endif
104
105   return dynamic;
106 }
107
108 extern /*void*/ int __dl_start __asm__ ("_dl_start");
109
110 /* Return the run-time load address of the shared object.  */
111 static __always_inline Elf32_Addr __attribute__ ((unused))
112 elf_machine_load_address (void)
113 {
114         Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
115         Elf32_Addr pcrel_addr;
116 #if defined __OPTIMIZE__ && !defined __thumb__
117         __asm__ ("adr %0, _dl_start" : "=r" (pcrel_addr));
118 #else
119         /* A simple adr does not work in Thumb mode because the offset is
120            negative, and for debug builds may be too large.  */
121         int tmp;
122         __asm__ ("adr %1, 1f\n\t"
123                  "ldr %0, [%1]\n\t"
124                  "add %0, %0, %1\n\t"
125                  "b 2f\n\t"
126                  ".align 2\n\t"
127                  "1: .word _dl_start - 1b\n\t"
128                  "2:"
129                  : "=r" (pcrel_addr), "=r" (tmp));
130 #endif
131         return pcrel_addr - got_addr;
132 }
133
134 static __always_inline void
135 elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
136                       Elf32_Word relative_count)
137 {
138          Elf32_Rel * rpnt = (void *) rel_addr;
139         --rpnt;
140         do {
141                 Elf32_Addr *const reloc_addr = (void *) (load_off + (++rpnt)->r_offset);
142
143                 *reloc_addr += load_off;
144         } while (--relative_count);
145 }
146 #endif /* !_ARCH_DL_SYSDEP */
147
148 #ifdef __ARM_EABI__
149 #define DL_MALLOC_ALIGN 8       /* EABI needs 8 byte alignment for STRD LDRD */
150 #endif