xref: /freebsd/sys/kern/init_main.c (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
1 /*
2  * Copyright (c) 1995 Terrence R. Lambert
3  * All rights reserved.
4  *
5  * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  * (c) UNIX System Laboratories, Inc.
8  * All or some portions of this file are derived from material licensed
9  * to the University of California by American Telephone and Telegraph
10  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11  * the permission of UNIX System Laboratories, Inc.
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 by the University of
24  *	California, Berkeley and its contributors.
25  * 4. Neither the name of the University nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  *	@(#)init_main.c	8.9 (Berkeley) 1/21/94
42  * $Id: init_main.c,v 1.102 1998/12/30 10:38:58 dfr Exp $
43  */
44 
45 #include "opt_devfs.h"
46 
47 #include <sys/param.h>
48 #include <sys/file.h>
49 #include <sys/filedesc.h>
50 #include <sys/kernel.h>
51 #include <sys/mount.h>
52 #include <sys/sysctl.h>
53 #include <sys/proc.h>
54 #include <sys/resourcevar.h>
55 #include <sys/signalvar.h>
56 #include <sys/systm.h>
57 #include <sys/vnode.h>
58 #include <sys/sysent.h>
59 #include <sys/reboot.h>
60 #include <sys/sysproto.h>
61 #include <sys/vmmeter.h>
62 #include <sys/unistd.h>
63 #include <sys/malloc.h>
64 
65 #include <machine/cpu.h>
66 
67 #include <vm/vm.h>
68 #include <vm/vm_param.h>
69 #include <vm/vm_prot.h>
70 #include <sys/lock.h>
71 #include <vm/pmap.h>
72 #include <vm/vm_map.h>
73 #include <sys/user.h>
74 #include <sys/copyright.h>
75 
76 extern struct linker_set	sysinit_set;	/* XXX */
77 
78 extern void __main __P((void));
79 extern void main __P((void *framep));
80 
81 /* Components of the first process -- never freed. */
82 static struct session session0;
83 static struct pgrp pgrp0;
84 struct	proc proc0;
85 static struct pcred cred0;
86 #ifdef COMPAT_LINUX_THREADS
87 static struct procsig procsig0;
88 #endif /* COMPAT_LINUX_THREADS */
89 static struct filedesc0 filedesc0;
90 static struct plimit limit0;
91 static struct vmspace vmspace0;
92 struct	proc *initproc;
93 
94 int cmask = CMASK;
95 extern	struct user *proc0paddr;
96 
97 struct	vnode *rootvp;
98 int	boothowto = 0;		/* initialized so that it can be patched */
99 
100 struct	timeval boottime;
101 SYSCTL_STRUCT(_kern, KERN_BOOTTIME, boottime,
102 	CTLFLAG_RD, &boottime, timeval, "");
103 
104 static int shutdowntimeout = 120;
105 SYSCTL_INT(_kern, OID_AUTO, shutdown_timeout,
106 	CTLFLAG_RW, &shutdowntimeout, 0, "");
107 
108 /*
109  * Promiscuous argument pass for start_init()
110  *
111  * This is a kludge because we use a return from main() rather than a call
112  * to a new routine in locore.s to kick the kernel alive from locore.s.
113  */
114 static void	*init_framep;
115 
116 
117 #if __GNUC__ >= 2
118 void __main() {}
119 #endif
120 
121 
122 /*
123  * This ensures that there is at least one entry so that the sysinit_set
124  * symbol is not undefined.  A sybsystem ID of SI_SUB_DUMMY is never
125  * executed.
126  */
127 SYSINIT(placeholder, SI_SUB_DUMMY,SI_ORDER_ANY, NULL, NULL)
128 
129 /*
130  * The sysinit table itself.  Items are checked off as the are run.
131  * If we want to register new sysinit types, add them to newsysinit.
132  */
133 struct sysinit **sysinit = (struct sysinit **)sysinit_set.ls_items;
134 struct sysinit **newsysinit;
135 
136 /*
137  * Merge a new sysinit set into the current set, reallocating it if
138  * necessary.  This can only be called after malloc is running.
139  */
140 void
141 sysinit_add(set)
142 	struct sysinit **set;
143 {
144 	struct sysinit **newset;
145 	struct sysinit **sipp;
146 	struct sysinit **xipp;
147 	int count = 0;
148 
149 	if (newsysinit)
150 		for (sipp = newsysinit; *sipp; sipp++)
151 			count++;
152 	else
153 		for (sipp = sysinit; *sipp; sipp++)
154 			count++;
155 	for (sipp = set; *sipp; sipp++)
156 		count++;
157 	count++;		/* Trailing NULL */
158 	newset = malloc(count * sizeof(*sipp), M_TEMP, M_NOWAIT);
159 	if (newset == NULL)
160 		panic("cannot malloc for sysinit");
161 	xipp = newset;
162 	if (newsysinit)
163 		for (sipp = newsysinit; *sipp; sipp++)
164 			*xipp++ = *sipp;
165 	else
166 		for (sipp = sysinit; *sipp; sipp++)
167 			*xipp++ = *sipp;
168 	for (sipp = set; *sipp; sipp++)
169 		*xipp++ = *sipp;
170 	*xipp = NULL;
171 	if (newsysinit)
172 		free(newsysinit, M_TEMP);
173 	newsysinit = newset;
174 }
175 
176 /*
177  * System startup; initialize the world, create process 0, mount root
178  * filesystem, and fork to create init and pagedaemon.  Most of the
179  * hard work is done in the lower-level initialization routines including
180  * startup(), which does memory initialization and autoconfiguration.
181  *
182  * This allows simple addition of new kernel subsystems that require
183  * boot time initialization.  It also allows substitution of subsystem
184  * (for instance, a scheduler, kernel profiler, or VM system) by object
185  * module.  Finally, it allows for optional "kernel threads".
186  */
187 void
188 main(framep)
189 	void *framep;
190 {
191 
192 	register struct sysinit **sipp;		/* system initialization*/
193 	register struct sysinit **xipp;		/* interior loop of sort*/
194 	register struct sysinit *save;		/* bubble*/
195 
196 	/*
197 	 * Copy the locore.s frame pointer for proc0, this is forked into
198 	 * all other processes.
199 	 */
200 	init_framep = framep;
201 
202 restart:
203 	/*
204 	 * Perform a bubble sort of the system initialization objects by
205 	 * their subsystem (primary key) and order (secondary key).
206 	 */
207 	for (sipp = sysinit; *sipp; sipp++) {
208 		for (xipp = sipp + 1; *xipp; xipp++) {
209 			if ((*sipp)->subsystem < (*xipp)->subsystem ||
210 			     ((*sipp)->subsystem == (*xipp)->subsystem &&
211 			      (*sipp)->order < (*xipp)->order))
212 				continue;	/* skip*/
213 			save = *sipp;
214 			*sipp = *xipp;
215 			*xipp = save;
216 		}
217 	}
218 
219 	/*
220 	 * Traverse the (now) ordered list of system initialization tasks.
221 	 * Perform each task, and continue on to the next task.
222 	 *
223 	 * The last item on the list is expected to be the scheduler,
224 	 * which will not return.
225 	 */
226 	for (sipp = sysinit; *sipp; sipp++) {
227 
228 		if ((*sipp)->subsystem == SI_SUB_DUMMY)
229 			continue;	/* skip dummy task(s)*/
230 
231 		if ((*sipp)->subsystem == SI_SUB_DONE)
232 			continue;
233 
234 		switch( (*sipp)->type) {
235 		case SI_TYPE_DEFAULT:
236 			/* no special processing*/
237 			(*((*sipp)->func))((*sipp)->udata);
238 			break;
239 
240 		case SI_TYPE_KTHREAD:
241 #if !defined(SMP)
242 			/* kernel thread*/
243 			if (fork1(&proc0, RFMEM|RFFDG|RFPROC))
244 				panic("fork kernel thread");
245 			cpu_set_fork_handler(pfind(proc0.p_retval[0]),
246 			    (*sipp)->func, (*sipp)->udata);
247 			break;
248 #endif
249 
250 		case SI_TYPE_KPROCESS:
251 			if (fork1(&proc0, RFFDG|RFPROC))
252 				panic("fork kernel process");
253 			cpu_set_fork_handler(pfind(proc0.p_retval[0]),
254 			    (*sipp)->func, (*sipp)->udata);
255 			break;
256 
257 		default:
258 			panic("init_main: unrecognized init type");
259 		}
260 
261 		/* Check off the one we're just done */
262 		(*sipp)->subsystem = SI_SUB_DONE;
263 
264 		/* Check if we've installed more sysinit items via KLD */
265 		if (newsysinit != NULL) {
266 			if (sysinit != (struct sysinit **)sysinit_set.ls_items)
267 				free(sysinit, M_TEMP);
268 			sysinit = newsysinit;
269 			newsysinit = NULL;
270 			goto restart;
271 		}
272 	}
273 
274 	panic("Shouldn't get here!");
275 	/* NOTREACHED*/
276 }
277 
278 
279 /*
280  * Start a kernel process.  This is called after a fork() call in
281  * main() in the file kern/init_main.c.
282  *
283  * This function is used to start "internal" daemons.
284  */
285 /* ARGSUSED*/
286 void
287 kproc_start(udata)
288 	void *udata;
289 {
290 	struct kproc_desc	*kp = udata;
291 	struct proc		*p = curproc;
292 
293 #ifdef DIAGNOSTIC
294 	printf("Start pid=%d <%s>\n",p->p_pid, kp->arg0);
295 #endif
296 
297 	/* save a global descriptor, if desired*/
298 	if( kp->global_procpp != NULL)
299 		*kp->global_procpp	= p;
300 
301 	/* this is a non-swapped system process*/
302 	p->p_flag |= P_INMEM | P_SYSTEM;
303 
304 	/* set up arg0 for 'ps', et al*/
305 	strcpy( p->p_comm, kp->arg0);
306 
307 	/* call the processes' main()...*/
308 	(*kp->func)();
309 
310 	/* NOTREACHED */
311 	panic("kproc_start: %s", kp->arg0);
312 }
313 
314 
315 /*
316  ***************************************************************************
317  ****
318  **** The following SYSINIT's belong elsewhere, but have not yet
319  **** been moved.
320  ****
321  ***************************************************************************
322  */
323 #ifdef OMIT
324 /*
325  * Handled by vfs_mountroot (bad idea) at this time... should be
326  * done the same as 4.4Lite2.
327  */
328 SYSINIT(swapinit, SI_SUB_SWAP, SI_ORDER_FIRST, swapinit, NULL)
329 #endif	/* OMIT*/
330 
331 static void print_caddr_t __P((void *data));
332 static void
333 print_caddr_t(data)
334 	void *data;
335 {
336 	printf("%s", (char *)data);
337 }
338 SYSINIT(announce, SI_SUB_COPYRIGHT, SI_ORDER_FIRST, print_caddr_t, copyright)
339 
340 
341 /*
342  ***************************************************************************
343  ****
344  **** The two following SYSINT's are proc0 specific glue code.  I am not
345  **** convinced that they can not be safely combined, but their order of
346  **** operation has been maintained as the same as the original init_main.c
347  **** for right now.
348  ****
349  **** These probably belong in init_proc.c or kern_proc.c, since they
350  **** deal with proc0 (the fork template process).
351  ****
352  ***************************************************************************
353  */
354 /* ARGSUSED*/
355 static void proc0_init __P((void *dummy));
356 static void
357 proc0_init(dummy)
358 	void *dummy;
359 {
360 	register struct proc		*p;
361 	register struct filedesc0	*fdp;
362 	register unsigned i;
363 
364 	/*
365 	 * Initialize the current process pointer (curproc) before
366 	 * any possible traps/probes to simplify trap processing.
367 	 */
368 	p = &proc0;
369 	curproc = p;			/* XXX redundant*/
370 
371 	/*
372 	 * Initialize process and pgrp structures.
373 	 */
374 	procinit();
375 
376 	/*
377 	 * Initialize sleep queue hash table
378 	 */
379 	sleepinit();
380 
381 	/*
382 	 * additional VM structures
383 	 */
384 	vm_init2();
385 
386 	/*
387 	 * Create process 0 (the swapper).
388 	 */
389 	LIST_INSERT_HEAD(&allproc, p, p_list);
390 	p->p_pgrp = &pgrp0;
391 	LIST_INSERT_HEAD(PGRPHASH(0), &pgrp0, pg_hash);
392 	LIST_INIT(&pgrp0.pg_members);
393 	LIST_INSERT_HEAD(&pgrp0.pg_members, p, p_pglist);
394 
395 	pgrp0.pg_session = &session0;
396 	session0.s_count = 1;
397 	session0.s_leader = p;
398 
399 	p->p_sysent = &aout_sysvec;
400 
401 	p->p_flag = P_INMEM | P_SYSTEM;
402 	p->p_stat = SRUN;
403 	p->p_nice = NZERO;
404 	p->p_rtprio.type = RTP_PRIO_NORMAL;
405 	p->p_rtprio.prio = 0;
406 
407 /*
408  * Link for kernel based threads
409  */
410 	p->p_peers = 0;
411 	p->p_leader = p;
412 
413 	bcopy("swapper", p->p_comm, sizeof ("swapper"));
414 
415 	/* Create credentials. */
416 	cred0.p_refcnt = 1;
417 	p->p_cred = &cred0;
418 	p->p_ucred = crget();
419 	p->p_ucred->cr_ngroups = 1;	/* group 0 */
420 
421 #ifdef COMPAT_LINUX_THREADS
422 	/* Create procsig. */
423 	p->p_procsig = &procsig0;
424 	p->p_procsig->ps_refcnt = 2;
425 
426 #endif /* COMPAT_LINUX_THREADS */
427 	/* Create the file descriptor table. */
428 	fdp = &filedesc0;
429 	p->p_fd = &fdp->fd_fd;
430 	fdp->fd_fd.fd_refcnt = 1;
431 	fdp->fd_fd.fd_cmask = cmask;
432 	fdp->fd_fd.fd_ofiles = fdp->fd_dfiles;
433 	fdp->fd_fd.fd_ofileflags = fdp->fd_dfileflags;
434 	fdp->fd_fd.fd_nfiles = NDFILE;
435 
436 	/* Create the limits structures. */
437 	p->p_limit = &limit0;
438 	for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++)
439 		limit0.pl_rlimit[i].rlim_cur =
440 		    limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY;
441 	limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur =
442 	    limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles;
443 	limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur =
444 	    limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
445 	i = ptoa(cnt.v_free_count);
446 	limit0.pl_rlimit[RLIMIT_RSS].rlim_max = i;
447 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = i;
448 	limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = i / 3;
449 	limit0.p_cpulimit = RLIM_INFINITY;
450 	limit0.p_refcnt = 1;
451 
452 
453 	/* Allocate a prototype map so we have something to fork. */
454 	pmap_pinit0(&vmspace0.vm_pmap);
455 	p->p_vmspace = &vmspace0;
456 	vmspace0.vm_refcnt = 1;
457 	vm_map_init(&vmspace0.vm_map, round_page(VM_MIN_ADDRESS),
458 	    trunc_page(VM_MAXUSER_ADDRESS));
459 	vmspace0.vm_map.pmap = &vmspace0.vm_pmap;
460 	p->p_addr = proc0paddr;				/* XXX */
461 
462 #ifndef __alpha__		/* XXX what is this? */
463 #define INCOMPAT_LITES2
464 #ifdef INCOMPAT_LITES2
465 	/*
466 	 * proc0 needs to have a coherent frame base in its stack.
467 	 */
468 	cpu_set_init_frame(p, init_framep);			/* XXX! */
469 #endif	/* INCOMPAT_LITES2*/
470 #endif
471 
472 	/*
473 	 * We continue to place resource usage info and signal
474 	 * actions in the user struct so they're pageable.
475 	 */
476 	p->p_stats = &p->p_addr->u_stats;
477 	p->p_sigacts = &p->p_addr->u_sigacts;
478 
479 	/*
480 	 * Charge root for one process.
481 	 */
482 	(void)chgproccnt(0, 1);
483 
484 	/*
485 	 * Initialize the procfs flags (to 0, of course)
486 	 */
487 	p->p_stops = p->p_stype = p->p_step = 0;
488 
489 }
490 SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL)
491 
492 /* ARGSUSED*/
493 static void proc0_post __P((void *dummy));
494 static void
495 proc0_post(dummy)
496 	void *dummy;
497 {
498 	struct timespec ts;
499 
500 	/*
501 	 * Now can look at time, having had a chance to verify the time
502 	 * from the file system.  Reset p->p_runtime as it may have been
503 	 * munched in mi_switch() after the time got set.  Set
504 	 * p->p_switchtime to be consistent with this unmunching.
505 	 */
506 	microtime(&proc0.p_stats->p_start);
507 	proc0.p_runtime = 0;
508 	microuptime(&proc0.p_switchtime);
509 
510 	/*
511 	 * Give the ``random'' number generator a thump.
512 	 * XXX: Does read_random() contain enough bits to be used here ?
513 	 */
514 	nanotime(&ts);
515 	srandom(ts.tv_sec ^ ts.tv_nsec);
516 
517 	/* Initialize signal state for process 0. */
518 	siginit(&proc0);
519 }
520 SYSINIT(p0post, SI_SUB_INTRINSIC_POST, SI_ORDER_FIRST, proc0_post, NULL)
521 
522 
523 
524 
525 /*
526  ***************************************************************************
527  ****
528  **** The following SYSINIT's and glue code should be moved to the
529  **** respective files on a per subsystem basis.
530  ****
531  ***************************************************************************
532  */
533 
534 /* ARGSUSED */
535 static void root_conf __P((void *dummy));
536 static void
537 root_conf(dummy)
538 	void *dummy;
539 {
540 	cpu_rootconf();
541 }
542 SYSINIT(root_conf, SI_SUB_ROOT_CONF, SI_ORDER_FIRST, root_conf, NULL)
543 
544 /* ARGSUSED*/
545 static void xxx_vfs_root_fdtab __P((void *dummy));
546 static void
547 xxx_vfs_root_fdtab(dummy)
548 	void *dummy;
549 {
550 	register struct filedesc0	*fdp = &filedesc0;
551 
552 	/* Get the vnode for '/'.  Set fdp->fd_fd.fd_cdir to reference it. */
553 	if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
554 		panic("cannot find root vnode");
555 	fdp->fd_fd.fd_cdir = rootvnode;
556 	VREF(fdp->fd_fd.fd_cdir);
557 	VOP_UNLOCK(rootvnode, 0, &proc0);
558 	fdp->fd_fd.fd_rdir = rootvnode;
559 }
560 SYSINIT(retrofit, SI_SUB_ROOT_FDTAB, SI_ORDER_FIRST, xxx_vfs_root_fdtab, NULL)
561 
562 
563 /*
564  ***************************************************************************
565  ****
566  **** The following code probably belongs in another file, like
567  **** kern/init_init.c.  It is here for two reasons only:
568  ****
569  ****	1)	This code returns to startup the system; this is
570  ****		abnormal for a kernel thread.
571  ****	2)	This code promiscuously uses init_frame
572  ****
573  ***************************************************************************
574  */
575 
576 static void kthread_init __P((void *dummy));
577 SYSINIT_KP(init,SI_SUB_KTHREAD_INIT, SI_ORDER_FIRST, kthread_init, NULL)
578 
579 
580 extern void prepare_usermode __P((void));
581 static void start_init __P((struct proc *p));
582 
583 /* ARGSUSED*/
584 static void
585 kthread_init(dummy)
586 	void *dummy;
587 {
588 	/* Create process 1 (init(8)). */
589 	start_init(curproc);
590 
591 	prepare_usermode();
592 
593 	/*
594 	 * This returns to the fork trampoline, then to user mode.
595 	 */
596 	return;
597 }
598 
599 
600 /*
601  * List of paths to try when searching for "init".
602  */
603 static char *initpaths[] = {
604 	"/sbin/init",
605 	"/sbin/oinit",
606 	"/sbin/init.bak",
607 	"/stand/sysinstall",
608 	NULL,
609 };
610 
611 /*
612  * Start the initial user process; try exec'ing each pathname in "initpaths".
613  * The program is invoked with one argument containing the boot flags.
614  */
615 static void
616 start_init(p)
617 	struct proc *p;
618 {
619 	vm_offset_t addr;
620 	struct execve_args args;
621 	int options, i, error;
622 	char **pathp, *path, *ucp, **uap, *arg0, *arg1;
623 
624 	initproc = p;
625 
626 	/*
627 	 * Need just enough stack to hold the faked-up "execve()" arguments.
628 	 */
629 	addr = trunc_page(USRSTACK - PAGE_SIZE);
630 	if (vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr, PAGE_SIZE, FALSE, VM_PROT_ALL, VM_PROT_ALL, 0) != 0)
631 		panic("init: couldn't allocate argument space");
632 	p->p_vmspace->vm_maxsaddr = (caddr_t)addr;
633 	p->p_vmspace->vm_ssize = 1;
634 
635 	for (pathp = &initpaths[0]; (path = *pathp) != NULL; pathp++) {
636 		/*
637 		 * Move out the boot flag argument.
638 		 */
639 		options = 0;
640 		ucp = (char *)USRSTACK;
641 		(void)subyte(--ucp, 0);		/* trailing zero */
642 		if (boothowto & RB_SINGLE) {
643 			(void)subyte(--ucp, 's');
644 			options = 1;
645 		}
646 #ifdef notyet
647                 if (boothowto & RB_FASTBOOT) {
648 			(void)subyte(--ucp, 'f');
649 			options = 1;
650 		}
651 #endif
652 
653 #ifdef BOOTCDROM
654 		(void)subyte(--ucp, 'C');
655 		options = 1;
656 #endif
657 		if (options == 0)
658 			(void)subyte(--ucp, '-');
659 		(void)subyte(--ucp, '-');		/* leading hyphen */
660 		arg1 = ucp;
661 
662 		/*
663 		 * Move out the file name (also arg 0).
664 		 */
665 		for (i = strlen(path) + 1; i >= 0; i--)
666 			(void)subyte(--ucp, path[i]);
667 		arg0 = ucp;
668 
669 		/*
670 		 * Move out the arg pointers.
671 		 */
672 		uap = (char **)((intptr_t)ucp & ~(sizeof(intptr_t)-1));
673 		(void)suword((caddr_t)--uap, (long)0);	/* terminator */
674 		(void)suword((caddr_t)--uap, (long)(intptr_t)arg1);
675 		(void)suword((caddr_t)--uap, (long)(intptr_t)arg0);
676 
677 		/*
678 		 * Point at the arguments.
679 		 */
680 		args.fname = arg0;
681 		args.argv = uap;
682 		args.envv = NULL;
683 
684 		/*
685 		 * Now try to exec the program.  If can't for any reason
686 		 * other than it doesn't exist, complain.
687 		 *
688 		 * Otherwise return to main() which returns to btext
689 		 * which completes the system startup.
690 		 */
691 		if ((error = execve(p, &args)) == 0)
692 			return;
693 		if (error != ENOENT)
694 			printf("exec %s: error %d\n", path, error);
695 	}
696 	printf("init: not found\n");
697 	panic("no init");
698 }
699