1109905Smarkm/* LINTLIBRARY */ 270657Sobrien/*- 370657Sobrien * Copyright 2001 David E. O'Brien. 470657Sobrien * All rights reserved. 570657Sobrien * Copyright 1996-1998 John D. Polstra. 670657Sobrien * All rights reserved. 770657Sobrien * Copyright (c) 1997 Jason R. Thorpe. 870657Sobrien * Copyright (c) 1995 Christopher G. Demetriou 970657Sobrien * All rights reserved. 1070657Sobrien * 1170657Sobrien * Redistribution and use in source and binary forms, with or without 1270657Sobrien * modification, are permitted provided that the following conditions 1370657Sobrien * are met: 1470657Sobrien * 1. Redistributions of source code must retain the above copyright 1570657Sobrien * notice, this list of conditions and the following disclaimer. 1670657Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1770657Sobrien * notice, this list of conditions and the following disclaimer in the 1870657Sobrien * documentation and/or other materials provided with the distribution. 1970657Sobrien * 3. All advertising materials mentioning features or use of this software 2070657Sobrien * must display the following acknowledgement: 2170657Sobrien * This product includes software developed for the 2270657Sobrien * FreeBSD Project. See http://www.freebsd.org/ for 2370657Sobrien * information about FreeBSD. 2470657Sobrien * This product includes software developed for the 2570657Sobrien * NetBSD Project. See http://www.netbsd.org/ for 2670657Sobrien * information about NetBSD. 2770657Sobrien * 4. The name of the author may not be used to endorse or promote products 2870657Sobrien * derived from this software without specific prior written permission 2970657Sobrien * 3070657Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 3170657Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 3270657Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 3370657Sobrien * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 3470657Sobrien * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 3570657Sobrien * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3670657Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3770657Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3870657Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 3970657Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4070657Sobrien */ 4170657Sobrien 42216338Sdim#include <sys/cdefs.h> 43216338Sdim__FBSDID("$FreeBSD$"); 44216338Sdim 45100167Smarkm#ifndef lint 4670657Sobrien#ifndef __GNUC__ 4770657Sobrien#error "GCC is needed to compile this file" 4870657Sobrien#endif 49100167Smarkm#endif /* lint */ 5070657Sobrien 5170657Sobrien#include <stdlib.h> 52100167Smarkm 5393399Smarkm#include "libc_private.h" 5470657Sobrien#include "crtbrand.c" 5570657Sobrien 5680740Smpstruct Struct_Obj_Entry; 5780740Smpstruct ps_strings; 5880740Smp 59100167Smarkmextern int _DYNAMIC; 6070657Sobrien#pragma weak _DYNAMIC 6170657Sobrien 62100167Smarkmextern void _fini(void); 6370657Sobrienextern void _init(void); 6470657Sobrienextern int main(int, char **, char **); 6570657Sobrien 6670657Sobrien#ifdef GCRT 6770657Sobrienextern void _mcleanup(void); 6870657Sobrienextern void monstartup(void *, void *); 6970657Sobrienextern int eprol; 7070657Sobrienextern int etext; 7170657Sobrien#endif 7270657Sobrien 7370657Sobrienchar **environ; 7493399Smarkmconst char *__progname = ""; 7580740Smpstruct ps_strings *__ps_strings; 7670657Sobrien 77204756Suqsvoid _start(int, char **, char **, const struct Struct_Obj_Entry *, 78204756Suqs void (*)(void), struct ps_strings *); 79204756Suqs 80100167Smarkm/* The entry function. */ 81100167Smarkm/* 8293036Sobrien * First 5 arguments are specified by the PowerPC SVR4 ABI. 8393036Sobrien * The last argument, ps_strings, is a BSD extension. 8493036Sobrien */ 85100167Smarkm/* ARGSUSED */ 8670657Sobrienvoid 87100167Smarkm_start(int argc, char **argv, char **env, 88100167Smarkm const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void), 89100167Smarkm struct ps_strings *ps_strings) 9070657Sobrien{ 9193399Smarkm const char *s; 9270657Sobrien 93245777Skib if (environ == NULL) 94245777Skib environ = env; 9570657Sobrien 9691430Sobrien if (argc > 0 && argv[0] != NULL) { 9770657Sobrien __progname = argv[0]; 9870657Sobrien for (s = __progname; *s != '\0'; s++) 9970657Sobrien if (*s == '/') 10070657Sobrien __progname = s + 1; 10170657Sobrien } 10270657Sobrien 10370657Sobrien if (ps_strings != (struct ps_strings *)0) 10470657Sobrien __ps_strings = ps_strings; 10570657Sobrien 10670657Sobrien if (&_DYNAMIC != NULL) 10770657Sobrien atexit(cleanup); 108133754Sdfr else 109133754Sdfr _init_tls(); 11070657Sobrien 11170657Sobrien#ifdef GCRT 11270657Sobrien atexit(_mcleanup); 11370657Sobrien#endif 11470657Sobrien atexit(_fini); 11570657Sobrien#ifdef GCRT 11670657Sobrien monstartup(&eprol, &etext); 11770657Sobrien#endif 11870657Sobrien _init(); 119100167Smarkm exit( main(argc, argv, env) ); 12070657Sobrien} 12170657Sobrien 12270657Sobrien#ifdef GCRT 12370657Sobrien__asm__(".text"); 12470657Sobrien__asm__("eprol:"); 12570657Sobrien__asm__(".previous"); 12670657Sobrien#endif 127