crt1.c revision 163118
1/* LINTLIBRARY */ 2/*- 3 * Copyright 2001 David E. O'Brien. 4 * All rights reserved. 5 * Copyright (c) 1995, 1998 Berkeley Software Design, Inc. 6 * All rights reserved. 7 * Copyright 1996-1998 John D. Polstra. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. The name of the authors may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#ifndef lint 34#ifndef __GNUC__ 35#error "GCC is needed to compile this file" 36#endif 37#endif /* lint */ 38 39#include <stdlib.h> 40 41#include "libc_private.h" 42#include "crtbrand.c" 43 44struct Struct_Obj_Entry; 45struct ps_strings; 46 47extern int _DYNAMIC; 48#pragma weak _DYNAMIC 49 50extern void _fini(void); 51extern void _init(void); 52extern int main(int, char **, char **); 53extern void _start(char **, void (*)(void), struct Struct_Obj_Entry *, 54 struct ps_strings *); 55extern void __sparc_utrap_setup(void); 56 57#ifdef GCRT 58extern void _mcleanup(void); 59extern void monstartup(void *, void *); 60extern int eprol; 61extern int etext; 62#endif 63 64char **environ; 65const char *__progname = ""; 66 67/* The entry function. */ 68/* 69 * %o0 holds ps_strings pointer. 70 * 71 * Note: kernel may (is not set in stone yet) pass ELF aux vector in %o1, 72 * but for now we do not use it here. 73 * 74 * The SPARC compliance definitions specifies that the kernel pass the 75 * address of a function to be executed on exit in %g1. We do not make 76 * use of it as it is quite broken, because gcc can use this register 77 * as a temporary, so it is not safe from C code. Its even more broken 78 * for dynamic executables since rtld runs first. 79 */ 80/* ARGSUSED */ 81void 82_start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused, 83 struct ps_strings *ps_strings __unused) 84{ 85 int argc; 86 char **argv; 87 char **env; 88 const char *s; 89 90 argc = *(long *)(void *)ap; 91 argv = ap + 1; 92 env = ap + 2 + argc; 93 environ = env; 94 if (argc > 0 && argv[0] != NULL) { 95 __progname = argv[0]; 96 for (s = __progname; *s != '\0'; s++) 97 if (*s == '/') 98 __progname = s + 1; 99 } 100 101 if (&_DYNAMIC != NULL) 102 atexit(cleanup); 103 else { 104 __sparc_utrap_setup(); 105 _init_tls(); 106 } 107#ifdef GCRT 108 atexit(_mcleanup); 109#endif 110 atexit(_fini); 111#ifdef GCRT 112 monstartup(&eprol, &etext); 113#endif 114 _init(); 115 exit( main(argc, argv, env) ); 116} 117 118#ifdef GCRT 119__asm__(".text"); 120__asm__("eprol:"); 121__asm__(".previous"); 122#endif 123 124__asm__(".ident\t\"$FreeBSD: head/lib/csu/sparc64/crt1.c 163118 2006-10-08 02:50:34Z kmacy $\""); 125