crt1.c revision 80740
1161537Smarcel/*-
2161537Smarcel * Copyright 2001 David E. O'Brien.
3161537Smarcel * All rights reserved.
4161537Smarcel * Copyright 1996-1998 John D. Polstra.
5161537Smarcel * All rights reserved.
6161537Smarcel * Copyright (c) 1997 Jason R. Thorpe.
7161537Smarcel * Copyright (c) 1995 Christopher G. Demetriou
8161537Smarcel * All rights reserved.
9161537Smarcel *
10161537Smarcel * Redistribution and use in source and binary forms, with or without
11161537Smarcel * modification, are permitted provided that the following conditions
12161537Smarcel * are met:
13161537Smarcel * 1. Redistributions of source code must retain the above copyright
14161537Smarcel *    notice, this list of conditions and the following disclaimer.
15161537Smarcel * 2. Redistributions in binary form must reproduce the above copyright
16161537Smarcel *    notice, this list of conditions and the following disclaimer in the
17161537Smarcel *    documentation and/or other materials provided with the distribution.
18161537Smarcel * 3. All advertising materials mentioning features or use of this software
19161537Smarcel *    must display the following acknowledgement:
20161537Smarcel *          This product includes software developed for the
21161537Smarcel *          FreeBSD Project.  See http://www.freebsd.org/ for
22161537Smarcel *          information about FreeBSD.
23161537Smarcel *          This product includes software developed for the
24161537Smarcel *          NetBSD Project.  See http://www.netbsd.org/ for
25161537Smarcel *          information about NetBSD.
26161537Smarcel * 4. The name of the author may not be used to endorse or promote products
27161537Smarcel *    derived from this software without specific prior written permission
28161537Smarcel *
29161537Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30161537Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31161537Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32161537Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33161537Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34161537Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35161537Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36161537Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37161537Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38161537Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39161537Smarcel *
40161537Smarcel * $FreeBSD: head/lib/csu/powerpc/crt1.c 80740 2001-07-31 16:10:51Z mp $
41161537Smarcel */
42161537Smarcel
43161537Smarcel#ifndef __GNUC__
44161537Smarcel#error "GCC is needed to compile this file"
45161537Smarcel#endif
46161537Smarcel
47161537Smarcel#include <stdlib.h>
48161537Smarcel#include "crtbrand.c"
49161537Smarcel
50161537Smarcelstruct Struct_Obj_Entry;
51161537Smarcelstruct ps_strings;
52161537Smarcel
53161537Smarcel#pragma weak _DYNAMIC
54161537Smarcelextern int _DYNAMIC;
55161537Smarcel
56161537Smarcelextern void _init(void);
57161537Smarcelextern void _fini(void);
58161537Smarcelextern int main(int, char **, char **);
59161537Smarcel
60161537Smarcel#ifdef GCRT
61161537Smarcelextern void _mcleanup(void);
62161537Smarcelextern void monstartup(void *, void *);
63161537Smarcelextern int eprol;
64161537Smarcelextern int etext;
65161537Smarcel#endif
66161537Smarcel
67161537Smarcel/*
68161537Smarcel * First 5 arguments are specified by the PowerPC SVR4 ABI.
69161537Smarcel * The last argument, ps_strings, is a BSD extension.
70161537Smarcel */
71161537Smarcelvoid _start __P((int, char **, char **, const struct Struct_Obj_Entry *,
72161537Smarcel		void (*) __P((void)), struct ps_strings *));
73161537Smarcel
74161537Smarcelchar **environ;
75161537Smarcelchar *__progname = "";
76161537Smarcelstruct ps_strings *__ps_strings;
77161537Smarcel
78161537Smarcel/* The entry function. */
79161537Smarcelvoid
80161537Smarcel_start(argc, argv, envp, obj, cleanup, ps_strings)
81161537Smarcel	int argc;
82161537Smarcel	char **argv, **envp;
83161537Smarcel	const struct Struct_Obj_Entry *obj;	/* from shared loader */
84161537Smarcel	void (*cleanup) __P((void));		/* from shared loader */
85161537Smarcel	struct ps_strings *ps_strings;		/* BSD extension */
86161537Smarcel{
87161537Smarcel	char *namep;
88161537Smarcel
89161537Smarcel	environ = envp;
90161537Smarcel
91161537Smarcel	if(argc > 0 && argv[0] != NULL) {
92161537Smarcel		char *s;
93161537Smarcel		__progname = argv[0];
94161537Smarcel		for (s = __progname; *s != '\0'; s++)
95161537Smarcel			if (*s == '/')
96161537Smarcel				__progname = s + 1;
97161537Smarcel	}
98161537Smarcel
99161537Smarcel	if (ps_strings != (struct ps_strings *)0)
100161537Smarcel		__ps_strings = ps_strings;
101161537Smarcel
102161537Smarcel	if (&_DYNAMIC != NULL)
103161537Smarcel		atexit(cleanup);
104161537Smarcel
105161537Smarcel#ifdef GCRT
106161537Smarcel	atexit(_mcleanup);
107161537Smarcel#endif
108161537Smarcel	atexit(_fini);
109161537Smarcel#ifdef GCRT
110161537Smarcel	monstartup(&eprol, &etext);
111161537Smarcel#endif
112161537Smarcel	_init();
113161537Smarcel	exit( main(argc, argv, envp) );
114161537Smarcel}
115161537Smarcel
116161537Smarcel#ifdef GCRT
117161537Smarcel__asm__(".text");
118161537Smarcel__asm__("eprol:");
119161537Smarcel__asm__(".previous");
120161537Smarcel#endif
121161537Smarcel
122161537Smarcel/*
123161537Smarcel * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
124161537Smarcel */
125161537Smarcel#ifndef lint
126161537Smarcelstatic const char rcsid[] =
127161537Smarcel  "$FreeBSD: head/lib/csu/powerpc/crt1.c 80740 2001-07-31 16:10:51Z mp $";
128161537Smarcel#endif
129161537Smarcel