crt1.c revision 204756
1/* LINTLIBRARY */
2/*-
3 * Copyright 2001 David E. O'Brien.
4 * All rights reserved.
5 * Copyright 1996-1998 John D. Polstra.
6 * All rights reserved.
7 * Copyright (c) 1997 Jason R. Thorpe.
8 * Copyright (c) 1995 Christopher G. Demetriou
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgement:
21 *          This product includes software developed for the
22 *          FreeBSD Project.  See http://www.freebsd.org/ for
23 *          information about FreeBSD.
24 *          This product includes software developed for the
25 *          NetBSD Project.  See http://www.netbsd.org/ for
26 *          information about NetBSD.
27 * 4. The name of the author may not be used to endorse or promote products
28 *    derived from this software without specific prior written permission
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
31 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef lint
43#ifndef __GNUC__
44#error "GCC is needed to compile this file"
45#endif
46#endif /* lint */
47
48#include <stdlib.h>
49
50#include "libc_private.h"
51#include "crtbrand.c"
52
53struct Struct_Obj_Entry;
54struct ps_strings;
55
56extern int _DYNAMIC;
57#pragma weak _DYNAMIC
58
59extern void _fini(void);
60extern void _init(void);
61extern int main(int, char **, char **);
62
63#ifdef GCRT
64extern void _mcleanup(void);
65extern void monstartup(void *, void *);
66extern int eprol;
67extern int etext;
68#endif
69
70char **environ;
71const char *__progname = "";
72struct ps_strings *__ps_strings;
73
74void _start(int, char **, char **, const struct Struct_Obj_Entry *,
75    void (*)(void), struct ps_strings *);
76
77/* The entry function. */
78/*
79 * First 5 arguments are specified by the PowerPC SVR4 ABI.
80 * The last argument, ps_strings, is a BSD extension.
81 */
82/* ARGSUSED */
83void
84_start(int argc, char **argv, char **env,
85    const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void),
86    struct ps_strings *ps_strings)
87{
88	const char *s;
89
90	environ = env;
91
92	if (argc > 0 && argv[0] != NULL) {
93		__progname = argv[0];
94		for (s = __progname; *s != '\0'; s++)
95			if (*s == '/')
96				__progname = s + 1;
97	}
98
99	if (ps_strings != (struct ps_strings *)0)
100		__ps_strings = ps_strings;
101
102	if (&_DYNAMIC != NULL)
103		atexit(cleanup);
104	else
105		_init_tls();
106
107#ifdef GCRT
108	atexit(_mcleanup);
109#endif
110	atexit(_fini);
111#ifdef GCRT
112	monstartup(&eprol, &etext);
113#endif
114	_init();
115	exit( main(argc, argv, env) );
116}
117
118#ifdef GCRT
119__asm__(".text");
120__asm__("eprol:");
121__asm__(".previous");
122#endif
123
124__asm__(".ident\t\"$FreeBSD: head/lib/csu/powerpc/crt1.c 204756 2010-03-05 13:28:05Z uqs $\"");
125