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