1 /* LINTLIBRARY */
2 /*-
3  * SPDX-License-Identifier: BSD-3-Clause
4  *
5  * Copyright 2001 David E. O'Brien.
6  * All rights reserved.
7  * Copyright (c) 1995, 1998 Berkeley Software Design, Inc.
8  * All rights reserved.
9  * Copyright 1996-1998 John D. Polstra.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. The name of the authors may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD: stable/12/lib/csu/sparc64/crt1.c 326219 2017-11-26 02:00:33Z pfg $");
37 
38 #include <stdlib.h>
39 
40 #include "libc_private.h"
41 #include "crtbrand.c"
42 #include "ignore_init.c"
43 
44 struct Struct_Obj_Entry;
45 struct ps_strings;
46 
47 extern void __sparc_utrap_setup(void);
48 
49 #ifdef GCRT
50 extern void _mcleanup(void);
51 extern void monstartup(void *, void *);
52 extern int eprol;
53 extern int etext;
54 #endif
55 
56 void _start(char **, void (*)(void), struct Struct_Obj_Entry *,
57     struct ps_strings *);
58 
59 /* The entry function. */
60 /*
61  * %o0 holds ps_strings pointer.
62  *
63  * Note: kernel may (is not set in stone yet) pass ELF aux vector in %o1,
64  * but for now we do not use it here.
65  *
66  * The SPARC compliance definitions specifies that the kernel pass the
67  * address of a function to be executed on exit in %g1. We do not make
68  * use of it as it is quite broken, because gcc can use this register
69  * as a temporary, so it is not safe from C code. Its even more broken
70  * for dynamic executables since rtld runs first.
71  */
72 /* ARGSUSED */
73 void
_start(char ** ap,void (* cleanup)(void),struct Struct_Obj_Entry * obj __unused,struct ps_strings * ps_strings __unused)74 _start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused,
75     struct ps_strings *ps_strings __unused)
76 {
77 	int argc;
78 	char **argv;
79 	char **env;
80 
81 	argc = *(long *)(void *)ap;
82 	argv = ap + 1;
83 	env  = ap + 2 + argc;
84 	handle_argv(argc, argv, env);
85 
86 	if (&_DYNAMIC != NULL)
87 		atexit(cleanup);
88 	else {
89 		__sparc_utrap_setup();
90 		_init_tls();
91 	}
92 #ifdef GCRT
93 	atexit(_mcleanup);
94 	monstartup(&eprol, &etext);
95 #endif
96 
97 	handle_static_init(argc, argv, env);
98 	exit(main(argc, argv, env));
99 }
100 
101 #ifdef GCRT
102 __asm__(".text");
103 __asm__("eprol:");
104 __asm__(".previous");
105 #endif
106