2.9
[glibc/nacl-glibc.git] / sysdeps / powerpc / powerpc32 / elf / start.S
blobbafd2ae00109daa40b574abbb7bf8c0c8d7907a6
1 /* Startup code for programs linked with GNU libc.
2    Copyright (C) 1998,1999,2000,2001,2002,2003 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 Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    In addition to the permissions in the GNU Lesser General Public
11    License, the Free Software Foundation gives you unlimited
12    permission to link the compiled version of this file with other
13    programs, and to distribute those programs without any restriction
14    coming from the use of this file. (The GNU Lesser General Public
15    License restrictions do apply in other respects; for example, they
16    cover modification of the file, and distribution when not linked
17    into another program.)
19    Note that people who make modified versions of this file are not
20    obligated to grant this special exception for their modified
21    versions; it is their choice whether to do so. The GNU Lesser
22    General Public License gives permission to release a modified
23    version without this exception; this exception also makes it
24    possible to release a modified version which carries forward this
25    exception.
27    The GNU C Library is distributed in the hope that it will be useful,
28    but WITHOUT ANY WARRANTY; without even the implied warranty of
29    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
30    Lesser General Public License for more details.
32    You should have received a copy of the GNU Lesser General Public
33    License along with the GNU C Library; if not, write to the Free
34    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
35    02111-1307 USA.  */
37 #include <sysdep.h>
38 #include "bp-sym.h"
40  /* These are the various addresses we require.  */
41 #ifdef PIC
42         .section ".data"
43 #else
44         .section ".rodata"
45 #endif
46         .align  2
47 L(start_addresses):
48         .long   _SDA_BASE_
49         .long   BP_SYM (main)
50         .long   __libc_csu_init
51         .long   __libc_csu_fini
52         ASM_SIZE_DIRECTIVE(L(start_addresses))
54         .section ".text"
55 #if defined PIC && !defined HAVE_ASM_PPC_REL16
56 L(start_addressesp):
57         .long   L(start_addresses)-L(branch)
58 #endif
59 ENTRY(_start)
60  /* Save the stack pointer, in case we're statically linked under Linux.  */
61         mr      r9,r1
62  /* Set up an initial stack frame, and clear the LR.  */
63         clrrwi  r1,r1,4
64 #ifdef PIC
65         bcl     20,31,L(branch)
66 L(branch):
67         li      r0,0
68         mflr    r13
69 #else
70         li      r0,0
71 #endif
72         stwu    r1,-16(r1)
73         mtlr    r0
74         stw     r0,0(r1)
75  /* Set r13 to point at the 'small data area', and put the address of
76     start_addresses in r8.  Also load the GOT pointer so that new PLT
77     calls work, like the one to __libc_start_main.  */
78 #ifdef PIC
79 # ifdef HAVE_ASM_PPC_REL16
80         addis   r30,r13,_GLOBAL_OFFSET_TABLE_-L(branch)@ha
81         addis   r8,r13,L(start_addresses)-L(branch)@ha
82         addi    r30,r30,_GLOBAL_OFFSET_TABLE_-L(branch)@l
83         lwzu    r13,L(start_addresses)-L(branch)@l(r8)
84 # else
85         lwz     r8,L(start_addressesp)-L(branch)(r13)
86         add     r8,r13,r8
87         lwz     r13,0(r8)
88 # endif
89 #else
90         lis     r8,L(start_addresses)@ha
91         lwzu    r13,L(start_addresses)@l(r8)
92 #endif
93  /* and continue in libc-start, in glibc.  */
94         b       JUMPTARGET(BP_SYM (__libc_start_main))
95 END(_start)
97 /* Define a symbol for the first piece of initialized data.  */
98         .section ".data"
99         .globl  __data_start
100 __data_start:
101 weak_alias (__data_start, data_start)