crt1.c revision 93036
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 4170657Sobrien#ifndef __GNUC__ 4270657Sobrien#error "GCC is needed to compile this file" 4370657Sobrien#endif 4470657Sobrien 4570657Sobrien#include <stdlib.h> 4670657Sobrien#include "crtbrand.c" 4770657Sobrien 4880740Smpstruct Struct_Obj_Entry; 4980740Smpstruct ps_strings; 5080740Smp 5170657Sobrien#pragma weak _DYNAMIC 5270657Sobrienextern int _DYNAMIC; 5370657Sobrien 5470657Sobrienextern void _init(void); 5570657Sobrienextern void _fini(void); 5670657Sobrienextern int main(int, char **, char **); 5770657Sobrien 5870657Sobrien#ifdef GCRT 5970657Sobrienextern void _mcleanup(void); 6070657Sobrienextern void monstartup(void *, void *); 6170657Sobrienextern int eprol; 6270657Sobrienextern int etext; 6370657Sobrien#endif 6470657Sobrien 6570657Sobrienchar **environ; 6670657Sobrienchar *__progname = ""; 6780740Smpstruct ps_strings *__ps_strings; 6870657Sobrien 6993036Sobrien/* The entry function. 7093036Sobrien * 7193036Sobrien * First 5 arguments are specified by the PowerPC SVR4 ABI. 7293036Sobrien * The last argument, ps_strings, is a BSD extension. 7393036Sobrien */ 7470657Sobrienvoid 7570657Sobrien_start(argc, argv, envp, obj, cleanup, ps_strings) 7670657Sobrien int argc; 7770657Sobrien char **argv, **envp; 7880740Smp const struct Struct_Obj_Entry *obj; /* from shared loader */ 7993036Sobrien void (*cleanup)(void); /* from shared loader */ 8070657Sobrien struct ps_strings *ps_strings; /* BSD extension */ 8170657Sobrien{ 8270657Sobrien char *namep; 8370657Sobrien 8470657Sobrien environ = envp; 8570657Sobrien 8691430Sobrien if (argc > 0 && argv[0] != NULL) { 8770657Sobrien char *s; 8870657Sobrien __progname = argv[0]; 8970657Sobrien for (s = __progname; *s != '\0'; s++) 9070657Sobrien if (*s == '/') 9170657Sobrien __progname = s + 1; 9270657Sobrien } 9370657Sobrien 9470657Sobrien if (ps_strings != (struct ps_strings *)0) 9570657Sobrien __ps_strings = ps_strings; 9670657Sobrien 9770657Sobrien if (&_DYNAMIC != NULL) 9870657Sobrien atexit(cleanup); 9970657Sobrien 10070657Sobrien#ifdef GCRT 10170657Sobrien atexit(_mcleanup); 10270657Sobrien#endif 10370657Sobrien atexit(_fini); 10470657Sobrien#ifdef GCRT 10570657Sobrien monstartup(&eprol, &etext); 10670657Sobrien#endif 10770657Sobrien _init(); 10880740Smp exit( main(argc, argv, envp) ); 10970657Sobrien} 11070657Sobrien 11170657Sobrien#ifdef GCRT 11270657Sobrien__asm__(".text"); 11370657Sobrien__asm__("eprol:"); 11470657Sobrien__asm__(".previous"); 11570657Sobrien#endif 11670657Sobrien 11791430Sobrien__asm__(".ident\t\"$FreeBSD: head/lib/csu/powerpc/crt1.c 93036 2002-03-23 18:14:04Z obrien $\""); 118