xref: /freebsd/sys/kern/init_main.c (revision 39fb8e6b3ed00825cf6333574268aec971330f86)
1df8bae1dSRodney W. Grimes /*
22b14f991SJulian Elischer  * Copyright (c) 1995 Terrence R. Lambert
32b14f991SJulian Elischer  * All rights reserved.
42b14f991SJulian Elischer  *
5df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
6df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
7df8bae1dSRodney W. Grimes  * (c) UNIX System Laboratories, Inc.
8df8bae1dSRodney W. Grimes  * All or some portions of this file are derived from material licensed
9df8bae1dSRodney W. Grimes  * to the University of California by American Telephone and Telegraph
10df8bae1dSRodney W. Grimes  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11df8bae1dSRodney W. Grimes  * the permission of UNIX System Laboratories, Inc.
12df8bae1dSRodney W. Grimes  *
13df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
14df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
15df8bae1dSRodney W. Grimes  * are met:
16df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
17df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
18df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
19df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
20df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
21df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
22df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
23df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
24df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
25df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
26df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
27df8bae1dSRodney W. Grimes  *    without specific prior written permission.
28df8bae1dSRodney W. Grimes  *
29df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
40df8bae1dSRodney W. Grimes  *
41df8bae1dSRodney W. Grimes  *	@(#)init_main.c	8.9 (Berkeley) 1/21/94
4239fb8e6bSJulian Elischer  * $Id: init_main.c,v 1.100 1998/12/19 02:55:33 julian Exp $
43df8bae1dSRodney W. Grimes  */
44df8bae1dSRodney W. Grimes 
4519060a3aSPoul-Henning Kamp #include "opt_devfs.h"
464bd49128SPeter Wemm 
47df8bae1dSRodney W. Grimes #include <sys/param.h>
48b3c5c18dSBruce Evans #include <sys/file.h>
49df8bae1dSRodney W. Grimes #include <sys/filedesc.h>
50df8bae1dSRodney W. Grimes #include <sys/kernel.h>
51ac0ad63fSBruce Evans #include <sys/mount.h>
52946bb7a2SPoul-Henning Kamp #include <sys/sysctl.h>
53df8bae1dSRodney W. Grimes #include <sys/proc.h>
54df8bae1dSRodney W. Grimes #include <sys/resourcevar.h>
55df8bae1dSRodney W. Grimes #include <sys/signalvar.h>
56df8bae1dSRodney W. Grimes #include <sys/systm.h>
57df8bae1dSRodney W. Grimes #include <sys/vnode.h>
58f3f0ca60SSøren Schmidt #include <sys/sysent.h>
59df8bae1dSRodney W. Grimes #include <sys/reboot.h>
60ad7507e2SSteven Wallace #include <sys/sysproto.h>
61efeaf95aSDavid Greenman #include <sys/vmmeter.h>
6274b2192aSJohn Dyson #include <sys/unistd.h>
6394e9d7c1SPeter Wemm #include <sys/malloc.h>
64df8bae1dSRodney W. Grimes 
65df8bae1dSRodney W. Grimes #include <machine/cpu.h>
66df8bae1dSRodney W. Grimes 
67df8bae1dSRodney W. Grimes #include <vm/vm.h>
68efeaf95aSDavid Greenman #include <vm/vm_param.h>
69efeaf95aSDavid Greenman #include <vm/vm_prot.h>
70996c772fSJohn Dyson #include <sys/lock.h>
71efeaf95aSDavid Greenman #include <vm/pmap.h>
72efeaf95aSDavid Greenman #include <vm/vm_map.h>
73efeaf95aSDavid Greenman #include <sys/user.h>
746faaa756SWolfram Schneider #include <sys/copyright.h>
75df8bae1dSRodney W. Grimes 
769ef6c28aSBruce Evans extern struct linker_set	sysinit_set;	/* XXX */
779ef6c28aSBruce Evans 
789ef6c28aSBruce Evans extern void __main __P((void));
799ef6c28aSBruce Evans extern void main __P((void *framep));
80df8bae1dSRodney W. Grimes 
81df8bae1dSRodney W. Grimes /* Components of the first process -- never freed. */
82154c04e5SPoul-Henning Kamp static struct session session0;
83154c04e5SPoul-Henning Kamp static struct pgrp pgrp0;
84df8bae1dSRodney W. Grimes struct	proc proc0;
85154c04e5SPoul-Henning Kamp static struct pcred cred0;
866626c604SJulian Elischer #ifdef COMPAT_LINUX_THREADS
876626c604SJulian Elischer static struct procsig procsig0;
886626c604SJulian Elischer #endif /* COMPAT_LINUX_THREADS */
89154c04e5SPoul-Henning Kamp static struct filedesc0 filedesc0;
90154c04e5SPoul-Henning Kamp static struct plimit limit0;
91154c04e5SPoul-Henning Kamp static struct vmspace vmspace0;
922b14f991SJulian Elischer struct	proc *initproc;
93df8bae1dSRodney W. Grimes 
94dedb7b62SPeter Wemm int cmask = CMASK;
95df8bae1dSRodney W. Grimes extern	struct user *proc0paddr;
96df8bae1dSRodney W. Grimes 
972976b7f1SDavid Greenman struct	vnode *rootvp;
98c463cf1cSBruce Evans int	boothowto = 0;		/* initialized so that it can be patched */
99946bb7a2SPoul-Henning Kamp 
100df8bae1dSRodney W. Grimes struct	timeval boottime;
101946bb7a2SPoul-Henning Kamp SYSCTL_STRUCT(_kern, KERN_BOOTTIME, boottime,
102c463cf1cSBruce Evans 	CTLFLAG_RD, &boottime, timeval, "");
103946bb7a2SPoul-Henning Kamp 
104f4e39ee7SDavid Nugent static int shutdowntimeout = 120;
105f4e39ee7SDavid Nugent SYSCTL_INT(_kern, OID_AUTO, shutdown_timeout,
106f4e39ee7SDavid Nugent 	CTLFLAG_RW, &shutdowntimeout, 0, "");
107f4e39ee7SDavid Nugent 
1082b14f991SJulian Elischer /*
1092b14f991SJulian Elischer  * Promiscuous argument pass for start_init()
1102b14f991SJulian Elischer  *
1112b14f991SJulian Elischer  * This is a kludge because we use a return from main() rather than a call
11237b688c4SAlexander Langer  * to a new routine in locore.s to kick the kernel alive from locore.s.
1132b14f991SJulian Elischer  */
1142b14f991SJulian Elischer static void	*init_framep;
1152b14f991SJulian Elischer 
116df8bae1dSRodney W. Grimes 
11726f9a767SRodney W. Grimes #if __GNUC__ >= 2
11826f9a767SRodney W. Grimes void __main() {}
11926f9a767SRodney W. Grimes #endif
12026f9a767SRodney W. Grimes 
1212b14f991SJulian Elischer 
12226f9a767SRodney W. Grimes /*
1232b14f991SJulian Elischer  * This ensures that there is at least one entry so that the sysinit_set
1242b14f991SJulian Elischer  * symbol is not undefined.  A sybsystem ID of SI_SUB_DUMMY is never
1252b14f991SJulian Elischer  * executed.
12626f9a767SRodney W. Grimes  */
1272b14f991SJulian Elischer SYSINIT(placeholder, SI_SUB_DUMMY,SI_ORDER_ANY, NULL, NULL)
1288a129caeSDavid Greenman 
12994e9d7c1SPeter Wemm /*
13094e9d7c1SPeter Wemm  * The sysinit table itself.  Items are checked off as the are run.
13194e9d7c1SPeter Wemm  * If we want to register new sysinit types, add them to newsysinit.
13294e9d7c1SPeter Wemm  */
13394e9d7c1SPeter Wemm struct sysinit **sysinit = (struct sysinit **)sysinit_set.ls_items;
13494e9d7c1SPeter Wemm struct sysinit **newsysinit;
13594e9d7c1SPeter Wemm 
13694e9d7c1SPeter Wemm /*
13794e9d7c1SPeter Wemm  * Merge a new sysinit set into the current set, reallocating it if
13894e9d7c1SPeter Wemm  * necessary.  This can only be called after malloc is running.
13994e9d7c1SPeter Wemm  */
14094e9d7c1SPeter Wemm void
14194e9d7c1SPeter Wemm sysinit_add(set)
14294e9d7c1SPeter Wemm 	struct sysinit **set;
14394e9d7c1SPeter Wemm {
14494e9d7c1SPeter Wemm 	struct sysinit **newset;
14594e9d7c1SPeter Wemm 	struct sysinit **sipp;
14694e9d7c1SPeter Wemm 	struct sysinit **xipp;
14794e9d7c1SPeter Wemm 	int count = 0;
14894e9d7c1SPeter Wemm 
149ddd62546SPeter Wemm 	if (newsysinit)
150ddd62546SPeter Wemm 		for (sipp = newsysinit; *sipp; sipp++)
151ddd62546SPeter Wemm 			count++;
152ddd62546SPeter Wemm 	else
15394e9d7c1SPeter Wemm 		for (sipp = sysinit; *sipp; sipp++)
15494e9d7c1SPeter Wemm 			count++;
15594e9d7c1SPeter Wemm 	for (sipp = set; *sipp; sipp++)
15694e9d7c1SPeter Wemm 		count++;
157ddd62546SPeter Wemm 	count++;		/* Trailing NULL */
15894e9d7c1SPeter Wemm 	newset = malloc(count * sizeof(*sipp), M_TEMP, M_NOWAIT);
15994e9d7c1SPeter Wemm 	if (newset == NULL)
16094e9d7c1SPeter Wemm 		panic("cannot malloc for sysinit");
16194e9d7c1SPeter Wemm 	xipp = newset;
162ddd62546SPeter Wemm 	if (newsysinit)
163ddd62546SPeter Wemm 		for (sipp = newsysinit; *sipp; sipp++)
164ddd62546SPeter Wemm 			*xipp++ = *sipp;
165ddd62546SPeter Wemm 	else
16694e9d7c1SPeter Wemm 		for (sipp = sysinit; *sipp; sipp++)
16794e9d7c1SPeter Wemm 			*xipp++ = *sipp;
16894e9d7c1SPeter Wemm 	for (sipp = set; *sipp; sipp++)
16994e9d7c1SPeter Wemm 		*xipp++ = *sipp;
170ddd62546SPeter Wemm 	*xipp = NULL;
171ddd62546SPeter Wemm 	if (newsysinit)
172ddd62546SPeter Wemm 		free(newsysinit, M_TEMP);
17394e9d7c1SPeter Wemm 	newsysinit = newset;
17494e9d7c1SPeter Wemm }
17526f9a767SRodney W. Grimes 
176df8bae1dSRodney W. Grimes /*
177df8bae1dSRodney W. Grimes  * System startup; initialize the world, create process 0, mount root
178df8bae1dSRodney W. Grimes  * filesystem, and fork to create init and pagedaemon.  Most of the
179df8bae1dSRodney W. Grimes  * hard work is done in the lower-level initialization routines including
180df8bae1dSRodney W. Grimes  * startup(), which does memory initialization and autoconfiguration.
1812b14f991SJulian Elischer  *
1822b14f991SJulian Elischer  * This allows simple addition of new kernel subsystems that require
1832b14f991SJulian Elischer  * boot time initialization.  It also allows substitution of subsystem
1842b14f991SJulian Elischer  * (for instance, a scheduler, kernel profiler, or VM system) by object
185c5b193bfSPoul-Henning Kamp  * module.  Finally, it allows for optional "kernel threads".
186df8bae1dSRodney W. Grimes  */
18726f9a767SRodney W. Grimes void
188df8bae1dSRodney W. Grimes main(framep)
189df8bae1dSRodney W. Grimes 	void *framep;
190df8bae1dSRodney W. Grimes {
1912b14f991SJulian Elischer 
1922b14f991SJulian Elischer 	register struct sysinit **sipp;		/* system initialization*/
1932b14f991SJulian Elischer 	register struct sysinit **xipp;		/* interior loop of sort*/
1942b14f991SJulian Elischer 	register struct sysinit *save;		/* bubble*/
1952b14f991SJulian Elischer 
1962b14f991SJulian Elischer 	/*
197a2a1c95cSPeter Wemm 	 * Copy the locore.s frame pointer for proc0, this is forked into
198a2a1c95cSPeter Wemm 	 * all other processes.
1992b14f991SJulian Elischer 	 */
2002b14f991SJulian Elischer 	init_framep = framep;
2012b14f991SJulian Elischer 
20294e9d7c1SPeter Wemm restart:
2032b14f991SJulian Elischer 	/*
2042b14f991SJulian Elischer 	 * Perform a bubble sort of the system initialization objects by
2052b14f991SJulian Elischer 	 * their subsystem (primary key) and order (secondary key).
2062b14f991SJulian Elischer 	 */
20794e9d7c1SPeter Wemm 	for (sipp = sysinit; *sipp; sipp++) {
2082b14f991SJulian Elischer 		for (xipp = sipp + 1; *xipp; xipp++) {
2092b14f991SJulian Elischer 			if ((*sipp)->subsystem < (*xipp)->subsystem ||
2102b14f991SJulian Elischer 			     ((*sipp)->subsystem == (*xipp)->subsystem &&
2112b14f991SJulian Elischer 			      (*sipp)->order < (*xipp)->order))
2122b14f991SJulian Elischer 				continue;	/* skip*/
2132b14f991SJulian Elischer 			save = *sipp;
2142b14f991SJulian Elischer 			*sipp = *xipp;
2152b14f991SJulian Elischer 			*xipp = save;
2162b14f991SJulian Elischer 		}
2172b14f991SJulian Elischer 	}
2182b14f991SJulian Elischer 
2192b14f991SJulian Elischer 	/*
2202b14f991SJulian Elischer 	 * Traverse the (now) ordered list of system initialization tasks.
2212b14f991SJulian Elischer 	 * Perform each task, and continue on to the next task.
2222b14f991SJulian Elischer 	 *
2232b14f991SJulian Elischer 	 * The last item on the list is expected to be the scheduler,
2242b14f991SJulian Elischer 	 * which will not return.
2252b14f991SJulian Elischer 	 */
22694e9d7c1SPeter Wemm 	for (sipp = sysinit; *sipp; sipp++) {
22774b2192aSJohn Dyson 
2282b14f991SJulian Elischer 		if ((*sipp)->subsystem == SI_SUB_DUMMY)
2292b14f991SJulian Elischer 			continue;	/* skip dummy task(s)*/
2302b14f991SJulian Elischer 
23194e9d7c1SPeter Wemm 		if ((*sipp)->subsystem == SI_SUB_DONE)
23294e9d7c1SPeter Wemm 			continue;
23394e9d7c1SPeter Wemm 
2342b14f991SJulian Elischer 		switch( (*sipp)->type) {
2352b14f991SJulian Elischer 		case SI_TYPE_DEFAULT:
2362b14f991SJulian Elischer 			/* no special processing*/
2372b14f991SJulian Elischer 			(*((*sipp)->func))((*sipp)->udata);
2382b14f991SJulian Elischer 			break;
2392b14f991SJulian Elischer 
2402b14f991SJulian Elischer 		case SI_TYPE_KTHREAD:
24174b2192aSJohn Dyson #if !defined(SMP)
2422b14f991SJulian Elischer 			/* kernel thread*/
24374b2192aSJohn Dyson 			if (fork1(&proc0, RFMEM|RFFDG|RFPROC))
24474b2192aSJohn Dyson 				panic("fork kernel thread");
24574b2192aSJohn Dyson 			cpu_set_fork_handler(pfind(proc0.p_retval[0]),
24674b2192aSJohn Dyson 			    (*sipp)->func, (*sipp)->udata);
24774b2192aSJohn Dyson 			break;
24874b2192aSJohn Dyson #endif
24974b2192aSJohn Dyson 
25074b2192aSJohn Dyson 		case SI_TYPE_KPROCESS:
25174b2192aSJohn Dyson 			if (fork1(&proc0, RFFDG|RFPROC))
2522b14f991SJulian Elischer 				panic("fork kernel process");
253cb226aaaSPoul-Henning Kamp 			cpu_set_fork_handler(pfind(proc0.p_retval[0]),
254cb226aaaSPoul-Henning Kamp 			    (*sipp)->func, (*sipp)->udata);
2552b14f991SJulian Elischer 			break;
2562b14f991SJulian Elischer 
2572b14f991SJulian Elischer 		default:
2582b14f991SJulian Elischer 			panic("init_main: unrecognized init type");
2592b14f991SJulian Elischer 		}
26094e9d7c1SPeter Wemm 
26194e9d7c1SPeter Wemm 		/* Check off the one we're just done */
26294e9d7c1SPeter Wemm 		(*sipp)->subsystem = SI_SUB_DONE;
26394e9d7c1SPeter Wemm 
26494e9d7c1SPeter Wemm 		/* Check if we've installed more sysinit items via KLD */
26594e9d7c1SPeter Wemm 		if (newsysinit != NULL) {
26694e9d7c1SPeter Wemm 			if (sysinit != (struct sysinit **)sysinit_set.ls_items)
26794e9d7c1SPeter Wemm 				free(sysinit, M_TEMP);
26894e9d7c1SPeter Wemm 			sysinit = newsysinit;
26994e9d7c1SPeter Wemm 			newsysinit = NULL;
27094e9d7c1SPeter Wemm 			goto restart;
27194e9d7c1SPeter Wemm 		}
2722b14f991SJulian Elischer 	}
2732b14f991SJulian Elischer 
274477a642cSPeter Wemm 	panic("Shouldn't get here!");
2752b14f991SJulian Elischer 	/* NOTREACHED*/
2762b14f991SJulian Elischer }
2772b14f991SJulian Elischer 
2782b14f991SJulian Elischer 
2792b14f991SJulian Elischer /*
2802b14f991SJulian Elischer  * Start a kernel process.  This is called after a fork() call in
2812b14f991SJulian Elischer  * main() in the file kern/init_main.c.
2822b14f991SJulian Elischer  *
2832b14f991SJulian Elischer  * This function is used to start "internal" daemons.
2842b14f991SJulian Elischer  */
2852b14f991SJulian Elischer /* ARGSUSED*/
2862b14f991SJulian Elischer void
2872b14f991SJulian Elischer kproc_start(udata)
288d841aaa7SBruce Evans 	void *udata;
2892b14f991SJulian Elischer {
290d841aaa7SBruce Evans 	struct kproc_desc	*kp = udata;
2912b14f991SJulian Elischer 	struct proc		*p = curproc;
2922b14f991SJulian Elischer 
293477a642cSPeter Wemm #ifdef DIAGNOSTIC
294477a642cSPeter Wemm 	printf("Start pid=%d <%s>\n",p->p_pid, kp->arg0);
295477a642cSPeter Wemm #endif
296477a642cSPeter Wemm 
2972b14f991SJulian Elischer 	/* save a global descriptor, if desired*/
2982b14f991SJulian Elischer 	if( kp->global_procpp != NULL)
2992b14f991SJulian Elischer 		*kp->global_procpp	= p;
3002b14f991SJulian Elischer 
3012b14f991SJulian Elischer 	/* this is a non-swapped system process*/
3022b14f991SJulian Elischer 	p->p_flag |= P_INMEM | P_SYSTEM;
3032b14f991SJulian Elischer 
3042b14f991SJulian Elischer 	/* set up arg0 for 'ps', et al*/
3052b14f991SJulian Elischer 	strcpy( p->p_comm, kp->arg0);
3062b14f991SJulian Elischer 
3072b14f991SJulian Elischer 	/* call the processes' main()...*/
3082b14f991SJulian Elischer 	(*kp->func)();
3092b14f991SJulian Elischer 
3102b14f991SJulian Elischer 	/* NOTREACHED */
3112b14f991SJulian Elischer 	panic("kproc_start: %s", kp->arg0);
3122b14f991SJulian Elischer }
3132b14f991SJulian Elischer 
3142b14f991SJulian Elischer 
3152b14f991SJulian Elischer /*
3162b14f991SJulian Elischer  ***************************************************************************
3172b14f991SJulian Elischer  ****
3182b14f991SJulian Elischer  **** The following SYSINIT's belong elsewhere, but have not yet
3192b14f991SJulian Elischer  **** been moved.
3202b14f991SJulian Elischer  ****
3212b14f991SJulian Elischer  ***************************************************************************
3222b14f991SJulian Elischer  */
3232b14f991SJulian Elischer #ifdef OMIT
3242b14f991SJulian Elischer /*
3252b14f991SJulian Elischer  * Handled by vfs_mountroot (bad idea) at this time... should be
3262b14f991SJulian Elischer  * done the same as 4.4Lite2.
3272b14f991SJulian Elischer  */
3282b14f991SJulian Elischer SYSINIT(swapinit, SI_SUB_SWAP, SI_ORDER_FIRST, swapinit, NULL)
3292b14f991SJulian Elischer #endif	/* OMIT*/
3302b14f991SJulian Elischer 
3314590fd3aSDavid Greenman static void print_caddr_t __P((void *data));
3329ef6c28aSBruce Evans static void
3339ef6c28aSBruce Evans print_caddr_t(data)
3344590fd3aSDavid Greenman 	void *data;
3359ef6c28aSBruce Evans {
3369ef6c28aSBruce Evans 	printf("%s", (char *)data);
3379ef6c28aSBruce Evans }
338d841aaa7SBruce Evans SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t, copyright)
3392b14f991SJulian Elischer 
3402b14f991SJulian Elischer 
3412b14f991SJulian Elischer /*
3422b14f991SJulian Elischer  ***************************************************************************
3432b14f991SJulian Elischer  ****
3442b14f991SJulian Elischer  **** The two following SYSINT's are proc0 specific glue code.  I am not
3452b14f991SJulian Elischer  **** convinced that they can not be safely combined, but their order of
3462b14f991SJulian Elischer  **** operation has been maintained as the same as the original init_main.c
3472b14f991SJulian Elischer  **** for right now.
3482b14f991SJulian Elischer  ****
3492b14f991SJulian Elischer  **** These probably belong in init_proc.c or kern_proc.c, since they
3502b14f991SJulian Elischer  **** deal with proc0 (the fork template process).
3512b14f991SJulian Elischer  ****
3522b14f991SJulian Elischer  ***************************************************************************
3532b14f991SJulian Elischer  */
3542b14f991SJulian Elischer /* ARGSUSED*/
355154c04e5SPoul-Henning Kamp static void proc0_init __P((void *dummy));
356154c04e5SPoul-Henning Kamp static void
357d841aaa7SBruce Evans proc0_init(dummy)
358d841aaa7SBruce Evans 	void *dummy;
3592b14f991SJulian Elischer {
360df8bae1dSRodney W. Grimes 	register struct proc		*p;
361df8bae1dSRodney W. Grimes 	register struct filedesc0	*fdp;
36292579404SAlexander Langer 	register unsigned i;
363df8bae1dSRodney W. Grimes 
364df8bae1dSRodney W. Grimes 	/*
365df8bae1dSRodney W. Grimes 	 * Initialize the current process pointer (curproc) before
366df8bae1dSRodney W. Grimes 	 * any possible traps/probes to simplify trap processing.
367df8bae1dSRodney W. Grimes 	 */
368df8bae1dSRodney W. Grimes 	p = &proc0;
3692b14f991SJulian Elischer 	curproc = p;			/* XXX redundant*/
370df8bae1dSRodney W. Grimes 
371df8bae1dSRodney W. Grimes 	/*
372a3bfb996SJeffrey Hsu 	 * Initialize process and pgrp structures.
373a3bfb996SJeffrey Hsu 	 */
374a3bfb996SJeffrey Hsu 	procinit();
375a3bfb996SJeffrey Hsu 
376a3bfb996SJeffrey Hsu 	/*
377b1508c72SDavid Greenman 	 * Initialize sleep queue hash table
378b1508c72SDavid Greenman 	 */
379b1508c72SDavid Greenman 	sleepinit();
380b1508c72SDavid Greenman 
381b1508c72SDavid Greenman 	/*
3823075778bSJohn Dyson 	 * additional VM structures
3833075778bSJohn Dyson 	 */
3843075778bSJohn Dyson 	vm_init2();
3853075778bSJohn Dyson 
3863075778bSJohn Dyson 	/*
387df8bae1dSRodney W. Grimes 	 * Create process 0 (the swapper).
388df8bae1dSRodney W. Grimes 	 */
389a3bfb996SJeffrey Hsu 	LIST_INSERT_HEAD(&allproc, p, p_list);
390df8bae1dSRodney W. Grimes 	p->p_pgrp = &pgrp0;
391a3bfb996SJeffrey Hsu 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
392a3bfb996SJeffrey Hsu 	LIST_INIT(&pgrp0.pg_members);
393a3bfb996SJeffrey Hsu 	LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
394a3bfb996SJeffrey Hsu 
395df8bae1dSRodney W. Grimes 	pgrp0.pg_session = &session0;
396df8bae1dSRodney W. Grimes 	session0.s_count = 1;
397df8bae1dSRodney W. Grimes 	session0.s_leader = p;
398df8bae1dSRodney W. Grimes 
399f3f0ca60SSøren Schmidt 	p->p_sysent = &aout_sysvec;
400f3f0ca60SSøren Schmidt 
401df8bae1dSRodney W. Grimes 	p->p_flag = P_INMEM | P_SYSTEM;
402df8bae1dSRodney W. Grimes 	p->p_stat = SRUN;
403df8bae1dSRodney W. Grimes 	p->p_nice = NZERO;
4047216391eSDavid Greenman 	p->p_rtprio.type = RTP_PRIO_NORMAL;
4057216391eSDavid Greenman 	p->p_rtprio.prio = 0;
406f992f480SDavid Greenman 
4072c1011f7SJohn Dyson /*
4082c1011f7SJohn Dyson  * Link for kernel based threads
4092c1011f7SJohn Dyson  */
4102c1011f7SJohn Dyson 	p->p_peers = 0;
4112c1011f7SJohn Dyson 	p->p_leader = p;
4122c1011f7SJohn Dyson 
413df8bae1dSRodney W. Grimes 	bcopy("swapper", p->p_comm, sizeof ("swapper"));
414df8bae1dSRodney W. Grimes 
415df8bae1dSRodney W. Grimes 	/* Create credentials. */
416df8bae1dSRodney W. Grimes 	cred0.p_refcnt = 1;
417df8bae1dSRodney W. Grimes 	p->p_cred = &cred0;
418df8bae1dSRodney W. Grimes 	p->p_ucred = crget();
419df8bae1dSRodney W. Grimes 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
420df8bae1dSRodney W. Grimes 
4216626c604SJulian Elischer #ifdef COMPAT_LINUX_THREADS
4226626c604SJulian Elischer 	/* Create procsig. */
4236626c604SJulian Elischer 	p->p_procsig = &procsig0;
4246626c604SJulian Elischer 	p->p_procsig->ps_refcnt = 2;
4256626c604SJulian Elischer 
4266626c604SJulian Elischer #endif /* COMPAT_LINUX_THREADS */
427df8bae1dSRodney W. Grimes 	/* Create the file descriptor table. */
428df8bae1dSRodney W. Grimes 	fdp = &filedesc0;
429df8bae1dSRodney W. Grimes 	p->p_fd = &fdp->fd_fd;
430df8bae1dSRodney W. Grimes 	fdp->fd_fd.fd_refcnt = 1;
431df8bae1dSRodney W. Grimes 	fdp->fd_fd.fd_cmask = cmask;
432df8bae1dSRodney W. Grimes 	fdp->fd_fd.fd_ofiles = fdp->fd_dfiles;
433df8bae1dSRodney W. Grimes 	fdp->fd_fd.fd_ofileflags = fdp->fd_dfileflags;
434df8bae1dSRodney W. Grimes 	fdp->fd_fd.fd_nfiles = NDFILE;
435df8bae1dSRodney W. Grimes 
436df8bae1dSRodney W. Grimes 	/* Create the limits structures. */
437df8bae1dSRodney W. Grimes 	p->p_limit = &limit0;
438df8bae1dSRodney W. Grimes 	for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
439df8bae1dSRodney W. Grimes 		limit0.pl_rlimit[i].rlim_cur =
440df8bae1dSRodney W. Grimes 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
441b3c5c18dSBruce Evans 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur =
442b3c5c18dSBruce Evans 	    limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles;
443b3c5c18dSBruce Evans 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur =
444b3c5c18dSBruce Evans 	    limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
445df8bae1dSRodney W. Grimes 	i = ptoa(cnt.v_free_count);
446df8bae1dSRodney W. Grimes 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = i;
447df8bae1dSRodney W. Grimes 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = i;
448df8bae1dSRodney W. Grimes 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = i / 3;
449e796e00dSPoul-Henning Kamp 	limit0.p_cpulimit = RLIM_INFINITY;
450df8bae1dSRodney W. Grimes 	limit0.p_refcnt = 1;
451df8bae1dSRodney W. Grimes 
452e796e00dSPoul-Henning Kamp 
453df8bae1dSRodney W. Grimes 	/* Allocate a prototype map so we have something to fork. */
454a2481bbeSPoul-Henning Kamp 	pmap_pinit0(&vmspace0.vm_pmap);
455df8bae1dSRodney W. Grimes 	p->p_vmspace = &vmspace0;
456df8bae1dSRodney W. Grimes 	vmspace0.vm_refcnt = 1;
45726f9a767SRodney W. Grimes 	vm_map_init(&vmspace0.vm_map, round_page(VM_MIN_ADDRESS),
4582d8acc0fSJohn Dyson 	    trunc_page(VM_MAXUSER_ADDRESS));
459df8bae1dSRodney W. Grimes 	vmspace0.vm_map.pmap = &vmspace0.vm_pmap;
460df8bae1dSRodney W. Grimes 	p->p_addr = proc0paddr;				/* XXX */
461df8bae1dSRodney W. Grimes 
462ecbb00a2SDoug Rabson #ifndef __alpha__		/* XXX what is this? */
4632b14f991SJulian Elischer #define INCOMPAT_LITES2
4642b14f991SJulian Elischer #ifdef INCOMPAT_LITES2
465df8bae1dSRodney W. Grimes 	/*
466dc733423SDag-Erling Smørgrav 	 * proc0 needs to have a coherent frame base in its stack.
4672384fde5SDavid Greenman 	 */
4682b14f991SJulian Elischer 	cpu_set_init_frame(p, init_framep);			/* XXX! */
4692b14f991SJulian Elischer #endif	/* INCOMPAT_LITES2*/
470ecbb00a2SDoug Rabson #endif
4712384fde5SDavid Greenman 
4726626c604SJulian Elischer #ifndef COMPAT_LINUX_THREADS
47339fb8e6bSJulian Elischer 	/*
474df8bae1dSRodney W. Grimes 	 * We continue to place resource usage info and signal
475df8bae1dSRodney W. Grimes 	 * actions in the user struct so they're pageable.
476df8bae1dSRodney W. Grimes 	 */
477df8bae1dSRodney W. Grimes 	p->p_stats = &p->p_addr->u_stats;
478df8bae1dSRodney W. Grimes 	p->p_sigacts = &p->p_addr->u_sigacts;
4796626c604SJulian Elischer #else
48039fb8e6bSJulian Elischer 	/*
4816626c604SJulian Elischer 	 * We continue to place resource usage info in the user struct so
4826626c604SJulian Elischer 	 * it's pageable.
4836626c604SJulian Elischer 	 */
4846626c604SJulian Elischer 	p->p_stats = &p->p_addr->u_stats;
4856626c604SJulian Elischer 
4866626c604SJulian Elischer 	p->p_sigacts = &p->p_procsig->ps_sigacts;
4876626c604SJulian Elischer #endif /* COMPAT_LINUX_THREADS */
488df8bae1dSRodney W. Grimes 
489df8bae1dSRodney W. Grimes 	/*
490a3bfb996SJeffrey Hsu 	 * Charge root for one process.
491df8bae1dSRodney W. Grimes 	 */
492df8bae1dSRodney W. Grimes 	(void)chgproccnt(0, 1);
4932a024a2bSSean Eric Fagan 
4942a024a2bSSean Eric Fagan 	/*
4952a024a2bSSean Eric Fagan 	 * Initialize the procfs flags (to 0, of course)
4962a024a2bSSean Eric Fagan 	 */
4972a024a2bSSean Eric Fagan 	p->p_stops = p->p_stype = p->p_step = 0;
4982a024a2bSSean Eric Fagan 
49926f9a767SRodney W. Grimes }
5002b14f991SJulian Elischer SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL)
5012b14f991SJulian Elischer 
5022b14f991SJulian Elischer /* ARGSUSED*/
503154c04e5SPoul-Henning Kamp static void proc0_post __P((void *dummy));
504154c04e5SPoul-Henning Kamp static void
505d841aaa7SBruce Evans proc0_post(dummy)
506d841aaa7SBruce Evans 	void *dummy;
5072b14f991SJulian Elischer {
50800af9731SPoul-Henning Kamp 	struct timespec ts;
509a6fc8288SPeter Wemm 
5102b14f991SJulian Elischer 	/*
5112b14f991SJulian Elischer 	 * Now can look at time, having had a chance to verify the time
512e796e00dSPoul-Henning Kamp 	 * from the file system.  Reset p->p_runtime as it may have been
5135f88ec36SPoul-Henning Kamp 	 * munched in mi_switch() after the time got set.  Set
514e796e00dSPoul-Henning Kamp 	 * p->p_switchtime to be consistent with this unmunching.
5152b14f991SJulian Elischer 	 */
5165f88ec36SPoul-Henning Kamp 	microtime(&proc0.p_stats->p_start);
517e796e00dSPoul-Henning Kamp 	proc0.p_runtime = 0;
518e796e00dSPoul-Henning Kamp 	microuptime(&proc0.p_switchtime);
5192b14f991SJulian Elischer 
520a6fc8288SPeter Wemm 	/*
521a6fc8288SPeter Wemm 	 * Give the ``random'' number generator a thump.
5225f88ec36SPoul-Henning Kamp 	 * XXX: Does read_random() contain enough bits to be used here ?
523a6fc8288SPeter Wemm 	 */
52400af9731SPoul-Henning Kamp 	nanotime(&ts);
52500af9731SPoul-Henning Kamp 	srandom(ts.tv_sec ^ ts.tv_nsec);
526a6fc8288SPeter Wemm 
5272b14f991SJulian Elischer 	/* Initialize signal state for process 0. */
5282b14f991SJulian Elischer 	siginit(&proc0);
5292b14f991SJulian Elischer }
5302b14f991SJulian Elischer SYSINIT(p0post, SI_SUB_INTRINSIC_POST, SI_ORDER_FIRST, proc0_post, NULL)
5312b14f991SJulian Elischer 
5322b14f991SJulian Elischer 
5332b14f991SJulian Elischer 
534df8bae1dSRodney W. Grimes 
535df8bae1dSRodney W. Grimes /*
5362b14f991SJulian Elischer  ***************************************************************************
5372b14f991SJulian Elischer  ****
5382b14f991SJulian Elischer  **** The following SYSINIT's and glue code should be moved to the
5392b14f991SJulian Elischer  **** respective files on a per subsystem basis.
5402b14f991SJulian Elischer  ****
5412b14f991SJulian Elischer  ***************************************************************************
542df8bae1dSRodney W. Grimes  */
543df8bae1dSRodney W. Grimes 
5442b14f991SJulian Elischer /* ARGSUSED */
545ab36c067SJustin T. Gibbs static void root_conf __P((void *dummy));
546ab36c067SJustin T. Gibbs static void
547ab36c067SJustin T. Gibbs root_conf(dummy)
548ab36c067SJustin T. Gibbs 	void *dummy;
549ab36c067SJustin T. Gibbs {
550ab36c067SJustin T. Gibbs 	cpu_rootconf();
551ab36c067SJustin T. Gibbs }
552ab36c067SJustin T. Gibbs SYSINIT(root_conf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, root_conf, NULL)
553ab36c067SJustin T. Gibbs 
554ab36c067SJustin T. Gibbs /* ARGSUSED*/
555154c04e5SPoul-Henning Kamp static void xxx_vfs_root_fdtab __P((void *dummy));
556154c04e5SPoul-Henning Kamp static void
557d841aaa7SBruce Evans xxx_vfs_root_fdtab(dummy)
558d841aaa7SBruce Evans 	void *dummy;
5592b14f991SJulian Elischer {
5602b14f991SJulian Elischer 	register struct filedesc0	*fdp = &filedesc0;
561df8bae1dSRodney W. Grimes 
562df8bae1dSRodney W. Grimes 	/* Get the vnode for '/'.  Set fdp->fd_fd.fd_cdir to reference it. */
563628641f8SDavid Greenman 	if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
564df8bae1dSRodney W. Grimes 		panic("cannot find root vnode");
565df8bae1dSRodney W. Grimes 	fdp->fd_fd.fd_cdir = rootvnode;
566df8bae1dSRodney W. Grimes 	VREF(fdp->fd_fd.fd_cdir);
567996c772fSJohn Dyson 	VOP_UNLOCK(rootvnode, 0, &proc0);
5689f24f214SJohn Dyson 	fdp->fd_fd.fd_rdir = rootvnode;
5692b14f991SJulian Elischer }
5702b14f991SJulian Elischer SYSINIT(retrofit, SI_SUB_ROOT_FDTAB, SI_ORDER_FIRST, xxx_vfs_root_fdtab, NULL)
5712b14f991SJulian Elischer 
572df8bae1dSRodney W. Grimes 
573df8bae1dSRodney W. Grimes /*
5742b14f991SJulian Elischer  ***************************************************************************
5752b14f991SJulian Elischer  ****
5762b14f991SJulian Elischer  **** The following code probably belongs in another file, like
5772b14f991SJulian Elischer  **** kern/init_init.c.  It is here for two reasons only:
5782b14f991SJulian Elischer  ****
5792b14f991SJulian Elischer  ****	1)	This code returns to startup the system; this is
5802b14f991SJulian Elischer  ****		abnormal for a kernel thread.
5812b14f991SJulian Elischer  ****	2)	This code promiscuously uses init_frame
5822b14f991SJulian Elischer  ****
5832b14f991SJulian Elischer  ***************************************************************************
584df8bae1dSRodney W. Grimes  */
585df8bae1dSRodney W. Grimes 
586d841aaa7SBruce Evans static void kthread_init __P((void *dummy));
58774b2192aSJohn Dyson SYSINIT_KP(init,SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kthread_init, NULL)
5882b14f991SJulian Elischer 
5892b14f991SJulian Elischer 
590a2a1c95cSPeter Wemm extern void prepare_usermode __P((void));
591a2a1c95cSPeter Wemm static void start_init __P((struct proc *p));
5922b14f991SJulian Elischer 
5932b14f991SJulian Elischer /* ARGSUSED*/
5942b14f991SJulian Elischer static void
595d841aaa7SBruce Evans kthread_init(dummy)
596d841aaa7SBruce Evans 	void *dummy;
5972b14f991SJulian Elischer {
598df8bae1dSRodney W. Grimes 	/* Create process 1 (init(8)). */
599a2a1c95cSPeter Wemm 	start_init(curproc);
600a2a1c95cSPeter Wemm 
601a2a1c95cSPeter Wemm 	prepare_usermode();
6022b14f991SJulian Elischer 
6032b14f991SJulian Elischer 	/*
604a2a1c95cSPeter Wemm 	 * This returns to the fork trampoline, then to user mode.
6052b14f991SJulian Elischer 	 */
606df8bae1dSRodney W. Grimes 	return;
607df8bae1dSRodney W. Grimes }
608df8bae1dSRodney W. Grimes 
609df8bae1dSRodney W. Grimes 
610df8bae1dSRodney W. Grimes /*
611df8bae1dSRodney W. Grimes  * List of paths to try when searching for "init".
612df8bae1dSRodney W. Grimes  */
613df8bae1dSRodney W. Grimes static char *initpaths[] = {
614df8bae1dSRodney W. Grimes 	"/sbin/init",
615df8bae1dSRodney W. Grimes 	"/sbin/oinit",
616df8bae1dSRodney W. Grimes 	"/sbin/init.bak",
6172257b745SPoul-Henning Kamp 	"/stand/sysinstall",
618df8bae1dSRodney W. Grimes 	NULL,
619df8bae1dSRodney W. Grimes };
620df8bae1dSRodney W. Grimes 
621df8bae1dSRodney W. Grimes /*
622df8bae1dSRodney W. Grimes  * Start the initial user process; try exec'ing each pathname in "initpaths".
623df8bae1dSRodney W. Grimes  * The program is invoked with one argument containing the boot flags.
624df8bae1dSRodney W. Grimes  */
625df8bae1dSRodney W. Grimes static void
626a2a1c95cSPeter Wemm start_init(p)
627df8bae1dSRodney W. Grimes 	struct proc *p;
628df8bae1dSRodney W. Grimes {
629df8bae1dSRodney W. Grimes 	vm_offset_t addr;
630df8bae1dSRodney W. Grimes 	struct execve_args args;
6314a11ca4eSPoul-Henning Kamp 	int options, i, error;
632df8bae1dSRodney W. Grimes 	char **pathp, *path, *ucp, **uap, *arg0, *arg1;
633df8bae1dSRodney W. Grimes 
634df8bae1dSRodney W. Grimes 	initproc = p;
635df8bae1dSRodney W. Grimes 
636df8bae1dSRodney W. Grimes 	/*
637df8bae1dSRodney W. Grimes 	 * Need just enough stack to hold the faked-up "execve()" arguments.
638df8bae1dSRodney W. Grimes 	 */
63926f9a767SRodney W. Grimes 	addr = trunc_page(VM_MAXUSER_ADDRESS - PAGE_SIZE);
640bd7e5f99SJohn Dyson 	if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0)
641df8bae1dSRodney W. Grimes 		panic("init: couldn't allocate argument space");
642df8bae1dSRodney W. Grimes 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
64326f9a767SRodney W. Grimes 	p->p_vmspace->vm_ssize = 1;
644df8bae1dSRodney W. Grimes 
645df8bae1dSRodney W. Grimes 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
646df8bae1dSRodney W. Grimes 		/*
647df8bae1dSRodney W. Grimes 		 * Move out the boot flag argument.
648df8bae1dSRodney W. Grimes 		 */
649df8bae1dSRodney W. Grimes 		options = 0;
650df8bae1dSRodney W. Grimes 		ucp = (char *)USRSTACK;
651df8bae1dSRodney W. Grimes 		(void)subyte(--ucp, 0);		/* trailing zero */
652df8bae1dSRodney W. Grimes 		if (boothowto & RB_SINGLE) {
653df8bae1dSRodney W. Grimes 			(void)subyte(--ucp, 's');
654df8bae1dSRodney W. Grimes 			options = 1;
655df8bae1dSRodney W. Grimes 		}
656df8bae1dSRodney W. Grimes #ifdef notyet
657df8bae1dSRodney W. Grimes                 if (boothowto & RB_FASTBOOT) {
658df8bae1dSRodney W. Grimes 			(void)subyte(--ucp, 'f');
659df8bae1dSRodney W. Grimes 			options = 1;
660df8bae1dSRodney W. Grimes 		}
661df8bae1dSRodney W. Grimes #endif
66217755ac8SPoul-Henning Kamp 
66317755ac8SPoul-Henning Kamp #ifdef BOOTCDROM
66417755ac8SPoul-Henning Kamp 		(void)subyte(--ucp, 'C');
66517755ac8SPoul-Henning Kamp 		options = 1;
66617755ac8SPoul-Henning Kamp #endif
667df8bae1dSRodney W. Grimes 		if (options == 0)
668df8bae1dSRodney W. Grimes 			(void)subyte(--ucp, '-');
669df8bae1dSRodney W. Grimes 		(void)subyte(--ucp, '-');		/* leading hyphen */
670df8bae1dSRodney W. Grimes 		arg1 = ucp;
671df8bae1dSRodney W. Grimes 
672df8bae1dSRodney W. Grimes 		/*
673df8bae1dSRodney W. Grimes 		 * Move out the file name (also arg 0).
674df8bae1dSRodney W. Grimes 		 */
675df8bae1dSRodney W. Grimes 		for (i = strlen(path) + 1; i >= 0; i--)
676df8bae1dSRodney W. Grimes 			(void)subyte(--ucp, path[i]);
677df8bae1dSRodney W. Grimes 		arg0 = ucp;
678df8bae1dSRodney W. Grimes 
679df8bae1dSRodney W. Grimes 		/*
680df8bae1dSRodney W. Grimes 		 * Move out the arg pointers.
681df8bae1dSRodney W. Grimes 		 */
682a20d7755SDoug Rabson 		uap = (char **)((intptr_t)ucp & ~(sizeof(intptr_t)-1));
683c2da0fd9SBruce Evans 		(void)suword((caddr_t)--uap, (long)0);	/* terminator */
684c2da0fd9SBruce Evans 		(void)suword((caddr_t)--uap, (long)(intptr_t)arg1);
685c2da0fd9SBruce Evans 		(void)suword((caddr_t)--uap, (long)(intptr_t)arg0);
686df8bae1dSRodney W. Grimes 
687df8bae1dSRodney W. Grimes 		/*
688df8bae1dSRodney W. Grimes 		 * Point at the arguments.
689df8bae1dSRodney W. Grimes 		 */
690df8bae1dSRodney W. Grimes 		args.fname = arg0;
69126f9a767SRodney W. Grimes 		args.argv = uap;
69226f9a767SRodney W. Grimes 		args.envv = NULL;
693df8bae1dSRodney W. Grimes 
694df8bae1dSRodney W. Grimes 		/*
695df8bae1dSRodney W. Grimes 		 * Now try to exec the program.  If can't for any reason
696df8bae1dSRodney W. Grimes 		 * other than it doesn't exist, complain.
6972b14f991SJulian Elischer 		 *
6982b14f991SJulian Elischer 		 * Otherwise return to main() which returns to btext
6992b14f991SJulian Elischer 		 * which completes the system startup.
700df8bae1dSRodney W. Grimes 		 */
701cb226aaaSPoul-Henning Kamp 		if ((error = execve(p, &args)) == 0)
702df8bae1dSRodney W. Grimes 			return;
703df8bae1dSRodney W. Grimes 		if (error != ENOENT)
704df8bae1dSRodney W. Grimes 			printf("exec %s: error %d\n", path, error);
705df8bae1dSRodney W. Grimes 	}
706df8bae1dSRodney W. Grimes 	printf("init: not found\n");
707df8bae1dSRodney W. Grimes 	panic("no init");
708df8bae1dSRodney W. Grimes }
709