crt1.c revision 204756
1169689Skan/* LINTLIBRARY */ 2169689Skan/*- 3169689Skan * Copyright 2001 David E. O'Brien. 4169689Skan * All rights reserved. 5169689Skan * Copyright (c) 1995, 1998 Berkeley Software Design, Inc. 6169689Skan * All rights reserved. 7169689Skan * Copyright 1996-1998 John D. Polstra. 8169689Skan * All rights reserved. 9169689Skan * 10169689Skan * Redistribution and use in source and binary forms, with or without 11169689Skan * modification, are permitted provided that the following conditions 12169689Skan * are met: 13169689Skan * 1. Redistributions of source code must retain the above copyright 14169689Skan * notice, this list of conditions and the following disclaimer. 15169689Skan * 2. Redistributions in binary form must reproduce the above copyright 16169689Skan * notice, this list of conditions and the following disclaimer in the 17169689Skan * documentation and/or other materials provided with the distribution. 18169689Skan * 3. The name of the authors may not be used to endorse or promote products 19169689Skan * derived from this software without specific prior written permission 20169689Skan * 21169689Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22169689Skan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23169689Skan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24169689Skan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25169689Skan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26169689Skan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27169689Skan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28169689Skan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29169689Skan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30169689Skan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31169689Skan */ 32169689Skan 33169689Skan#ifndef lint 34169689Skan#ifndef __GNUC__ 35169689Skan#error "GCC is needed to compile this file" 36169689Skan#endif 37169689Skan#endif /* lint */ 38169689Skan 39169689Skan#include <stdlib.h> 40169689Skan 41169689Skan#include "libc_private.h" 42169689Skan#include "crtbrand.c" 43169689Skan 44169689Skanstruct Struct_Obj_Entry; 45169689Skanstruct ps_strings; 46169689Skan 47169689Skanextern int _DYNAMIC; 48169689Skan#pragma weak _DYNAMIC 49169689Skan 50169689Skanextern void _fini(void); 51169689Skanextern void _init(void); 52169689Skanextern int main(int, char **, char **); 53169689Skanextern void __sparc_utrap_setup(void); 54169689Skan 55169689Skan#ifdef GCRT 56169689Skanextern void _mcleanup(void); 57169689Skanextern void monstartup(void *, void *); 58169689Skanextern int eprol; 59169689Skanextern int etext; 60#endif 61 62char **environ; 63const char *__progname = ""; 64 65void _start(char **, void (*)(void), struct Struct_Obj_Entry *, 66 struct ps_strings *); 67 68/* The entry function. */ 69/* 70 * %o0 holds ps_strings pointer. 71 * 72 * Note: kernel may (is not set in stone yet) pass ELF aux vector in %o1, 73 * but for now we do not use it here. 74 * 75 * The SPARC compliance definitions specifies that the kernel pass the 76 * address of a function to be executed on exit in %g1. We do not make 77 * use of it as it is quite broken, because gcc can use this register 78 * as a temporary, so it is not safe from C code. Its even more broken 79 * for dynamic executables since rtld runs first. 80 */ 81/* ARGSUSED */ 82void 83_start(char **ap, void (*cleanup)(void), struct Struct_Obj_Entry *obj __unused, 84 struct ps_strings *ps_strings __unused) 85{ 86 int argc; 87 char **argv; 88 char **env; 89 const char *s; 90 91 argc = *(long *)(void *)ap; 92 argv = ap + 1; 93 env = ap + 2 + argc; 94 environ = env; 95 if (argc > 0 && argv[0] != NULL) { 96 __progname = argv[0]; 97 for (s = __progname; *s != '\0'; s++) 98 if (*s == '/') 99 __progname = s + 1; 100 } 101 102 if (&_DYNAMIC != NULL) 103 atexit(cleanup); 104 else { 105 __sparc_utrap_setup(); 106 _init_tls(); 107 } 108#ifdef GCRT 109 atexit(_mcleanup); 110#endif 111 atexit(_fini); 112#ifdef GCRT 113 monstartup(&eprol, &etext); 114#endif 115 _init(); 116 exit( main(argc, argv, env) ); 117} 118 119#ifdef GCRT 120__asm__(".text"); 121__asm__("eprol:"); 122__asm__(".previous"); 123#endif 124 125__asm__(".ident\t\"$FreeBSD: head/lib/csu/sparc64/crt1.c 204756 2010-03-05 13:28:05Z uqs $\""); 126