]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/alpha/elf/start.S
596cea6265618eac7e8ca6dac0680772628245d3
[thirdparty/glibc.git] / sysdeps / alpha / elf / start.S
1 /* Startup code for Alpha/ELF.
2 Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
3 Contributed by Richard Henderson <rth@tamu.edu>
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
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
19
20 #include <sysdep.h>
21
22 .text
23 .globl _start /* what ELF wants */
24 .globl __start /* for backwards (ECOFF) comatibility */
25 .align 3
26 .ent __start, 0
27 _start:
28 __start:
29 .frame fp, 0, zero
30 mov zero, fp
31 br gp, 1f
32 1: ldgp gp, 0(gp)
33 .prologue 1
34
35 /* Save v0. When starting a binary via the dynamic linker, s0
36 contains the address of the shared library termination function,
37 which we will register below with atexit() to be called by exit().
38 If we are statically linked, this will be NULL. */
39 mov v0, s0
40
41 /* Do essential libc initialization (sp points to argc, argv, and envp) */
42 jsr ra, __libc_init_first
43 ldgp gp, 0(ra)
44
45 /* Now that we have the proper stack frame, register library termination
46 function, if there is any: */
47
48 beq s0, 1f
49 mov s0, a0
50 jsr ra, atexit
51 ldgp gp, 0(ra)
52 1:
53
54 /* Extract the arguments and environment as encoded on the stack. */
55 ldl a0, 0(sp) /* get argc */
56 lda a1, 8(sp) /* get argv */
57 s8addq a0, a1, a2 /* get envp */
58 addq a2, 8, a2
59 stq a2, _environ
60
61 mov a0, s0 /* tuck them away */
62 mov a1, s1
63 mov a2, s2
64
65 #ifdef HAVE_INITFINI
66 /* Call _init, the entry point to our own .init section. */
67 jsr ra, _init
68 ldgp gp, 0(ra)
69
70 /* Register our .fini section with atexit. */
71 lda a0, _fini
72 jsr ra, atexit
73 ldgp gp, 0(ra)
74 #else
75 /* initialize constructors: */
76 jsr ra, __main
77 ldgp gp, 0(ra)
78 #endif
79 mov s0, a0
80 mov s1, a1
81 mov s2, a2
82
83 /* Call the user's main and exit with its return value. */
84 jsr ra, main
85 ldgp gp, 0(ra)
86
87 mov v0, a0
88 jsr ra, exit
89
90 /* Die very horribly if exit returns. Call_pal hlt is callable from
91 kernel mode only; this will result in an illegal instruction trap. */
92 call_pal 0
93 END(__start)
94
95 /* Define a symbol for the first piece of initialized data. */
96 .data
97 .globl __data_start
98 __data_start:
99 .long 0
100
101 #ifdef __ELF__
102 .size __data_start, 4
103 .type __data_start, @object
104 #endif
105
106 weak_alias(__data_start, data_start)