]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/ldso/ldso/microblaze/dl-sysdep.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / ldso / ldso / microblaze / dl-sysdep.h
1 /* elf reloc code for the microblaze platform, based on glibc 2.3.6, dl-machine.h */
2
3 /*
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <http://www.gnu.org/licenses/>.  */
17
18 /* Use reloca */
19 #define ELF_USES_RELOCA
20
21 #include <elf.h>
22
23
24 /* Initialise the GOT */
25 #define INIT_GOT(GOT_BASE,MODULE)                                                       \
26 do {                                                                                                            \
27         GOT_BASE[2] = (unsigned long) _dl_linux_resolve;                \
28         GOT_BASE[1] = (unsigned long) MODULE;                                   \
29 } while(0)
30
31 /* Here we define the magic numbers that this dynamic loader should accept */
32
33 #define MAGIC1 EM_MICROBLAZE_OLD
34 #undef  MAGIC2
35 /* Used for error messages */
36 #define ELF_TARGET "microblaze"
37
38 #define elf_machine_type_class(type) \
39   (((type) == R_MICROBLAZE_JUMP_SLOT) * ELF_RTYPE_CLASS_PLT \
40    | ((type) == R_MICROBLAZE_COPY) * ELF_RTYPE_CLASS_COPY)
41
42 /* Return the link-time address of _DYNAMIC.  Conveniently, this is the
43    first element of the GOT.  This must be inlined in a function which
44    uses global data.  */
45 static inline Elf32_Addr
46 elf_machine_dynamic (void)
47 {
48   Elf32_Addr got_entry_0;
49   __asm__ __volatile__(
50     "lwi %0,r20,0"
51     :"=r"(got_entry_0)
52     );
53   return got_entry_0;
54 }
55
56
57 /* Return the run-time load address of the shared object.  */
58 static inline Elf32_Addr
59 elf_machine_load_address (void)
60 {
61   /* Compute the difference between the runtime address of _DYNAMIC as seen
62      by a GOTOFF reference, and the link-time address found in the special
63      unrelocated first GOT entry.  */
64   Elf32_Addr dyn;
65   __asm__ __volatile__ (
66     "addik %0,r20,_DYNAMIC@GOTOFF"
67     : "=r"(dyn)
68     );
69   return dyn - elf_machine_dynamic ();
70 }
71
72
73
74 static __always_inline void
75 elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr,
76                       Elf32_Word relative_count)
77 {
78         Elf32_Rel * rpnt = (void *) rel_addr;
79         do {
80                 Elf32_Addr *const reloc_addr = (void *) (load_off + (rpnt)->r_offset);
81
82                 *reloc_addr += load_off;
83         } while (--relative_count);
84 }