]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/ldso/ldso/bfin/dl-startup.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / ldso / ldso / bfin / dl-startup.h
1      /* Copyright (C) 2003 Red Hat, Inc.
2         Contributed by Alexandre Oliva <aoliva@redhat.com>
3
4 This file is part of uClibc.
5
6 uClibc is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 uClibc is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with uClibc; see the file COPYING.LIB.  If not, see
18 <http://www.gnu.org/licenses/>.  */
19
20 /* Any assembly language/system dependent hacks needed to setup
21  * boot1.c so it will work as expected and cope with whatever platform
22  * specific wierdness is needed for this architecture.
23  */
24
25 /* At program start-up, p0 contains a pointer to a
26    elf32_fdpic_loadmap that describes how the executable was loaded
27    into memory.  p1 contains a pointer to the interpreter (our!)
28    loadmap, if there is an interpreter, or 0 if we're being run as an
29    executable.  p2 holds a pointer to the interpreter's dynamic
30    section, if there is an interpreter, or to the executable's dynamic
31    section, otherwise.  If the executable is not dynamic, gr18 is 0.
32
33    We rely on the fact that the linker adds a pointer to the
34    _GLOBAL_OFFSET_TABLE_ as the last ROFIXUP entry, and that
35    __self_reloc returns the relocated pointer to us, so that we can
36    use this value to initialize the PIC register.  */
37
38 __asm__(
39         "       .text\n"
40         "       .global __start\n"
41         "       .type   __start,@function\n"
42         "       .hidden __start\n"
43         "__start:\n"
44         "       call    .Lcall\n"
45         ".Lcall:\n"
46         "       R4 = RETS;\n"
47         "       SP += -32;\n"
48         "       R5 = P0;\n"
49         "       R6 = P1;\n"
50         "       R7 = P2;\n"
51         "       R0.L = .Lcall;\n"
52         "       R0.H = .Lcall;\n"
53         "       R1.L = __ROFIXUP_LIST__;\n"
54         "       R1.H = __ROFIXUP_LIST__;\n"
55         "       R2.L = __ROFIXUP_END__;\n"
56         "       R2.H = __ROFIXUP_END__;\n"
57         "       R1 = R1 - R0;\n"
58         "       R1 = R1 + R4;\n"
59         "       R2 = R2 - R0;\n"
60         "       R2 = R2 + R4;\n"
61         "       R0 = P1;\n"
62         "       CC = R0 == 0;\n"
63         "       IF CC R0 = P0;\n"
64         "       CALL    ___self_reloc;\n"
65         "       P3 = R0;\n"
66         "       P5 = R0;\n"
67         "       R1 = R5;\n"
68         "       R2 = R6;\n"
69         "       [SP + 12] = R7;\n"
70         "       P0 = SP;\n"
71         "       P0 += 24;\n"
72         "       [SP + 16] = P0;\n"
73         "       P0 += 8;\n"
74         "       [SP + 20] = P0;\n"
75         "       CALL    __dl_start;\n"
76         "       /* Pass our FINI ptr() to the user in P1 */\n"
77         "       R7 = [P5 + __dl_fini@FUNCDESC_GOT17M4];\n"
78         "       P4 = [SP + 24];\n"
79         "       P3 = [SP + 28];\n"
80         "       P0 = R5;\n"
81         "       SP += 32;\n"
82         "       JUMP (P4);\n"
83         "       .size   __start,.-__start\n"
84 );
85
86 #undef DL_START
87 #define DL_START(X)   \
88 static void  __attribute__ ((used)) \
89 _dl_start (Elf32_Addr dl_boot_got_pointer, \
90            struct elf32_fdpic_loadmap *dl_boot_progmap, \
91            struct elf32_fdpic_loadmap *dl_boot_ldsomap, \
92            Elf32_Dyn *dl_boot_ldso_dyn_pointer, \
93            struct funcdesc_value *dl_main_funcdesc, \
94            X)
95
96 /*
97  * Get a pointer to the argv array.  On many platforms this can be just
98  * the address of the first argument, on other platforms we need to
99  * do something a little more subtle here.
100  */
101 #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS) + 1)
102
103 /*
104  * Here is a macro to perform a relocation.  This is only used when
105  * bootstrapping the dynamic loader.  RELP is the relocation that we
106  * are performing, REL is the pointer to the address we are relocating.
107  * SYMBOL is the symbol involved in the relocation, and LOAD is the
108  * load address.
109  */
110 #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB) \
111         switch(ELF_R_TYPE((RELP)->r_info)){                             \
112         case R_BFIN_BYTE4_DATA:                                                 \
113           *(REL) += (SYMBOL);                                           \
114           break;                                                        \
115         case R_BFIN_FUNCDESC_VALUE:                                     \
116           {                                                             \
117             struct funcdesc_value fv = {                                \
118               (void*)((SYMBOL) + *(REL)),                               \
119               (LOAD).got_value                                          \
120             };                                                          \
121             *(struct funcdesc_value volatile *)(REL) = fv;              \
122             break;                                                      \
123           }                                                             \
124         default:                                                        \
125           _dl_exit(1);                                                  \
126         }
127
128 /*
129  * Transfer control to the user's application, once the dynamic loader
130  * is done.  We return the address of the function's entry point to
131  * _dl_boot, see boot1_arch.h.
132  */
133 #define START() do {                                                    \
134   struct elf_resolve *exec_mod = _dl_loaded_modules;                    \
135   dl_main_funcdesc->entry_point = _dl_elf_main;                         \
136   while (exec_mod->libtype != elf_executable)                           \
137     exec_mod = exec_mod->next;                                          \
138   dl_main_funcdesc->got_value = exec_mod->loadaddr.got_value;           \
139   return;                                                               \
140 } while (0)