1178739Sgonzo/*-
2178739Sgonzo * Copyright 1996-1998 John D. Polstra.
3178739Sgonzo * All rights reserved.
4178739Sgonzo * Copyright (c) 1995 Christopher G. Demetriou
5178739Sgonzo * All rights reserved.
6178739Sgonzo *
7178739Sgonzo * Redistribution and use in source and binary forms, with or without
8178739Sgonzo * modification, are permitted provided that the following conditions
9178739Sgonzo * are met:
10178739Sgonzo * 1. Redistributions of source code must retain the above copyright
11178739Sgonzo *    notice, this list of conditions and the following disclaimer.
12178739Sgonzo * 2. Redistributions in binary form must reproduce the above copyright
13178739Sgonzo *    notice, this list of conditions and the following disclaimer in the
14178739Sgonzo *    documentation and/or other materials provided with the distribution.
15178739Sgonzo * 3. All advertising materials mentioning features or use of this software
16178739Sgonzo *    must display the following acknowledgement:
17178739Sgonzo *      This product includes software developed by Christopher G. Demetriou
18178739Sgonzo *    for the NetBSD Project.
19178739Sgonzo * 4. The name of the author may not be used to endorse or promote products
20178739Sgonzo *    derived from this software without specific prior written permission
21178739Sgonzo *
22178739Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23178739Sgonzo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24178739Sgonzo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25178739Sgonzo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26178739Sgonzo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27178739Sgonzo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28178739Sgonzo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29178739Sgonzo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30178739Sgonzo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31178739Sgonzo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32178739Sgonzo *
33178739Sgonzo * $FreeBSD$
34178739Sgonzo */
35178739Sgonzo
36178739Sgonzo#include <sys/cdefs.h>
37178739Sgonzo__FBSDID("$FreeBSD$");
38178739Sgonzo
39178739Sgonzo#ifndef __GNUC__
40178739Sgonzo#error "GCC is needed to compile this file"
41178739Sgonzo#endif
42178739Sgonzo
43178739Sgonzo#include <stdlib.h>
44178739Sgonzo#include "libc_private.h"
45178739Sgonzo#include "crtbrand.c"
46232832Skib#include "ignore_init.c"
47178739Sgonzo
48178739Sgonzostruct Struct_Obj_Entry;
49178739Sgonzostruct ps_strings;
50178739Sgonzo
51178739Sgonzo#ifdef GCRT
52178739Sgonzoextern void _mcleanup(void);
53178739Sgonzoextern void monstartup(void *, void *);
54178739Sgonzoextern int eprol;
55178739Sgonzoextern int etext;
56178739Sgonzo#endif
57178739Sgonzo
58204756Suqsvoid __start(char **, void (*)(void), struct Struct_Obj_Entry *, struct ps_strings *);
59204756Suqs
60178739Sgonzo/* The entry function. */
61178739Sgonzovoid
62178739Sgonzo__start(char **ap,
63178739Sgonzo	void (*cleanup)(void),			/* from shared loader */
64204757Suqs	struct Struct_Obj_Entry *obj __unused,	/* from shared loader */
65204757Suqs	struct ps_strings *ps_strings __unused)
66178739Sgonzo{
67178739Sgonzo	int argc;
68178739Sgonzo	char **argv;
69178739Sgonzo	char **env;
70178739Sgonzo
71178739Sgonzo	argc = * (long *) ap;
72178739Sgonzo	argv = ap + 1;
73178739Sgonzo	env  = ap + 2 + argc;
74245133Skib	handle_argv(argc, argv, env);
75178739Sgonzo
76178739Sgonzo	if (&_DYNAMIC != NULL)
77178739Sgonzo		atexit(cleanup);
78232580Sgonzo	else
79232580Sgonzo		_init_tls();
80232580Sgonzo
81178739Sgonzo#ifdef GCRT
82178739Sgonzo	atexit(_mcleanup);
83178739Sgonzo	monstartup(&eprol, &etext);
84178739Sgonzo#endif
85232832Skib
86232832Skib	handle_static_init(argc, argv, env);
87232832Skib	exit(main(argc, argv, env));
88178739Sgonzo}
89178739Sgonzo
90178739Sgonzo#ifdef GCRT
91178739Sgonzo__asm__(".text");
92178739Sgonzo__asm__("eprol:");
93178739Sgonzo__asm__(".previous");
94178739Sgonzo#endif
95