]>
Commit | Line | Data |
---|---|---|
052b6a6c UD |
1 | /* Machine-dependent ELF startup code. PowerPC version. |
2 | Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. | |
3 | This file is part of the GNU C Library. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Library General Public License as | |
7 | published by the Free Software Foundation; either version 2 of the | |
8 | License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Library General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Library General Public | |
16 | License along with the GNU C Library; see the file COPYING.LIB. If not, | |
17 | write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
18 | Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include <sysdep.h> | |
21 | ||
22 | /* Initial entry point code for the dynamic linker. | |
23 | The C function `_dl_start' is the real entry point; | |
24 | its return value is the user program's entry point. */ | |
25 | ENTRY(_start) | |
26 | /* We start with the following on the stack, from top: | |
27 | argc (4 bytes); | |
28 | arguments for program (terminated by NULL); | |
29 | environment variables (terminated by NULL); | |
30 | arguments for the program loader. */ | |
31 | ||
32 | /* Call _dl_start with one parameter pointing at argc */ | |
33 | mr %r3,%r1 | |
34 | /* (we have to frob the stack pointer a bit to allow room for | |
35 | _dl_start to save the link register). */ | |
36 | li %r4,0 | |
37 | addi %r1,%r1,-16 | |
38 | stw %r4,0(%r1) | |
39 | bl _dl_start@local | |
40 | ||
41 | /* Now, we do our main work of calling initialisation procedures. | |
42 | The ELF ABI doesn't say anything about parameters for these, | |
43 | so we just pass argc, argv, and the environment. | |
44 | Changing these is strongly discouraged (not least because argc is | |
45 | passed by value!). */ | |
46 | ||
47 | /* Put our GOT pointer in r31, */ | |
48 | bl _GLOBAL_OFFSET_TABLE_-4@local | |
49 | mflr %r31 | |
50 | /* the address of _start in r30, */ | |
51 | mr %r30,%r3 | |
8e140239 UD |
52 | /* &_dl_argc in 29, &_dl_argv in 27, and _dl_main_searchlist in 28. */ |
53 | lwz %r28,_dl_main_searchlist@got(%r31) | |
052b6a6c UD |
54 | lwz %r29,_dl_argc@got(%r31) |
55 | lwz %r27,_dl_argv@got(%r31) | |
56 | 0: | |
8e140239 UD |
57 | /* Set initfunc = _dl_init_next(_dl_main_searchlist) */ |
58 | lwz %r3,0(%r28) | |
052b6a6c UD |
59 | bl _dl_init_next@plt |
60 | /* If initfunc is NULL, we exit the loop; otherwise, */ | |
61 | cmpwi %r3,0 | |
62 | beq 1f | |
63 | /* call initfunc(_dl_argc, _dl_argv, _dl_argv+_dl_argc+1) */ | |
64 | mtlr %r3 | |
65 | lwz %r3,0(%r29) | |
66 | lwz %r4,0(%r27) | |
67 | slwi %r5,%r3,2 | |
68 | add %r5,%r4,%r5 | |
69 | addi %r5,%r5,4 | |
70 | blrl | |
71 | /* and loop. */ | |
72 | b 0b | |
73 | 1: | |
74 | /* Now, to conform to the ELF ABI, we have to: */ | |
75 | /* Pass argc (actually _dl_argc) in r3; */ | |
76 | lwz %r3,0(%r29) | |
77 | /* pass argv (actually _dl_argv) in r4; */ | |
78 | lwz %r4,0(%r27) | |
79 | /* pass envp (actually _dl_argv+_dl_argc+1) in r5; */ | |
80 | slwi %r5,%r3,2 | |
81 | add %r6,%r4,%r5 | |
82 | addi %r5,%r6,4 | |
83 | /* pass the auxilary vector in r6. This is passed to us just after _envp. */ | |
84 | 2: lwzu %r0,4(%r6) | |
85 | cmpwi %r0,0 | |
86 | bne 2b | |
87 | addi %r6,%r6,4 | |
88 | /* Pass a termination function pointer (in this case _dl_fini) in r7. */ | |
89 | lwz %r7,_dl_fini@got(%r31) | |
90 | /* Now, call the start function in r30... */ | |
91 | mtctr %r30 | |
92 | lwz %r26,_dl_starting_up@got(%r31) | |
93 | /* Pass the stack pointer in r1 (so far so good), pointing to a NULL value. | |
94 | (This lets our startup code distinguish between a program linked statically, | |
95 | which linux will call with argc on top of the stack which will hopefully | |
96 | never be zero, and a dynamically linked program which will always have | |
97 | a NULL on the top of the stack). | |
98 | Take the opportunity to clear LR, so anyone who accidentally returns | |
99 | from _start gets SEGV. Also clear the next few words of the stack. */ | |
100 | ||
101 | li %r31,0 | |
102 | stw %r31,0(%r1) | |
103 | mtlr %r31 | |
104 | stw %r31,4(%r1) | |
105 | stw %r31,8(%r1) | |
106 | stw %r31,12(%r1) | |
107 | /* Clear _dl_starting_up. */ | |
108 | stw %r31,0(%r26) | |
109 | /* Go do it! */ | |
110 | bctr | |
111 | END(_start) |