blob: 4f1494a8f3ab7878142998797f8b0e6846da29cd [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * Copyright (C) 2003 by Erik Andersen
3 *
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.
8 *
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
12 * for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include <features.h>
20/* Integer registers. */
21#define r0 0
22#define r1 1
23#define r2 2
24#define r3 3
25#define r4 4
26#define r5 5
27#define r6 6
28#define r7 7
29#define r8 8
30#define r9 9
31#define r10 10
32#define r13 13
33#define r31 31
34
35.text
36 .globl _start
37 .type _start,%function
38 .type _init,%function
39 .type _fini,%function
40#ifndef __UCLIBC_CTOR_DTOR__
41 .weak _init
42 .weak _fini
43#endif
44 .type main,%function
45 .type __uClibc_main,%function
46
47_start:
48 mr r9,r1 /* Save the stack pointer and pass it to __uClibc_main */
49 clrrwi r1,r1,4 /* Align stack ptr to 16 bytes */
50#ifdef __PIC__
51# ifdef HAVE_ASM_PPC_REL16
52 bcl 20,31,1f
531: mflr r31
54 addis r31,r31,_GLOBAL_OFFSET_TABLE_-1b@ha
55 addi r31,r31,_GLOBAL_OFFSET_TABLE_-1b@l
56# else
57 bl _GLOBAL_OFFSET_TABLE_-4@local
58 mflr r31
59# endif
60#endif
61 /* Set up the small data pointer in r13. */
62#ifdef __PIC__
63 lwz r13,_SDA_BASE_@got(r31)
64#else
65 lis r13,_SDA_BASE_@ha
66 addi r13,r13,_SDA_BASE_@l
67#endif
68 /* Set up an initial stack frame, and clear the LR. */
69 li r0,0
70 stwu r1,-16(r1)
71 mtlr r0
72 stw r0,0(r1)
73 /* find argc from the stack pointer */
74 lwz r4,0(r9)
75 /* find argv one word offset from the stack pointer */
76 addi r5,r9,4
77 mr r8,r3 /* Pass _dl_fini from ldso or NULL if statically linked */
78 /* Note: PPC depends on the kernel to zero r3 before */
79 /* handing over to user space, otherwise static apps */
80 /* will SEGV during exit() */
81
82 /* Ok, now run uClibc's main() -- shouldn't return */
83#ifdef __PIC__
84 lwz r6,_init@got(r31)
85 lwz r7,_fini@got(r31)
86 lwz r3,main@got(r31)
87 b __uClibc_main@plt
88#else
89 lis r6,_init@ha # load top 16 bits
90 addi r6,r6,_init@l # load bottom 16 bits
91 lis r7,_fini@ha # load top 16 bits
92 addi r7,r7,_fini@l # load bottom 16 bits
93 lis r3,main@ha # load top 16 bits
94 addi r3,r3,main@l # load bottom 16 bits
95 b __uClibc_main
96#endif
97
98.size _start,.-_start
99
100/* Define a symbol for the first piece of initialized data. */
101 .data
102 .globl __data_start
103__data_start:
104 .long 0
105 .weak data_start
106 data_start = __data_start
107