crt1.c revision 80740
170657Sobrien/*-
270657Sobrien * Copyright 2001 David E. O'Brien.
370657Sobrien * All rights reserved.
470657Sobrien * Copyright 1996-1998 John D. Polstra.
570657Sobrien * All rights reserved.
670657Sobrien * Copyright (c) 1997 Jason R. Thorpe.
770657Sobrien * Copyright (c) 1995 Christopher G. Demetriou
870657Sobrien * All rights reserved.
970657Sobrien *
1070657Sobrien * Redistribution and use in source and binary forms, with or without
1170657Sobrien * modification, are permitted provided that the following conditions
1270657Sobrien * are met:
1370657Sobrien * 1. Redistributions of source code must retain the above copyright
1470657Sobrien *    notice, this list of conditions and the following disclaimer.
1570657Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1670657Sobrien *    notice, this list of conditions and the following disclaimer in the
1770657Sobrien *    documentation and/or other materials provided with the distribution.
1870657Sobrien * 3. All advertising materials mentioning features or use of this software
1970657Sobrien *    must display the following acknowledgement:
2070657Sobrien *          This product includes software developed for the
2170657Sobrien *          FreeBSD Project.  See http://www.freebsd.org/ for
2270657Sobrien *          information about FreeBSD.
2370657Sobrien *          This product includes software developed for the
2470657Sobrien *          NetBSD Project.  See http://www.netbsd.org/ for
2570657Sobrien *          information about NetBSD.
2670657Sobrien * 4. The name of the author may not be used to endorse or promote products
2770657Sobrien *    derived from this software without specific prior written permission
2870657Sobrien *
2970657Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
3070657Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3170657Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
3270657Sobrien * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
3370657Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3470657Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3570657Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3670657Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3770657Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3870657Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3970657Sobrien *
4070657Sobrien * $FreeBSD: head/lib/csu/powerpc/crt1.c 80740 2001-07-31 16:10:51Z mp $
4170657Sobrien */
4270657Sobrien
4370657Sobrien#ifndef __GNUC__
4470657Sobrien#error "GCC is needed to compile this file"
4570657Sobrien#endif
4670657Sobrien
4770657Sobrien#include <stdlib.h>
4870657Sobrien#include "crtbrand.c"
4970657Sobrien
5080740Smpstruct Struct_Obj_Entry;
5180740Smpstruct ps_strings;
5280740Smp
5370657Sobrien#pragma weak _DYNAMIC
5470657Sobrienextern int _DYNAMIC;
5570657Sobrien
5670657Sobrienextern void _init(void);
5770657Sobrienextern void _fini(void);
5870657Sobrienextern int main(int, char **, char **);
5970657Sobrien
6070657Sobrien#ifdef GCRT
6170657Sobrienextern void _mcleanup(void);
6270657Sobrienextern void monstartup(void *, void *);
6370657Sobrienextern int eprol;
6470657Sobrienextern int etext;
6570657Sobrien#endif
6670657Sobrien
6770657Sobrien/*
6870657Sobrien * First 5 arguments are specified by the PowerPC SVR4 ABI.
6970657Sobrien * The last argument, ps_strings, is a BSD extension.
7070657Sobrien */
7180740Smpvoid _start __P((int, char **, char **, const struct Struct_Obj_Entry *,
7270657Sobrien		void (*) __P((void)), struct ps_strings *));
7370657Sobrien
7470657Sobrienchar **environ;
7570657Sobrienchar *__progname = "";
7680740Smpstruct ps_strings *__ps_strings;
7770657Sobrien
7870657Sobrien/* The entry function. */
7970657Sobrienvoid
8070657Sobrien_start(argc, argv, envp, obj, cleanup, ps_strings)
8170657Sobrien	int argc;
8270657Sobrien	char **argv, **envp;
8380740Smp	const struct Struct_Obj_Entry *obj;	/* from shared loader */
8470657Sobrien	void (*cleanup) __P((void));		/* from shared loader */
8570657Sobrien	struct ps_strings *ps_strings;		/* BSD extension */
8670657Sobrien{
8770657Sobrien	char *namep;
8870657Sobrien
8970657Sobrien	environ = envp;
9070657Sobrien
9170657Sobrien	if(argc > 0 && argv[0] != NULL) {
9270657Sobrien		char *s;
9370657Sobrien		__progname = argv[0];
9470657Sobrien		for (s = __progname; *s != '\0'; s++)
9570657Sobrien			if (*s == '/')
9670657Sobrien				__progname = s + 1;
9770657Sobrien	}
9870657Sobrien
9970657Sobrien	if (ps_strings != (struct ps_strings *)0)
10070657Sobrien		__ps_strings = ps_strings;
10170657Sobrien
10270657Sobrien	if (&_DYNAMIC != NULL)
10370657Sobrien		atexit(cleanup);
10470657Sobrien
10570657Sobrien#ifdef GCRT
10670657Sobrien	atexit(_mcleanup);
10770657Sobrien#endif
10870657Sobrien	atexit(_fini);
10970657Sobrien#ifdef GCRT
11070657Sobrien	monstartup(&eprol, &etext);
11170657Sobrien#endif
11270657Sobrien	_init();
11380740Smp	exit( main(argc, argv, envp) );
11470657Sobrien}
11570657Sobrien
11670657Sobrien#ifdef GCRT
11770657Sobrien__asm__(".text");
11870657Sobrien__asm__("eprol:");
11970657Sobrien__asm__(".previous");
12070657Sobrien#endif
12170657Sobrien
12270657Sobrien/*
12370657Sobrien * NOTE: Leave the RCS ID _after_ __start(), in case it gets placed in .text.
12470657Sobrien */
12570657Sobrien#ifndef lint
12670657Sobrienstatic const char rcsid[] =
12770657Sobrien  "$FreeBSD: head/lib/csu/powerpc/crt1.c 80740 2001-07-31 16:10:51Z mp $";
12870657Sobrien#endif
129