xref: /titanic_51/usr/src/uts/common/os/main.c (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* from SVr4.0 1.31 */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/param.h>
347c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
357c478bd9Sstevel@tonic-gate #include <sys/pcb.h>
367c478bd9Sstevel@tonic-gate #include <sys/systm.h>
377c478bd9Sstevel@tonic-gate #include <sys/signal.h>
387c478bd9Sstevel@tonic-gate #include <sys/cred.h>
397c478bd9Sstevel@tonic-gate #include <sys/user.h>
407c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
417c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
427c478bd9Sstevel@tonic-gate #include <sys/proc.h>
437c478bd9Sstevel@tonic-gate #include <sys/time.h>
447c478bd9Sstevel@tonic-gate #include <sys/file.h>
457c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
467c478bd9Sstevel@tonic-gate #include <sys/procset.h>
477c478bd9Sstevel@tonic-gate #include <sys/disp.h>
487c478bd9Sstevel@tonic-gate #include <sys/callo.h>
497c478bd9Sstevel@tonic-gate #include <sys/callb.h>
507c478bd9Sstevel@tonic-gate #include <sys/debug.h>
517c478bd9Sstevel@tonic-gate #include <sys/conf.h>
527c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
537c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
547c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
557c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>
567c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
577c478bd9Sstevel@tonic-gate #include <sys/vm.h>
587c478bd9Sstevel@tonic-gate #include <sys/callb.h>
597c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
607c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
617c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
627c478bd9Sstevel@tonic-gate #include <sys/cladm.h>
637c478bd9Sstevel@tonic-gate #include <sys/corectl.h>
647c478bd9Sstevel@tonic-gate #include <sys/exec.h>
657c478bd9Sstevel@tonic-gate #include <sys/syscall.h>
667c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
677c478bd9Sstevel@tonic-gate #include <sys/task.h>
687c478bd9Sstevel@tonic-gate #include <sys/exacct.h>
697c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
707c478bd9Sstevel@tonic-gate #include <sys/errorq.h>
717c478bd9Sstevel@tonic-gate #include <sys/class.h>
727c478bd9Sstevel@tonic-gate #include <sys/stack.h>
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #include <vm/as.h>
757c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
767c478bd9Sstevel@tonic-gate #include <sys/dc_ki.h>
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #include <c2/audit.h>
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /* well known processes */
817c478bd9Sstevel@tonic-gate proc_t *proc_sched;		/* memory scheduler */
827c478bd9Sstevel@tonic-gate proc_t *proc_init;		/* init */
837c478bd9Sstevel@tonic-gate proc_t *proc_pageout;		/* pageout daemon */
847c478bd9Sstevel@tonic-gate proc_t *proc_fsflush;		/* fsflush daemon */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate pgcnt_t	maxmem;		/* Maximum available memory in pages.	*/
877c478bd9Sstevel@tonic-gate pgcnt_t	freemem;	/* Current available memory in pages.	*/
887c478bd9Sstevel@tonic-gate int	audit_active;
897c478bd9Sstevel@tonic-gate int	interrupts_unleashed;	/* set when we do the first spl0() */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate kmem_cache_t *process_cache;	/* kmem cache for proc structures */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Process 0's lwp directory and lwpid hash table.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate lwpdir_t p0_lwpdir[2];
977c478bd9Sstevel@tonic-gate lwpdir_t *p0_tidhash[2];
987c478bd9Sstevel@tonic-gate lwpent_t p0_lep;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  * Machine-independent initialization code
1027c478bd9Sstevel@tonic-gate  * Called from cold start routine as
1037c478bd9Sstevel@tonic-gate  * soon as a stack and segmentation
1047c478bd9Sstevel@tonic-gate  * have been established.
1057c478bd9Sstevel@tonic-gate  * Functions:
1067c478bd9Sstevel@tonic-gate  *	clear and free user core
1077c478bd9Sstevel@tonic-gate  *	turn on clock
1087c478bd9Sstevel@tonic-gate  *	hand craft 0th process
1097c478bd9Sstevel@tonic-gate  *	call all initialization routines
1107c478bd9Sstevel@tonic-gate  *	fork	- process 0 to schedule
1117c478bd9Sstevel@tonic-gate  *		- process 1 execute bootstrap
1127c478bd9Sstevel@tonic-gate  *		- process 2 to page out
1137c478bd9Sstevel@tonic-gate  *	create system threads
1147c478bd9Sstevel@tonic-gate  */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate int cluster_bootflags = 0;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate void
1197c478bd9Sstevel@tonic-gate cluster_wrapper(void)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	cluster();
1227c478bd9Sstevel@tonic-gate 	panic("cluster()  returned");
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate char initname[INITNAME_SZ] = "/sbin/init";
1267c478bd9Sstevel@tonic-gate char initargs[INITARGS_SZ] = "";
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * Start the initial user process.
1307c478bd9Sstevel@tonic-gate  * The program [initname] may be invoked with one argument
1317c478bd9Sstevel@tonic-gate  * containing the boot flags.
1327c478bd9Sstevel@tonic-gate  *
1337c478bd9Sstevel@tonic-gate  * It must be a 32-bit program.
1347c478bd9Sstevel@tonic-gate  */
1357c478bd9Sstevel@tonic-gate void
1367c478bd9Sstevel@tonic-gate icode(void)
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate 	proc_t *p = ttoproc(curthread);
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	/*
1437c478bd9Sstevel@tonic-gate 	 * Allocate user address space and stack segment
1447c478bd9Sstevel@tonic-gate 	 */
1457c478bd9Sstevel@tonic-gate 	proc_init = p;
1467c478bd9Sstevel@tonic-gate 	zone0.zone_proc_initpid = proc_init->p_pid;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	p->p_cstime = p->p_stime = p->p_cutime = p->p_utime = 0;
1497c478bd9Sstevel@tonic-gate 	p->p_usrstack = (caddr_t)USRSTACK32;
1507c478bd9Sstevel@tonic-gate 	p->p_model = DATAMODEL_ILP32;
1517c478bd9Sstevel@tonic-gate 	p->p_stkprot = PROT_ZFOD & ~PROT_EXEC;
1527c478bd9Sstevel@tonic-gate 	p->p_datprot = PROT_ZFOD & ~PROT_EXEC;
1537c478bd9Sstevel@tonic-gate 	p->p_stk_ctl = INT32_MAX;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate 	p->p_as = as_alloc();
1567c478bd9Sstevel@tonic-gate 	p->p_as->a_userlimit = (caddr_t)USERLIMIT32;
1577c478bd9Sstevel@tonic-gate 	(void) hat_setup(p->p_as->a_hat, HAT_INIT);
1587c478bd9Sstevel@tonic-gate 	init_core();
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	init_mstate(curthread, LMS_SYSTEM);
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (exec_init(initname, 1, initargs[0] == '\0' ? NULL : initargs) != 0)
1637c478bd9Sstevel@tonic-gate 		halt("Could not start init");
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	lwp_rtt();
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate int
1697c478bd9Sstevel@tonic-gate exec_init(const char *initpath, int useboothowto, const char *args)
1707c478bd9Sstevel@tonic-gate {
1717c478bd9Sstevel@tonic-gate 	char *ucp;
1727c478bd9Sstevel@tonic-gate 	caddr32_t *uap;
1737c478bd9Sstevel@tonic-gate 	char *argv[4];				/* backwards */
1747c478bd9Sstevel@tonic-gate 	int argc = 0;
1757c478bd9Sstevel@tonic-gate 	int error = 0, len, count = 0, i;
1767c478bd9Sstevel@tonic-gate 	proc_t *p = ttoproc(curthread);
1777c478bd9Sstevel@tonic-gate 	klwp_t *lwp = ttolwp(curthread);
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	/*
1807c478bd9Sstevel@tonic-gate 	 * Construct the exec arguments in userland.  That is, make an array
1817c478bd9Sstevel@tonic-gate 	 * of pointers to the argument strings, just like for execv().  This
1827c478bd9Sstevel@tonic-gate 	 * is done backwards.
1837c478bd9Sstevel@tonic-gate 	 */
1847c478bd9Sstevel@tonic-gate 	ucp = p->p_usrstack;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	argv[0] = NULL;				/* argv terminator */
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	if (args != NULL) {
1897c478bd9Sstevel@tonic-gate 		len = strlen(args) + 1;
1907c478bd9Sstevel@tonic-gate 		ucp -= len;
1917c478bd9Sstevel@tonic-gate 		error |= copyoutstr(args, ucp, len, NULL);
1927c478bd9Sstevel@tonic-gate 		argv[++argc] = ucp;
1937c478bd9Sstevel@tonic-gate 	}
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	if (useboothowto &&
1967c478bd9Sstevel@tonic-gate 	    boothowto & (RB_SINGLE|RB_RECONFIG|RB_VERBOSE)) {
1977c478bd9Sstevel@tonic-gate 		error |= subyte(--ucp, '\0');		/* trailing null byte */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 		if (boothowto & RB_SINGLE)
2007c478bd9Sstevel@tonic-gate 			error |= subyte(--ucp, 's');
2017c478bd9Sstevel@tonic-gate 		if (boothowto & RB_RECONFIG)
2027c478bd9Sstevel@tonic-gate 			error |= subyte(--ucp, 'r');
2037c478bd9Sstevel@tonic-gate 		if (boothowto & RB_VERBOSE)
2047c478bd9Sstevel@tonic-gate 			error |= subyte(--ucp, 'v');
2057c478bd9Sstevel@tonic-gate 		error |= subyte(--ucp, '-');	/* leading hyphen */
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 		argv[++argc] = ucp;
2087c478bd9Sstevel@tonic-gate 	}
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	len = strlen(initpath) + 1;
2117c478bd9Sstevel@tonic-gate 	ucp -= len;
2127c478bd9Sstevel@tonic-gate 	error |= copyoutstr(initpath, ucp, len, NULL);
2137c478bd9Sstevel@tonic-gate 	argv[++argc] = ucp;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	/*
2167c478bd9Sstevel@tonic-gate 	 * Move out the arg pointers.
2177c478bd9Sstevel@tonic-gate 	 */
2187c478bd9Sstevel@tonic-gate 	uap = (caddr32_t *)P2ALIGN((uintptr_t)ucp, sizeof (caddr32_t));
2197c478bd9Sstevel@tonic-gate 	for (i = 0; i < argc + 1; ++i)
2207c478bd9Sstevel@tonic-gate 		error |= suword32(--uap, (uint32_t)(uintptr_t)argv[i]);
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	if (error != 0) {
2237c478bd9Sstevel@tonic-gate 		zcmn_err(p->p_zone->zone_id, CE_WARN,
2247c478bd9Sstevel@tonic-gate 		    "Could not construct stack for init.\n");
2257c478bd9Sstevel@tonic-gate 		return (EFAULT);
2267c478bd9Sstevel@tonic-gate 	}
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	/*
2297c478bd9Sstevel@tonic-gate 	 * Point at the arguments.
2307c478bd9Sstevel@tonic-gate 	 */
2317c478bd9Sstevel@tonic-gate 	lwp->lwp_ap = lwp->lwp_arg;
2327c478bd9Sstevel@tonic-gate 	lwp->lwp_arg[0] = (uintptr_t)argv[argc];
2337c478bd9Sstevel@tonic-gate 	lwp->lwp_arg[1] = (uintptr_t)uap;
2347c478bd9Sstevel@tonic-gate 	lwp->lwp_arg[2] = NULL;
2357c478bd9Sstevel@tonic-gate 	curthread->t_post_sys = 1;
2367c478bd9Sstevel@tonic-gate 	curthread->t_sysnum = SYS_execve;
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate again:
2397c478bd9Sstevel@tonic-gate 	error = exec_common((const char *)argv[argc], (const char **)uap, NULL);
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	/*
2427c478bd9Sstevel@tonic-gate 	 * Normally we would just set lwp_argsaved and t_post_sys and
2437c478bd9Sstevel@tonic-gate 	 * let post_syscall reset lwp_ap for us.  Unfortunately,
2447c478bd9Sstevel@tonic-gate 	 * exec_init isn't always called from a system call.  Instead
2457c478bd9Sstevel@tonic-gate 	 * of making a mess of trap_cleanup, we just reset the args
2467c478bd9Sstevel@tonic-gate 	 * pointer here.
2477c478bd9Sstevel@tonic-gate 	 */
2487c478bd9Sstevel@tonic-gate 	reset_syscall_args();
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	switch (error) {
2517c478bd9Sstevel@tonic-gate 	case 0:
2527c478bd9Sstevel@tonic-gate 		return (0);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	case ENOENT:
2557c478bd9Sstevel@tonic-gate 		zcmn_err(p->p_zone->zone_id, CE_WARN,
2567c478bd9Sstevel@tonic-gate 		    "exec(%s) failed (file not found).\n", initpath);
2577c478bd9Sstevel@tonic-gate 		return (ENOENT);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	case EAGAIN:
2607c478bd9Sstevel@tonic-gate 	case EINTR:
2617c478bd9Sstevel@tonic-gate 		++count;
2627c478bd9Sstevel@tonic-gate 		if (count < 5) {
2637c478bd9Sstevel@tonic-gate 			zcmn_err(p->p_zone->zone_id, CE_WARN,
2647c478bd9Sstevel@tonic-gate 			    "exec(%s) failed with errno %d.  Retrying...\n",
2657c478bd9Sstevel@tonic-gate 			    initpath, error);
2667c478bd9Sstevel@tonic-gate 			goto again;
2677c478bd9Sstevel@tonic-gate 		}
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	zcmn_err(p->p_zone->zone_id, CE_WARN,
2717c478bd9Sstevel@tonic-gate 	    "exec(%s) failed with errno %d.", initpath, error);
2727c478bd9Sstevel@tonic-gate 	return (error);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate void
2767c478bd9Sstevel@tonic-gate main(void)
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate 	proc_t		*p = ttoproc(curthread);	/* &p0 */
2797c478bd9Sstevel@tonic-gate 	int		(**initptr)();
2807c478bd9Sstevel@tonic-gate 	extern void	sched();
2817c478bd9Sstevel@tonic-gate 	extern void	fsflush();
2827c478bd9Sstevel@tonic-gate 	extern void	thread_reaper();
2837c478bd9Sstevel@tonic-gate 	extern int	(*init_tbl[])();
2847c478bd9Sstevel@tonic-gate 	extern int	(*mp_init_tbl[])();
2857c478bd9Sstevel@tonic-gate 	extern id_t	syscid, defaultcid;
2867c478bd9Sstevel@tonic-gate 	extern int	swaploaded;
2877c478bd9Sstevel@tonic-gate 	extern int	netboot;
2887c478bd9Sstevel@tonic-gate 	extern void	vm_init(void);
2897c478bd9Sstevel@tonic-gate 	extern void	cbe_init(void);
2907c478bd9Sstevel@tonic-gate 	extern void	clock_init(void);
2917c478bd9Sstevel@tonic-gate 	extern void	physio_bufs_init(void);
2927c478bd9Sstevel@tonic-gate 	extern void	pm_cfb_setup_intr(void);
2937c478bd9Sstevel@tonic-gate 	extern int	pm_adjust_timestamps(dev_info_t *, void *);
2947c478bd9Sstevel@tonic-gate 	extern void	start_other_cpus(int);
2957c478bd9Sstevel@tonic-gate 	extern void	sysevent_evc_thrinit();
2967c478bd9Sstevel@tonic-gate 	extern void	lgrp_main_init(void);
2977c478bd9Sstevel@tonic-gate 	extern void	lgrp_main_mp_init(void);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	/*
3007c478bd9Sstevel@tonic-gate 	 * In the horrible world of x86 in-lines, you can't get symbolic
3017c478bd9Sstevel@tonic-gate 	 * structure offsets a la genassym.  This assertion is here so
3027c478bd9Sstevel@tonic-gate 	 * that the next poor slob who innocently changes the offset of
3037c478bd9Sstevel@tonic-gate 	 * cpu_thread doesn't waste as much time as I just did finding
3047c478bd9Sstevel@tonic-gate 	 * out that it's hard-coded in i86/ml/i86.il.  Similarly for
3057c478bd9Sstevel@tonic-gate 	 * curcpup.  You're welcome.
3067c478bd9Sstevel@tonic-gate 	 */
3077c478bd9Sstevel@tonic-gate 	ASSERT(CPU == CPU->cpu_self);
3087c478bd9Sstevel@tonic-gate 	ASSERT(curthread == CPU->cpu_thread);
3097c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	/*
3127c478bd9Sstevel@tonic-gate 	 * Setup the first lgroup, and home t0
3137c478bd9Sstevel@tonic-gate 	 */
3147c478bd9Sstevel@tonic-gate 	lgrp_setup();
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	startup();
3177c478bd9Sstevel@tonic-gate 	segkmem_gc();
3187c478bd9Sstevel@tonic-gate 	callb_init();
3197c478bd9Sstevel@tonic-gate 	callout_init();	/* callout table MUST be init'd before clock starts */
3207c478bd9Sstevel@tonic-gate 	cbe_init();
3217c478bd9Sstevel@tonic-gate 	clock_init();
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	/*
3247c478bd9Sstevel@tonic-gate 	 * May need to probe to determine latencies from CPU 0 after
3257c478bd9Sstevel@tonic-gate 	 * gethrtime() comes alive in cbe_init() and before enabling interrupts
3267c478bd9Sstevel@tonic-gate 	 */
3277c478bd9Sstevel@tonic-gate 	lgrp_plat_probe();
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	/*
3307c478bd9Sstevel@tonic-gate 	 * Call all system initialization functions.
3317c478bd9Sstevel@tonic-gate 	 */
3327c478bd9Sstevel@tonic-gate 	for (initptr = &init_tbl[0]; *initptr; initptr++)
3337c478bd9Sstevel@tonic-gate 		(**initptr)();
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	/*
3367c478bd9Sstevel@tonic-gate 	 * initialize vm related stuff.
3377c478bd9Sstevel@tonic-gate 	 */
3387c478bd9Sstevel@tonic-gate 	vm_init();
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	/*
3417c478bd9Sstevel@tonic-gate 	 * initialize buffer pool for raw I/O requests
3427c478bd9Sstevel@tonic-gate 	 */
3437c478bd9Sstevel@tonic-gate 	physio_bufs_init();
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	ttolwp(curthread)->lwp_error = 0; /* XXX kludge for SCSI driver */
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	/*
3487c478bd9Sstevel@tonic-gate 	 * Drop the interrupt level and allow interrupts.  At this point
3497c478bd9Sstevel@tonic-gate 	 * the DDI guarantees that interrupts are enabled.
3507c478bd9Sstevel@tonic-gate 	 */
3517c478bd9Sstevel@tonic-gate 	(void) spl0();
3527c478bd9Sstevel@tonic-gate 	interrupts_unleashed = 1;
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	vfs_mountroot();	/* Mount the root file system */
3557c478bd9Sstevel@tonic-gate 	errorq_init();		/* after vfs_mountroot() so DDI root is ready */
3567c478bd9Sstevel@tonic-gate 	cpu_kstat_init(CPU);	/* after vfs_mountroot() so TOD is valid */
3577c478bd9Sstevel@tonic-gate 	ddi_walk_devs(ddi_root_node(), pm_adjust_timestamps, NULL);
3587c478bd9Sstevel@tonic-gate 				/* after vfs_mountroot() so hrestime is valid */
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	post_startup();
3617c478bd9Sstevel@tonic-gate 	swaploaded = 1;
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	/*
3647c478bd9Sstevel@tonic-gate 	 * Initial C2 audit system
3657c478bd9Sstevel@tonic-gate 	 */
3667c478bd9Sstevel@tonic-gate #ifdef C2_AUDIT
3677c478bd9Sstevel@tonic-gate 	audit_init();	/* C2 hook */
3687c478bd9Sstevel@tonic-gate #endif
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	/*
3717c478bd9Sstevel@tonic-gate 	 * Plumb the protocol modules and drivers only if we are not
3727c478bd9Sstevel@tonic-gate 	 * networked booted, in this case we already did it in rootconf().
3737c478bd9Sstevel@tonic-gate 	 */
3747c478bd9Sstevel@tonic-gate 	if (netboot == 0)
3757c478bd9Sstevel@tonic-gate 		(void) strplumb();
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	gethrestime(&u.u_start);
3787c478bd9Sstevel@tonic-gate 	curthread->t_start = u.u_start.tv_sec;
3797c478bd9Sstevel@tonic-gate 	p->p_mstart = gethrtime();
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate 	/*
3827c478bd9Sstevel@tonic-gate 	 * Perform setup functions that can only be done after root
3837c478bd9Sstevel@tonic-gate 	 * and swap have been set up.
3847c478bd9Sstevel@tonic-gate 	 */
3857c478bd9Sstevel@tonic-gate 	consconfig();
3867c478bd9Sstevel@tonic-gate #if defined(__i386) || defined(__amd64)
3877c478bd9Sstevel@tonic-gate 	release_bootstrap();
3887c478bd9Sstevel@tonic-gate #endif
3897c478bd9Sstevel@tonic-gate 	/*
3907c478bd9Sstevel@tonic-gate 	 * attach drivers with ddi-forceattach prop
3917c478bd9Sstevel@tonic-gate 	 * This must be done after consconfig() to prevent usb key/mouse
3927c478bd9Sstevel@tonic-gate 	 * from attaching before the upper console stream is plumbed.
3937c478bd9Sstevel@tonic-gate 	 * It must be done early enough to load hotplug drivers (e.g.
3947c478bd9Sstevel@tonic-gate 	 * pcmcia nexus) so that devices enumerated via hotplug is
3957c478bd9Sstevel@tonic-gate 	 * available before I/O subsystem is fully initialized.
3967c478bd9Sstevel@tonic-gate 	 */
3977c478bd9Sstevel@tonic-gate 	i_ddi_forceattach_drivers();
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate 	/*
4007c478bd9Sstevel@tonic-gate 	 * Set the scan rate and other parameters of the paging subsystem.
4017c478bd9Sstevel@tonic-gate 	 */
4027c478bd9Sstevel@tonic-gate 	setupclock(0);
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	/*
4057c478bd9Sstevel@tonic-gate 	 * Create kmem cache for proc structures
4067c478bd9Sstevel@tonic-gate 	 */
4077c478bd9Sstevel@tonic-gate 	process_cache = kmem_cache_create("process_cache", sizeof (proc_t),
4087c478bd9Sstevel@tonic-gate 	    0, NULL, NULL, NULL, NULL, NULL, 0);
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	/*
4117c478bd9Sstevel@tonic-gate 	 * Initialize process 0's lwp directory and lwpid hash table.
4127c478bd9Sstevel@tonic-gate 	 */
4137c478bd9Sstevel@tonic-gate 	p->p_lwpdir = p->p_lwpfree = p0_lwpdir;
4147c478bd9Sstevel@tonic-gate 	p->p_lwpdir->ld_next = p->p_lwpdir + 1;
4157c478bd9Sstevel@tonic-gate 	p->p_lwpdir_sz = 2;
4167c478bd9Sstevel@tonic-gate 	p->p_tidhash = p0_tidhash;
4177c478bd9Sstevel@tonic-gate 	p->p_tidhash_sz = 2;
4187c478bd9Sstevel@tonic-gate 	p0_lep.le_thread = curthread;
4197c478bd9Sstevel@tonic-gate 	p0_lep.le_lwpid = curthread->t_tid;
4207c478bd9Sstevel@tonic-gate 	p0_lep.le_start = curthread->t_start;
4217c478bd9Sstevel@tonic-gate 	lwp_hash_in(p, &p0_lep);
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	/*
4247c478bd9Sstevel@tonic-gate 	 * Initialize extended accounting.
4257c478bd9Sstevel@tonic-gate 	 */
4267c478bd9Sstevel@tonic-gate 	exacct_init();
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	/*
4297c478bd9Sstevel@tonic-gate 	 * Initialize threads of sysevent event channels
4307c478bd9Sstevel@tonic-gate 	 */
4317c478bd9Sstevel@tonic-gate 	sysevent_evc_thrinit();
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 	/*
4347c478bd9Sstevel@tonic-gate 	 * main lgroup initialization
4357c478bd9Sstevel@tonic-gate 	 * This must be done after post_startup(), but before
4367c478bd9Sstevel@tonic-gate 	 * start_other_cpus()
4377c478bd9Sstevel@tonic-gate 	 */
4387c478bd9Sstevel@tonic-gate 	lgrp_main_init();
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 	/*
4417c478bd9Sstevel@tonic-gate 	 * Perform MP initialization, if any.
4427c478bd9Sstevel@tonic-gate 	 */
4437c478bd9Sstevel@tonic-gate 	start_other_cpus(0);
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 	/*
4467c478bd9Sstevel@tonic-gate 	 * Finish lgrp initialization after all CPUS are brought online.
4477c478bd9Sstevel@tonic-gate 	 */
4487c478bd9Sstevel@tonic-gate 	lgrp_main_mp_init();
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	/*
4517c478bd9Sstevel@tonic-gate 	 * After mp_init(), number of cpus are known (this is
4527c478bd9Sstevel@tonic-gate 	 * true for the time being, when there are actually
4537c478bd9Sstevel@tonic-gate 	 * hot pluggable cpus then this scheme  would not do).
4547c478bd9Sstevel@tonic-gate 	 * Any per cpu initialization is done here.
4557c478bd9Sstevel@tonic-gate 	 */
4567c478bd9Sstevel@tonic-gate 	kmem_mp_init();
4577c478bd9Sstevel@tonic-gate 	vmem_update(NULL);
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 	for (initptr = &mp_init_tbl[0]; *initptr; initptr++)
4607c478bd9Sstevel@tonic-gate 		(**initptr)();
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 	/*
4637c478bd9Sstevel@tonic-gate 	 * This must be called after start_other_cpus
4647c478bd9Sstevel@tonic-gate 	 */
4657c478bd9Sstevel@tonic-gate 	pm_cfb_setup_intr();
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	/*
4687c478bd9Sstevel@tonic-gate 	 * Make init process; enter scheduling loop with system process.
4697c478bd9Sstevel@tonic-gate 	 */
4707c478bd9Sstevel@tonic-gate 
4717c478bd9Sstevel@tonic-gate 	/* create init process */
4727c478bd9Sstevel@tonic-gate 	if (newproc(icode, NULL, defaultcid, 59, NULL))
4737c478bd9Sstevel@tonic-gate 		panic("main: unable to fork init.");
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 	/* create pageout daemon */
4767c478bd9Sstevel@tonic-gate 	if (newproc(pageout, NULL, syscid, maxclsyspri - 1, NULL))
4777c478bd9Sstevel@tonic-gate 		panic("main: unable to fork pageout()");
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	/* create fsflush daemon */
4807c478bd9Sstevel@tonic-gate 	if (newproc(fsflush, NULL, syscid, minclsyspri, NULL))
4817c478bd9Sstevel@tonic-gate 		panic("main: unable to fork fsflush()");
4827c478bd9Sstevel@tonic-gate 
4837c478bd9Sstevel@tonic-gate 	/* create cluster process if we're a member of one */
4847c478bd9Sstevel@tonic-gate 	if (cluster_bootflags & CLUSTER_BOOTED) {
4857c478bd9Sstevel@tonic-gate 		if (newproc(cluster_wrapper, NULL, syscid, minclsyspri, NULL))
4867c478bd9Sstevel@tonic-gate 			panic("main: unable to fork cluster()");
4877c478bd9Sstevel@tonic-gate 	}
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate 	/*
4907c478bd9Sstevel@tonic-gate 	 * Create system threads (threads are associated with p0)
4917c478bd9Sstevel@tonic-gate 	 */
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	/* create thread_reaper daemon */
4947c478bd9Sstevel@tonic-gate 	(void) thread_create(NULL, 0, (void (*)())thread_reaper,
4957c478bd9Sstevel@tonic-gate 	    NULL, 0, &p0, TS_RUN, minclsyspri);
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 	/* create module uninstall daemon */
4987c478bd9Sstevel@tonic-gate 	/* BugID 1132273. If swapping over NFS need a bigger stack */
4997c478bd9Sstevel@tonic-gate 	(void) thread_create(NULL, 0, (void (*)())mod_uninstall_daemon,
5007c478bd9Sstevel@tonic-gate 	    NULL, 0, &p0, TS_RUN, minclsyspri);
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	(void) thread_create(NULL, 0, seg_pasync_thread,
5037c478bd9Sstevel@tonic-gate 	    NULL, 0, &p0, TS_RUN, minclsyspri);
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	pid_setmin();
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate 	bcopy("sched", u.u_psargs, 6);
5087c478bd9Sstevel@tonic-gate 	bcopy("sched", u.u_comm, 5);
5097c478bd9Sstevel@tonic-gate 	sched();
5107c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
5117c478bd9Sstevel@tonic-gate }
512