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.
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.
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.
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. */
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. */
26 /* We start with the following on the stack, from top:
28 arguments for program (terminated by NULL);
29 environment variables (terminated by NULL);
30 arguments for the program loader. */
32 /* Call _dl_start with one parameter pointing at argc */
34 /* (we have to frob the stack pointer a bit to allow room for
35 _dl_start to save the link register). */
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
47 /* Put our GOT pointer in r31, */
48 bl _GLOBAL_OFFSET_TABLE_-4@local
50 /* the address of _start in r30, */
52 /* &_dl_argc in 29, &_dl_argv in 27, and _dl_main_searchlist in 28. */
53 lwz %r28,_dl_main_searchlist@got(%r31)
54 lwz %r29,_dl_argc@got(%r31)
55 lwz %r27,_dl_argv@got(%r31)
57 /* Set initfunc = _dl_init_next(_dl_main_searchlist) */
60 /* If initfunc is NULL, we exit the loop; otherwise, */
63 /* call initfunc(_dl_argc, _dl_argv, _dl_argv+_dl_argc+1) */
74 /* Now, to conform to the ELF ABI, we have to: */
75 /* Pass argc (actually _dl_argc) in r3; */
77 /* pass argv (actually _dl_argv) in r4; */
79 /* pass envp (actually _dl_argv+_dl_argc+1) in r5; */
83 /* pass the auxilary vector in r6. This is passed to us just after _envp. */
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... */
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. */
107 /* Clear _dl_starting_up. */