]>
Commit | Line | Data |
---|---|---|
df27fae1 UD |
1 | /* Startup code for ARM & ELF |
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 | /* This is the canonical entry point, usually the first thing in the text | |
21 | segment. | |
22 | ||
23 | Note that the code in the .init section has already been run. | |
24 | This includes _init and _libc_init | |
25 | ||
26 | ||
27 | At this entry point, most registers' values are unspecified, except for: | |
28 | ||
29 | r0 Contains a function pointer to be registered with `atexit'. | |
30 | This is how the dynamic linker arranges to have DT_FINI | |
31 | functions called for shared libraries that have been loaded | |
32 | before this code runs. | |
33 | ||
34 | sp The stack contains the arguments and environment: | |
35 | 0(%esp) argc | |
36 | 4(%esp) argv[0] | |
37 | ... | |
38 | (4*argc)(%esp) NULL | |
39 | (4*(argc+1))(%esp) envp[0] | |
40 | ... | |
41 | NULL | |
42 | */ | |
43 | ||
44 | .text | |
45 | .globl _start | |
46 | _start: | |
47 | /* Clear the frame pointer. The Intel ABI suggests this be done, | |
48 | to mark the outermost frame obviously. This seems like a | |
49 | sensible thing to do */ | |
50 | mov fp, #0 | |
51 | ||
52 | /* r0 contains the address of the shared library termination | |
53 | function, which we will register with `atexit' to be called by | |
54 | `exit'. I suspect that on some systems, and when statically | |
55 | linked, this will not be set by anything to any function | |
56 | pointer; hopefully it will be zero so we don't try to call | |
57 | random pointers. */ | |
58 | cmp r0,#0 | |
59 | blne atexit(PLT) | |
60 | ||
61 | /* Do essential libc initialization. In statically linked | |
62 | programs under the GNU Hurd, this is what sets up the | |
63 | arguments on the stack for the code below. For dyn-link | |
64 | programs, this has been run already, in the .init code. */ | |
65 | #ifndef PIC | |
66 | bl __libc_init_first | |
67 | ||
68 | /* Extract the arguments and environment as encoded on the stack | |
69 | and set up the arguments for `main': argc, argv, envp. */ | |
70 | ldr r0,[sp] | |
71 | add r1,sp,#4 | |
72 | add r2,r1,r0,lsl #2 | |
73 | add r2,r2,#4 | |
74 | /* save a copy of envp while we have it */ | |
75 | ldr r3,L_environ | |
76 | str r2,[r3] | |
77 | ||
78 | /* Call `_init', which is the entry point to our own `.init' | |
79 | section; and register with `atexit' to have `exit' call | |
80 | `_fini', which is the entry point to our own `.fini' section. */ | |
81 | bl _init | |
82 | ldr r0,L_fini | |
83 | bl atexit | |
84 | b L_pfini | |
85 | ||
86 | L_fini: .word _fini | |
87 | L_environ: .word _environ | |
88 | L_pfini: | |
89 | #endif | |
90 | /* rebuild the arg list for main() */ | |
91 | ldr r0,[sp] | |
92 | add r1,sp,#4 | |
93 | add r2,r1,r0,lsl #2 | |
94 | add r2,r2,#4 | |
95 | ||
96 | /* Call the user's main function, and exit with its value. */ | |
97 | bl main | |
98 | bl exit | |
99 | /* should never get here....*/ | |
100 | bl abort | |
101 | ||
102 | ||
103 | /* Define a symbol for the first piece of initialized data. */ | |
104 | .data | |
105 | .globl __data_start | |
106 | __data_start: | |
107 | .long 0 | |
108 | .weak data_start | |
109 | data_start = __data_start |