2 * Copyright (C) 2003 by Erik Andersen
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Library General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING.LIB. If not, see
16 * <http://www.gnu.org/licenses/>.
20 /* Integer registers. */
37 .type _start,%function
40 #ifndef __UCLIBC_CTOR_DTOR__
45 .type reloc_static_pie,%function
48 .type __uClibc_main,%function
51 mr r9,r1 /* Save the stack pointer and pass it to __uClibc_main */
52 clrrwi r1,r1,4 /* Align stack ptr to 16 bytes */
54 # ifdef HAVE_ASM_PPC_REL16
57 addis r31,r31,_GLOBAL_OFFSET_TABLE_-1b@ha
58 addi r31,r31,_GLOBAL_OFFSET_TABLE_-1b@l
60 bl _GLOBAL_OFFSET_TABLE_-4@local
63 /* in PIC/PIE, plt stubs need r30 to point to the GOT if using secure-plt */
64 # ifdef PPC_HAS_SECUREPLT
68 stwu r3, -4(r1) /* Save r3 */
69 stwu r9, -16(r1) /* Save r9 */
70 bcl 20,31,2f /* Jump to label 2 */
71 2: mflr r3 /* Load lr into r3 */
72 addis r3, r3, _DYNAMIC-2b@ha /* Add high half of _DYNAMIC to r3 */
73 addi r3,r3,_DYNAMIC-2b@l /* Add low half of _DYNAMIC */
74 lwz r4, 0(r31) /* load _DYNAMIC from the GOT */
75 subf r3, r4, r3 /* sub _DYNAMIC@got and it's actual address */
76 bl reloc_static_pie /* Call reloc_static_pie */
77 lwzu r9, 0(r1) /* restore r9 */
78 addi r1, r1, 16 /* update stack pointer */
79 lwzu r3, 0(r1) /* restore r3 */
80 addi r1, r1, 4 /* update stack pointer */
81 li r5, 0 /* zero r5 */
84 /* Set up the small data pointer in r13. */
86 lwz r13,_SDA_BASE_@got(r31)
89 addi r13,r13,_SDA_BASE_@l
91 /* Set up an initial stack frame, and clear the LR. */
96 /* find argc from the stack pointer */
98 /* find argv one word offset from the stack pointer */
100 mr r8,r3 /* Pass _dl_fini from ldso or NULL if statically linked */
101 /* Note: PPC depends on the kernel to zero r3 before */
102 /* handing over to user space, otherwise static apps */
103 /* will SEGV during exit() */
105 /* Ok, now run uClibc's main() -- shouldn't return */
107 lwz r6,_init@got(r31)
108 lwz r7,_fini@got(r31)
112 lis r6,_init@ha # load top 16 bits
113 addi r6,r6,_init@l # load bottom 16 bits
114 lis r7,_fini@ha # load top 16 bits
115 addi r7,r7,_fini@l # load bottom 16 bits
116 lis r3,main@ha # load top 16 bits
117 addi r3,r3,main@l # load bottom 16 bits
121 .size _start,.-_start
123 /* Define a symbol for the first piece of initialized data. */
129 data_start = __data_start