xref: /freebsd/lib/csu/aarch64/crt1_c.c (revision 99282790b7d01ec3c4072621d46a0d7302517ad4)
1*99282790SJohn Baldwin /* LINTLIBRARY */
2*99282790SJohn Baldwin /*-
3*99282790SJohn Baldwin  * Copyright 1996-1998 John D. Polstra.
4*99282790SJohn Baldwin  * Copyright 2014 Andrew Turner.
5*99282790SJohn Baldwin  * Copyright 2014-2015 The FreeBSD Foundation.
6*99282790SJohn Baldwin  * All rights reserved.
7*99282790SJohn Baldwin  *
8*99282790SJohn Baldwin  * Portions of this software were developed by Andrew Turner
9*99282790SJohn Baldwin  * under sponsorship from the FreeBSD Foundation.
10*99282790SJohn Baldwin  *
11*99282790SJohn Baldwin  * Redistribution and use in source and binary forms, with or without
12*99282790SJohn Baldwin  * modification, are permitted provided that the following conditions
13*99282790SJohn Baldwin  * are met:
14*99282790SJohn Baldwin  * 1. Redistributions of source code must retain the above copyright
15*99282790SJohn Baldwin  *    notice, this list of conditions and the following disclaimer.
16*99282790SJohn Baldwin  * 2. Redistributions in binary form must reproduce the above copyright
17*99282790SJohn Baldwin  *    notice, this list of conditions and the following disclaimer in the
18*99282790SJohn Baldwin  *    documentation and/or other materials provided with the distribution.
19*99282790SJohn Baldwin  *
20*99282790SJohn Baldwin  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21*99282790SJohn Baldwin  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22*99282790SJohn Baldwin  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23*99282790SJohn Baldwin  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24*99282790SJohn Baldwin  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25*99282790SJohn Baldwin  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*99282790SJohn Baldwin  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*99282790SJohn Baldwin  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*99282790SJohn Baldwin  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29*99282790SJohn Baldwin  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*99282790SJohn Baldwin  */
31*99282790SJohn Baldwin 
32*99282790SJohn Baldwin #include <sys/cdefs.h>
33*99282790SJohn Baldwin __FBSDID("$FreeBSD$");
34*99282790SJohn Baldwin 
35*99282790SJohn Baldwin #include <stdlib.h>
36*99282790SJohn Baldwin 
37*99282790SJohn Baldwin #include "libc_private.h"
38*99282790SJohn Baldwin #include "ignore_init.c"
39*99282790SJohn Baldwin 
40*99282790SJohn Baldwin #ifdef GCRT
41*99282790SJohn Baldwin extern void _mcleanup(void);
42*99282790SJohn Baldwin extern void monstartup(void *, void *);
43*99282790SJohn Baldwin extern int eprol;
44*99282790SJohn Baldwin extern int etext;
45*99282790SJohn Baldwin #endif
46*99282790SJohn Baldwin 
47*99282790SJohn Baldwin extern long * _end;
48*99282790SJohn Baldwin 
49*99282790SJohn Baldwin void __start(int, char **, char **, void (*)(void));
50*99282790SJohn Baldwin 
51*99282790SJohn Baldwin /* The entry function. */
52*99282790SJohn Baldwin void
53*99282790SJohn Baldwin __start(int argc, char *argv[], char *env[], void (*cleanup)(void))
54*99282790SJohn Baldwin {
55*99282790SJohn Baldwin 
56*99282790SJohn Baldwin 	handle_argv(argc, argv, env);
57*99282790SJohn Baldwin 
58*99282790SJohn Baldwin 	if (&_DYNAMIC != NULL)
59*99282790SJohn Baldwin 		atexit(cleanup);
60*99282790SJohn Baldwin 	else
61*99282790SJohn Baldwin 		_init_tls();
62*99282790SJohn Baldwin 
63*99282790SJohn Baldwin #ifdef GCRT
64*99282790SJohn Baldwin 	atexit(_mcleanup);
65*99282790SJohn Baldwin 	monstartup(&eprol, &etext);
66*99282790SJohn Baldwin __asm__("eprol:");
67*99282790SJohn Baldwin #endif
68*99282790SJohn Baldwin 
69*99282790SJohn Baldwin 	handle_static_init(argc, argv, env);
70*99282790SJohn Baldwin 	exit(main(argc, argv, env));
71*99282790SJohn Baldwin }
72