crt1.c revision 109903
1/*- 2 * Copyright 2001 David E. O'Brien. 3 * All rights reserved. 4 * Copyright (c) 1995, 1998 Berkeley Software Design, Inc. 5 * All rights reserved. 6 * Copyright 1996-1998 John D. Polstra. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. The name of the authors may not be used to endorse or promote products 18 * derived from this software without specific prior written permission 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef lint 33#ifndef __GNUC__ 34#error "GCC is needed to compile this file" 35#endif 36#endif /* lint */ 37 38#include <stdlib.h> 39 40#include "libc_private.h" 41#include "crtbrand.c" 42 43struct Struct_Obj_Entry; 44struct ps_strings; 45 46extern int _DYNAMIC; 47#pragma weak _DYNAMIC 48 49typedef void (*fptr)(void); 50 51extern void _fini(void); 52extern void _init(void); 53extern int main(int, char **, char **); 54extern void _start(char **, void (*)(void), struct Struct_Obj_Entry *, 55 struct ps_strings *); 56extern void __sparc_utrap_setup(void); 57 58#ifdef GCRT 59extern void _mcleanup(void); 60extern void monstartup(void *, void *); 61extern int eprol; 62extern int etext; 63#endif 64 65char **environ; 66const char *__progname = ""; 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 __sparc_utrap_setup(); 103 104 if (&_DYNAMIC != NULL) 105 atexit(cleanup); 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 109903 2003-01-26 23:01:36Z markm $\""); 125