OSDN Git Service

0161554734230898922bf434ea74b4ac4def06c8
[uclinux-h8/uClibc.git] / ldso / ldso / arc / dl-startup.h
1 /*
2  * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
3  *
4  * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
5  */
6
7 /*
8  * vineetg: Refactoring/cleanup of loader entry point
9  *  Removed 6 useless insns
10  * Joern Improved it even further:
11  *  -better insn scheduling
12  *  -no need for conditional code for _dl_skip_args
13  *  -use of assembler .&2 expressions vs. @gotpc refs (avoids need for GP)
14  *
15  * What this code does:
16  *  -ldso starts execution here when kernel returns from execve()
17  *  -calls into generic ldso entry point _dl_start( )
18  *  -optionally adjusts argc for executable if exec passed as cmd
19  *  -calls into app main with address of finaliser
20  */
21 __asm__(
22     ".section .text                                             \n"
23     ".align 4                                                   \n"
24     ".global _start                                             \n"
25     ".hidden _start                                             \n"
26     ".type  _start,@function                                    \n"
27
28     "_start:                                                    \n"
29     "   ; ldso entry point, returns app entry point             \n"
30     "   bl.d    _dl_start                                       \n"
31     "   mov_s   r0, sp          ; pass ptr to aux vector tbl    \n"
32
33     "   ; If ldso ran as cmd with executable file nm as arg     \n"
34     "   ; skip the extra args calc by dl_start()                \n"
35     "   ld_s    r1, [sp]       ; orig argc from aux-vec Tbl     \n"
36 #ifdef STAR_9000535888_FIXED
37     "   ld      r12, [pcl, _dl_skip_args-.+(.&2)]               \n"
38 #else
39     "   add     r12, pcl, _dl_skip_args-.+(.&2)                 \n"
40     "   ld      r12, [r12]                                      \n"
41 #endif
42
43     "   add     r2, pcl, _dl_fini-.+(.&2)   ; finalizer         \n"
44
45     "   add2    sp, sp, r12    ; discard argv entries from stack\n"
46     "   sub_s   r1, r1, r12    ; adjusted argc, on stack        \n"
47     "   st_s    r1, [sp]                                        \n"
48
49     "   j_s.d   [r0]           ; app entry point                \n"
50     "   mov_s   r0, r2         ; ptr to finalizer _dl_fini      \n"
51
52     ".size  _start,.-_start                                     \n"
53     ".previous                                                  \n"
54 );
55
56 /*
57  * Get a pointer to the argv array.  On many platforms this can be just
58  * the address if the first argument, on other platforms we need to
59  * do something a little more subtle here.
60  */
61 #define GET_ARGV(ARGVP, ARGS) ARGVP = ((unsigned long*) ARGS + 1)
62
63 /*
64  * Dynamic loader bootstrapping:
65  * Since we don't modify text at runtime, these can only be data relos
66  * (so safe to assume that they are word aligned).
67  * And also they HAVE to be RELATIVE relos only
68  * @RELP is the relo entry being processed
69  * @REL is the pointer to the address we are relocating.
70  * @SYMBOL is the symbol involved in the relocation
71  * @LOAD is the load address.
72  */
73
74 #define PERFORM_BOOTSTRAP_RELOC(RELP,REL,SYMBOL,LOAD,SYMTAB)            \
75 do {                                                                    \
76         int type = ELF32_R_TYPE((RELP)->r_info);                        \
77         if (likely(type == R_ARC_RELATIVE))                             \
78                 *REL += (unsigned long) LOAD;                           \
79         else                                                            \
80                 _dl_exit(1);                                            \
81 }while(0)
82
83 /*
84  * This will go away once we have DT_RELACOUNT
85  */
86 #define ARCH_NEEDS_BOOTSTRAP_RELOCS
87
88 /* we dont need to spit out argc, argv etc for debugging */
89 #define NO_EARLY_SEND_STDERR    1