crt1.c revision 232616
169450Smsmith/*- 269450Smsmith * Copyright 1996-1998 John D. Polstra. 3167802Sjkim * All rights reserved. 469450Smsmith * Copyright (c) 1995 Christopher G. Demetriou 569450Smsmith * All rights reserved. 669450Smsmith * 7217365Sjkim * Redistribution and use in source and binary forms, with or without 8229989Sjkim * modification, are permitted provided that the following conditions 970243Smsmith * are met: 1069450Smsmith * 1. Redistributions of source code must retain the above copyright 11217365Sjkim * notice, this list of conditions and the following disclaimer. 12217365Sjkim * 2. Redistributions in binary form must reproduce the above copyright 13217365Sjkim * notice, this list of conditions and the following disclaimer in the 14217365Sjkim * documentation and/or other materials provided with the distribution. 15217365Sjkim * 3. All advertising materials mentioning features or use of this software 16217365Sjkim * must display the following acknowledgement: 17217365Sjkim * This product includes software developed by Christopher G. Demetriou 18217365Sjkim * for the NetBSD Project. 19217365Sjkim * 4. The name of the author may not be used to endorse or promote products 20217365Sjkim * derived from this software without specific prior written permission 21217365Sjkim * 22217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23217365Sjkim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24217365Sjkim * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2569450Smsmith * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26217365Sjkim * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27217365Sjkim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28217365Sjkim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2969450Smsmith * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30217365Sjkim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31217365Sjkim * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32217365Sjkim * 33217365Sjkim * $FreeBSD: head/lib/csu/mips/crt1.c 232616 2012-03-06 19:19:33Z gonzo $ 34217365Sjkim */ 35217365Sjkim 36217365Sjkim#include <sys/cdefs.h> 37217365Sjkim__FBSDID("$FreeBSD: head/lib/csu/mips/crt1.c 232616 2012-03-06 19:19:33Z gonzo $"); 38217365Sjkim 39217365Sjkim#ifndef __GNUC__ 40217365Sjkim#error "GCC is needed to compile this file" 41217365Sjkim#endif 42217365Sjkim 4369450Smsmith#include <stdlib.h> 4469450Smsmith#include "libc_private.h" 4569450Smsmith#include "crtbrand.c" 4669450Smsmith 47167802Sjkimstruct Struct_Obj_Entry; 48167802Sjkimstruct ps_strings; 49167802Sjkim 50197104Sjkimextern int _DYNAMIC; 51167802Sjkim#pragma weak _DYNAMIC 52167802Sjkim 53167802Sjkimextern void _init(void); 54167802Sjkimextern void _fini(void); 55197104Sjkimextern int main(int, char **, char **); 56197104Sjkim 57167802Sjkim#ifdef GCRT 58167802Sjkimextern void _mcleanup(void); 59167802Sjkimextern void monstartup(void *, void *); 60167802Sjkimextern int eprol; 61197104Sjkimextern int etext; 62197104Sjkim#endif 63197104Sjkim 64167802Sjkimchar **environ; 65193267Sjkimconst char *__progname = ""; 66167802Sjkim 67167802Sjkimvoid __start(char **, void (*)(void), struct Struct_Obj_Entry *, struct ps_strings *); 68193267Sjkim 69193267Sjkim/* The entry function. */ 70193267Sjkimvoid 71167802Sjkim__start(char **ap, 72197104Sjkim void (*cleanup)(void), /* from shared loader */ 73167802Sjkim struct Struct_Obj_Entry *obj __unused, /* from shared loader */ 74167802Sjkim struct ps_strings *ps_strings __unused) 75167802Sjkim{ 76167802Sjkim int argc; 77167802Sjkim char **argv; 78167802Sjkim char **env; 79167802Sjkim 80167802Sjkim argc = * (long *) ap; 81167802Sjkim argv = ap + 1; 8269450Smsmith env = ap + 2 + argc; 8369450Smsmith environ = env; 8491116Smsmith if (argc > 0 && argv[0] != NULL) { 85167802Sjkim const char *s; 86167802Sjkim __progname = argv[0]; 87167802Sjkim for (s = __progname; *s != '\0'; s++) 8891116Smsmith if (*s == '/') 89167802Sjkim __progname = s + 1; 90167802Sjkim } 91197104Sjkim 92197104Sjkim if (&_DYNAMIC != NULL) 93197104Sjkim atexit(cleanup); 94197104Sjkim else 95197104Sjkim _init_tls(); 96167802Sjkim 97197104Sjkim#ifdef GCRT 98197104Sjkim atexit(_mcleanup); 99167802Sjkim#endif 10069450Smsmith atexit(_fini); 101167802Sjkim#ifdef GCRT 102167802Sjkim monstartup(&eprol, &etext); 103151937Sjkim#endif 104167802Sjkim _init(); 10569450Smsmith exit( main(argc, argv, env) ); 10669450Smsmith} 107197104Sjkim 108193267Sjkim#ifdef GCRT 109193267Sjkim__asm__(".text"); 110193267Sjkim__asm__("eprol:"); 111193267Sjkim__asm__(".previous"); 112193267Sjkim#endif 113193267Sjkim