150397Sobrien/*-
250397Sobrien * Copyright 1996-1998 John D. Polstra.
350397Sobrien * All rights reserved.
450397Sobrien * Copyright (c) 1995 Christopher G. Demetriou
550397Sobrien * All rights reserved.
650397Sobrien *
750397Sobrien * Redistribution and use in source and binary forms, with or without
850397Sobrien * modification, are permitted provided that the following conditions
950397Sobrien * are met:
1050397Sobrien * 1. Redistributions of source code must retain the above copyright
1150397Sobrien *    notice, this list of conditions and the following disclaimer.
1250397Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1350397Sobrien *    notice, this list of conditions and the following disclaimer in the
1450397Sobrien *    documentation and/or other materials provided with the distribution.
1550397Sobrien * 3. All advertising materials mentioning features or use of this software
1650397Sobrien *    must display the following acknowledgement:
1750397Sobrien *      This product includes software developed by Christopher G. Demetriou
1850397Sobrien *    for the NetBSD Project.
1950397Sobrien * 4. The name of the author may not be used to endorse or promote products
2050397Sobrien *    derived from this software without specific prior written permission
2150397Sobrien *
2250397Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2350397Sobrien * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2450397Sobrien * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2550397Sobrien * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26169689Skan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27169689Skan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2850397Sobrien * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2950397Sobrien * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3050397Sobrien * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3150397Sobrien * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3250397Sobrien *
3350397Sobrien * $FreeBSD: releng/10.3/lib/csu/mips/crt1.c 245133 2013-01-07 17:58:27Z kib $
3450397Sobrien */
3550397Sobrien
3650397Sobrien#include <sys/cdefs.h>
3750397Sobrien__FBSDID("$FreeBSD: releng/10.3/lib/csu/mips/crt1.c 245133 2013-01-07 17:58:27Z kib $");
3850397Sobrien
3950397Sobrien#ifndef __GNUC__
4050397Sobrien#error "GCC is needed to compile this file"
4150397Sobrien#endif
4250397Sobrien
4350397Sobrien#include <stdlib.h>
4450397Sobrien#include "libc_private.h"
4550397Sobrien#include "crtbrand.c"
4650397Sobrien#include "ignore_init.c"
4750397Sobrien
4850397Sobrienstruct Struct_Obj_Entry;
4950397Sobrienstruct ps_strings;
5050397Sobrien
5150397Sobrien#ifdef GCRT
5250397Sobrienextern void _mcleanup(void);
5350397Sobrienextern void monstartup(void *, void *);
5450397Sobrienextern int eprol;
5550397Sobrienextern int etext;
5650397Sobrien#endif
5750397Sobrien
5850397Sobrienvoid __start(char **, void (*)(void), struct Struct_Obj_Entry *, struct ps_strings *);
5950397Sobrien
6050397Sobrien/* The entry function. */
6150397Sobrienvoid
6250397Sobrien__start(char **ap,
6350397Sobrien	void (*cleanup)(void),			/* from shared loader */
6450397Sobrien	struct Struct_Obj_Entry *obj __unused,	/* from shared loader */
6550397Sobrien	struct ps_strings *ps_strings __unused)
6650397Sobrien{
6750397Sobrien	int argc;
6850397Sobrien	char **argv;
6950397Sobrien	char **env;
7050397Sobrien
7150397Sobrien	argc = * (long *) ap;
7250397Sobrien	argv = ap + 1;
7350397Sobrien	env  = ap + 2 + argc;
7450397Sobrien	handle_argv(argc, argv, env);
7550397Sobrien
7650397Sobrien	if (&_DYNAMIC != NULL)
7750397Sobrien		atexit(cleanup);
7850397Sobrien	else
7950397Sobrien		_init_tls();
8050397Sobrien
8150397Sobrien#ifdef GCRT
8250397Sobrien	atexit(_mcleanup);
8350397Sobrien	monstartup(&eprol, &etext);
8450397Sobrien#endif
8550397Sobrien
8650397Sobrien	handle_static_init(argc, argv, env);
8750397Sobrien	exit(main(argc, argv, env));
8850397Sobrien}
8950397Sobrien
9050397Sobrien#ifdef GCRT
9150397Sobrien__asm__(".text");
9250397Sobrien__asm__("eprol:");
9350397Sobrien__asm__(".previous");
9450397Sobrien#endif
9550397Sobrien