crt1.c revision 70657
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 * $FreeBSD: head/lib/csu/powerpc/crt1.c 70657 2001-01-04 10:25:59Z obrien $
41 */
42
43#ifndef __GNUC__
44#error "GCC is needed to compile this file"
45#endif
46
47#include <stdlib.h>
48#include "crtbrand.c"
49
50#pragma weak _DYNAMIC
51extern int _DYNAMIC;
52
53extern void _init(void);
54extern void _fini(void);
55extern int main(int, char **, char **);
56
57#ifdef GCRT
58extern void _mcleanup(void);
59extern void monstartup(void *, void *);
60extern int eprol;
61extern int etext;
62#endif
63
64/*
65 * First 5 arguments are specified by the PowerPC SVR4 ABI.
66 * The last argument, ps_strings, is a BSD extension.
67 */
68void _start __P((int, char **, char **, const Obj_Entry *,
69		void (*) __P((void)), struct ps_strings *));
70
71char **environ;
72char *__progname = "";
73
74/* The entry function. */
75void
76_start(argc, argv, envp, obj, cleanup, ps_strings)
77	int argc;
78	char **argv, **envp;
79	const Obj_Entry *obj;			/* from shared loader */
80	void (*cleanup) __P((void));		/* from shared loader */
81	struct ps_strings *ps_strings;		/* BSD extension */
82{
83	char *namep;
84
85	environ = envp;
86
87	if(argc > 0 && argv[0] != NULL) {
88		char *s;
89		__progname = argv[0];
90		for (s = __progname; *s != '\0'; s++)
91			if (*s == '/')
92				__progname = s + 1;
93	}
94
95	if (ps_strings != (struct ps_strings *)0)
96		__ps_strings = ps_strings;
97
98	if (&_DYNAMIC != NULL)
99		atexit(cleanup);
100
101#ifdef GCRT
102	atexit(_mcleanup);
103#endif
104	atexit(_fini);
105#ifdef GCRT
106	monstartup(&eprol, &etext);
107#endif
108	_init();
109	exit( main(argc, argv, env) );
110}
111
112#ifdef GCRT
113__asm__(".text");
114__asm__("eprol:");
115__asm__(".previous");
116#endif
117
118/*
119 * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
120 */
121#ifndef lint
122static const char rcsid[] =
123  "$FreeBSD: head/lib/csu/powerpc/crt1.c 70657 2001-01-04 10:25:59Z obrien $";
124#endif
125