1/* LINTLIBRARY */
2/*-
3 * SPDX-License-Identifier: BSD-4-Clause
4 *
5 * Copyright 2001 David E. O'Brien.
6 * All rights reserved.
7 * Copyright 1996-1998 John D. Polstra.
8 * All rights reserved.
9 * Copyright (c) 1997 Jason R. Thorpe.
10 * Copyright (c) 1995 Christopher G. Demetriou
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 *    must display the following acknowledgement:
23 *          This product includes software developed for the
24 *          FreeBSD Project.  See https://www.freebsd.org/ for
25 *          information about FreeBSD.
26 *          This product includes software developed for the
27 *          NetBSD Project.  See http://www.netbsd.org/ for
28 *          information about NetBSD.
29 * 4. The name of the author may not be used to endorse or promote products
30 *    derived from this software without specific prior written permission
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD$");
46
47#include <stdlib.h>
48
49#include "libc_private.h"
50#include "ignore_init.c"
51
52struct Struct_Obj_Entry;
53struct ps_strings;
54
55#ifdef GCRT
56extern void _mcleanup(void);
57extern void monstartup(void *, void *);
58extern int eprol;
59extern int etext;
60#endif
61
62struct ps_strings *__ps_strings;
63
64void _start(int, char **, char **, const struct Struct_Obj_Entry *,
65    void (*)(void), struct ps_strings *);
66
67/* The entry function. */
68/*
69 * First 5 arguments are specified by the PowerPC SVR4 ABI.
70 * The last argument, ps_strings, is a BSD extension.
71 */
72/* ARGSUSED */
73void
74_start(int argc, char **argv, char **env,
75    const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void),
76    struct ps_strings *ps_strings)
77{
78
79
80	handle_argv(argc, argv, env);
81
82	if (ps_strings != (struct ps_strings *)0)
83		__ps_strings = ps_strings;
84
85	if (&_DYNAMIC != NULL)
86		atexit(cleanup);
87	else
88		_init_tls();
89
90#ifdef GCRT
91	atexit(_mcleanup);
92	monstartup(&eprol, &etext);
93#endif
94
95	handle_static_init(argc, argv, env);
96	exit(main(argc, argv, env));
97}
98
99#ifdef GCRT
100__asm__(".text");
101__asm__("eprol:");
102__asm__(".previous");
103#endif
104
105#ifndef PIC
106__asm__(".text\n"
107	"\t.global _GLOBAL_OFFSET_TABLE_\n"
108	"\t.reloc 0, R_PPC_NONE, _GLOBAL_OFFSET_TABLE_");
109#endif
110