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