crt1.c revision 38928
1/*- 2 * Copyright 1996-1998 John D. Polstra. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 * $Id: crt1.c,v 1.1.1.1 1998/03/07 20:27:10 jdp Exp $ 26 */ 27 28#ifndef __GNUC__ 29#error "GCC is needed to compile this file" 30#endif 31 32#include <stdlib.h> 33 34typedef void (*fptr)(void); 35 36extern void _fini(void); 37extern void _init(void); 38extern int main(int, char **, char **); 39 40#ifdef GCRT 41extern void _mcleanup(void); 42extern void monstartup(void *, void *); 43extern int eprol; 44extern int etext; 45#endif 46 47extern int _DYNAMIC; 48#pragma weak _DYNAMIC 49 50#ifdef __i386__ 51#define get_rtld_cleanup() \ 52 ({ fptr __value; \ 53 __asm__("movl %%edx,%0" : "=rm"(__value)); \ 54 __value; }) 55#else 56#error "This file only supports the i386 architecture" 57#endif 58 59char **environ; 60char *__progname = ""; 61 62void 63_start(char *arguments, ...) 64{ 65 fptr rtld_cleanup; 66 int argc; 67 char **argv; 68 char **env; 69 70 rtld_cleanup = get_rtld_cleanup(); 71 argv = &arguments; 72 argc = * (int *) (argv - 1); 73 env = argv + argc + 1; 74 environ = env; 75 if(argc > 0) 76 __progname = argv[0]; 77 78 if(&_DYNAMIC != 0) 79 atexit(rtld_cleanup); 80 81#ifdef GCRT 82 atexit(_mcleanup); 83#endif 84 atexit(_fini); 85#ifdef GCRT 86 monstartup(&eprol, &etext); 87#endif 88 _init(); 89 exit( main(argc, argv, env) ); 90} 91 92#ifdef GCRT 93__asm__(".text"); 94__asm__("eprol:"); 95__asm__(".previous"); 96#endif 97