crt0.c revision 1.6
1/* $OpenBSD: crt0.c,v 1.6 2016/03/20 02:32:39 guenther Exp $ */ 2 3/* 4 * Copyright (c) 1995 Christopher G. Demetriou 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Christopher G. Demetriou 18 * for the NetBSD Project. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34#include <stdlib.h> 35#include <limits.h> 36 37#include "md_init.h" 38#ifdef MD_RCRT0_START 39#include "boot.h" 40#endif 41 42/* some defaults */ 43#ifndef MD_START_ARGS 44#define MD_START_ARGS \ 45 int argc, char **argv, char **envp, void (*cleanup)(void) 46#endif 47#ifndef MD_START 48#define MD_START ___start 49static void ___start(MD_START_ARGS) __used; 50#endif 51#ifndef MD_EPROL_LABEL 52#define MD_EPROL_LABEL __asm(" .text\n_eprol:") 53#endif 54 55char ***_csu_finish(char **_argv, char **_envp, void (*_cleanup)(void)); 56 57#ifdef MCRT0 58extern void monstartup(u_long, u_long); 59extern void _mcleanup(void); 60extern unsigned char _etext, _eprol; 61#endif /* MCRT0 */ 62 63#ifdef RCRT0 64#ifdef MD_RCRT0_START 65MD_RCRT0_START; 66#endif 67#else 68#ifdef MD_CRT0_START 69MD_CRT0_START; 70#endif 71#endif 72 73void 74MD_START(MD_START_ARGS) 75{ 76 char ***environp; 77#ifdef MD_START_SETUP 78 MD_START_SETUP 79#endif 80 81#ifndef MD_NO_CLEANUP 82 environp = _csu_finish(argv, envp, cleanup); 83#else 84 environp = _csu_finish(argv, envp, NULL); 85#endif 86 87#ifdef MCRT0 88 atexit(_mcleanup); 89 monstartup((u_long)&_eprol, (u_long)&_etext); 90#endif 91 92 __init(); 93 94 exit(main(argc, argv, *environp)); 95} 96 97#ifdef MCRT0 98MD_EPROL_LABEL; 99#endif 100