xref: /titanic_51/usr/src/uts/i86pc/os/mlsetup.c (revision 0ac7d7d81ec0313c4dbc45930710481fe618f5f9)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/disp.h>
317c478bd9Sstevel@tonic-gate #include <sys/promif.h>
327c478bd9Sstevel@tonic-gate #include <sys/clock.h>
337c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
347c478bd9Sstevel@tonic-gate #include <sys/stack.h>
357c478bd9Sstevel@tonic-gate #include <vm/as.h>
367c478bd9Sstevel@tonic-gate #include <vm/hat.h>
377c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
387c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
397c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
407c478bd9Sstevel@tonic-gate #include <sys/proc.h>
417c478bd9Sstevel@tonic-gate #include <sys/thread.h>
427c478bd9Sstevel@tonic-gate #include <sys/cpupart.h>
437c478bd9Sstevel@tonic-gate #include <sys/pset.h>
447c478bd9Sstevel@tonic-gate #include <sys/copyops.h>
457c478bd9Sstevel@tonic-gate #include <sys/chip.h>
467c478bd9Sstevel@tonic-gate #include <sys/disp.h>
477c478bd9Sstevel@tonic-gate #include <sys/debug.h>
487c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
497c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
507c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
517c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
527c478bd9Sstevel@tonic-gate #include <sys/ontrap.h>
537c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
547c478bd9Sstevel@tonic-gate #include <sys/kdi.h>
557c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
567c478bd9Sstevel@tonic-gate #include <sys/promif.h>
577c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
587c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
597c478bd9Sstevel@tonic-gate #include <sys/kobj_lex.h>
60c88420b3Sdmick #include <sys/pci_cfgspace.h>
617c478bd9Sstevel@tonic-gate #if defined(__amd64)
627c478bd9Sstevel@tonic-gate #include <sys/bootsvcs.h>
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * XX64	This stuff deals with switching stacks in case a trapping
667c478bd9Sstevel@tonic-gate  *	thread wants to call back into boot -after- boot has lost track
677c478bd9Sstevel@tonic-gate  *	of the mappings but before the kernel owns the console.
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  *	(A better way to hide this would be to add a 'this' pointer to
707c478bd9Sstevel@tonic-gate  *	every boot syscall so that vmx could get at the resulting save
717c478bd9Sstevel@tonic-gate  *	area.)
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate struct boot_syscalls *_vmx_sysp;
757c478bd9Sstevel@tonic-gate static struct boot_syscalls __kbootsvcs;
767c478bd9Sstevel@tonic-gate extern struct boot_syscalls *sysp;
777c478bd9Sstevel@tonic-gate extern void _stack_safe_putchar(int c);
787c478bd9Sstevel@tonic-gate #endif
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate  * some globals for patching the result of cpuid
827c478bd9Sstevel@tonic-gate  * to solve problems w/ creative cpu vendors
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include;
867c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude;
877c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include;
887c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * External Routines:
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate extern void init_tables(void);
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate static uint32_t
987c478bd9Sstevel@tonic-gate cpuid_getval(char *name)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	char prop[32];
1017c478bd9Sstevel@tonic-gate 	u_longlong_t ll;
1027c478bd9Sstevel@tonic-gate 	extern struct bootops *bootops;
1037c478bd9Sstevel@tonic-gate 	if ((BOP_GETPROPLEN(bootops, name) > sizeof (prop)) ||
1047c478bd9Sstevel@tonic-gate 	    (BOP_GETPROP(bootops, name, prop) < 0) ||
1057c478bd9Sstevel@tonic-gate 	    (kobj_getvalue(prop, &ll) == -1))
1067c478bd9Sstevel@tonic-gate 		return (0);
1077c478bd9Sstevel@tonic-gate 	return ((uint32_t)ll);
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Setup routine called right before main(). Interposing this function
1127c478bd9Sstevel@tonic-gate  * before main() allows us to call it in a machine-independent fashion.
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate void
1157c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate 	extern struct classfuncs sys_classfuncs;
1187c478bd9Sstevel@tonic-gate 	extern struct chip cpu0_chip;
1197c478bd9Sstevel@tonic-gate 	extern disp_t cpu0_disp;
1207c478bd9Sstevel@tonic-gate 	extern char t0stack[];
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate #if defined(__amd64)
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #if (BS_VERSION > 4)
1277c478bd9Sstevel@tonic-gate 	/*
1287c478bd9Sstevel@tonic-gate 	 * When new boot_syscalls are added to the vector, this routine
1297c478bd9Sstevel@tonic-gate 	 * must be modified to copy them into the kernel's copy of the
1307c478bd9Sstevel@tonic-gate 	 * vector.
1317c478bd9Sstevel@tonic-gate 	 */
1327c478bd9Sstevel@tonic-gate #error mlsetup() must be updated for amd64 to support new boot_syscalls
1337c478bd9Sstevel@tonic-gate #endif	/* (BS_VERSION > 4) */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	/*
1367c478bd9Sstevel@tonic-gate 	 * XX64	This remaps vmx's putchar to use the kernel's version
1377c478bd9Sstevel@tonic-gate 	 *	that switches stacks before diving into vmx
1387c478bd9Sstevel@tonic-gate 	 *	See explanation/complaints in commentary above.
1397c478bd9Sstevel@tonic-gate 	 */
1407c478bd9Sstevel@tonic-gate 	_vmx_sysp = sysp;
1417c478bd9Sstevel@tonic-gate 	sysp = &__kbootsvcs;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	sysp->bsvc_getchar = _vmx_sysp->bsvc_getchar;
1447c478bd9Sstevel@tonic-gate 	sysp->bsvc_putchar = _stack_safe_putchar;
1457c478bd9Sstevel@tonic-gate 	sysp->bsvc_ischar = _vmx_sysp->bsvc_ischar;
1467c478bd9Sstevel@tonic-gate #endif
1477c478bd9Sstevel@tonic-gate 	/*
1487c478bd9Sstevel@tonic-gate 	 * initialize cpu_self
1497c478bd9Sstevel@tonic-gate 	 */
1507c478bd9Sstevel@tonic-gate 	cpu[0]->cpu_self = cpu[0];
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	/*
1537c478bd9Sstevel@tonic-gate 	 * check if we've got special bits to clear or set
1547c478bd9Sstevel@tonic-gate 	 * when checking cpu features
1557c478bd9Sstevel@tonic-gate 	 */
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	cpuid_feature_ecx_include =
1587c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_ecx_include");
1597c478bd9Sstevel@tonic-gate 	cpuid_feature_ecx_exclude =
1607c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_ecx_exclude");
1617c478bd9Sstevel@tonic-gate 	cpuid_feature_edx_include =
1627c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_edx_include");
1637c478bd9Sstevel@tonic-gate 	cpuid_feature_edx_exclude =
1647c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_edx_exclude");
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/*
1677c478bd9Sstevel@tonic-gate 	 * The first lightweight pass (pass0) through the cpuid data
1687c478bd9Sstevel@tonic-gate 	 * was done in locore before mlsetup was called.  Do the next
1697c478bd9Sstevel@tonic-gate 	 * pass in C code.
1707c478bd9Sstevel@tonic-gate 	 *
1717c478bd9Sstevel@tonic-gate 	 * The x86_feature bits are set here on the basis of the capabilities
1727c478bd9Sstevel@tonic-gate 	 * of the boot CPU.  Note that if we choose to support CPUs that have
1737c478bd9Sstevel@tonic-gate 	 * different feature sets (at which point we would almost certainly
1747c478bd9Sstevel@tonic-gate 	 * want to set the feature bits to correspond to the feature
1757c478bd9Sstevel@tonic-gate 	 * minimum) this value may be altered.
1767c478bd9Sstevel@tonic-gate 	 */
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 	x86_feature = cpuid_pass1(cpu[0]);
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	/*
1817c478bd9Sstevel@tonic-gate 	 * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss.
1827c478bd9Sstevel@tonic-gate 	 */
1837c478bd9Sstevel@tonic-gate 	init_tables();
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate #if defined(__amd64)
1867c478bd9Sstevel@tonic-gate 	/*CSTYLED*/
1877c478bd9Sstevel@tonic-gate 	{
1887c478bd9Sstevel@tonic-gate 		/*
1897c478bd9Sstevel@tonic-gate 		 * setup %gs for the kernel
1907c478bd9Sstevel@tonic-gate 		 */
191*0ac7d7d8Skucharsk 		wrmsr(MSR_AMD_GSBASE, (uint64_t)&cpus[0]);
1927c478bd9Sstevel@tonic-gate 		/*
1937c478bd9Sstevel@tonic-gate 		 * XX64 We should never dereference off "other gsbase" or
1947c478bd9Sstevel@tonic-gate 		 * "fsbase".  So, we should arrange to point FSBASE and
1957c478bd9Sstevel@tonic-gate 		 * KGSBASE somewhere truly awful e.g. point it at the last
1967c478bd9Sstevel@tonic-gate 		 * valid address below the hole so that any attempts to index
1977c478bd9Sstevel@tonic-gate 		 * off them cause an exception.
1987c478bd9Sstevel@tonic-gate 		 *
1997c478bd9Sstevel@tonic-gate 		 * For now, point it at 8G -- at least it should be unmapped
2007c478bd9Sstevel@tonic-gate 		 * until some 64-bit processes run.
2017c478bd9Sstevel@tonic-gate 		 */
202*0ac7d7d8Skucharsk 		wrmsr(MSR_AMD_FSBASE, 0x200000000UL);
203*0ac7d7d8Skucharsk 		wrmsr(MSR_AMD_KGSBASE, 0x200000000UL);
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate #elif defined(__i386)
2077c478bd9Sstevel@tonic-gate 	/*
2087c478bd9Sstevel@tonic-gate 	 * enable large page support right here.
2097c478bd9Sstevel@tonic-gate 	 */
2107c478bd9Sstevel@tonic-gate 	if (x86_feature & X86_LARGEPAGE) {
2117c478bd9Sstevel@tonic-gate 		cr4_value |= CR4_PSE;
2127c478bd9Sstevel@tonic-gate 		if (x86_feature & X86_PGE)
2137c478bd9Sstevel@tonic-gate 			cr4_value |= CR4_PGE;
2147c478bd9Sstevel@tonic-gate 		setup_121_andcall(enable_big_page_support, cr4_value);
2157c478bd9Sstevel@tonic-gate 	}
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 	/*
2187c478bd9Sstevel@tonic-gate 	 * Some i386 processors do not implement the rdtsc instruction,
2197c478bd9Sstevel@tonic-gate 	 * or at least they do not implement it correctly.
2207c478bd9Sstevel@tonic-gate 	 *
2217c478bd9Sstevel@tonic-gate 	 * For those that do, patch in the rdtsc instructions in
2227c478bd9Sstevel@tonic-gate 	 * various parts of the kernel right now while the text is
2237c478bd9Sstevel@tonic-gate 	 * still writable.
2247c478bd9Sstevel@tonic-gate 	 */
2257c478bd9Sstevel@tonic-gate 	if (x86_feature & X86_TSC)
2267c478bd9Sstevel@tonic-gate 		patch_tsc();
2277c478bd9Sstevel@tonic-gate #endif
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	/*
2307c478bd9Sstevel@tonic-gate 	 * initialize t0
2317c478bd9Sstevel@tonic-gate 	 */
2327c478bd9Sstevel@tonic-gate 	t0.t_stk = (caddr_t)rp - MINFRAME;
2337c478bd9Sstevel@tonic-gate 	t0.t_stkbase = t0stack;
2347c478bd9Sstevel@tonic-gate 	t0.t_pri = maxclsyspri - 3;
2357c478bd9Sstevel@tonic-gate 	t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
2367c478bd9Sstevel@tonic-gate 	t0.t_procp = &p0;
2377c478bd9Sstevel@tonic-gate 	t0.t_plockp = &p0lock.pl_lock;
2387c478bd9Sstevel@tonic-gate 	t0.t_lwp = &lwp0;
2397c478bd9Sstevel@tonic-gate 	t0.t_forw = &t0;
2407c478bd9Sstevel@tonic-gate 	t0.t_back = &t0;
2417c478bd9Sstevel@tonic-gate 	t0.t_next = &t0;
2427c478bd9Sstevel@tonic-gate 	t0.t_prev = &t0;
2437c478bd9Sstevel@tonic-gate 	t0.t_cpu = cpu[0];
2447c478bd9Sstevel@tonic-gate 	t0.t_disp_queue = &cpu0_disp;
2457c478bd9Sstevel@tonic-gate 	t0.t_bind_cpu = PBIND_NONE;
2467c478bd9Sstevel@tonic-gate 	t0.t_bind_pset = PS_NONE;
2477c478bd9Sstevel@tonic-gate 	t0.t_cpupart = &cp_default;
2487c478bd9Sstevel@tonic-gate 	t0.t_clfuncs = &sys_classfuncs.thread;
2497c478bd9Sstevel@tonic-gate 	t0.t_copyops = NULL;
2507c478bd9Sstevel@tonic-gate 	THREAD_ONPROC(&t0, CPU);
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	lwp0.lwp_thread = &t0;
2537c478bd9Sstevel@tonic-gate 	lwp0.lwp_regs = (void *) rp;
2547c478bd9Sstevel@tonic-gate 	lwp0.lwp_procp = &p0;
2557c478bd9Sstevel@tonic-gate 	t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	p0.p_exec = NULL;
2587c478bd9Sstevel@tonic-gate 	p0.p_stat = SRUN;
2597c478bd9Sstevel@tonic-gate 	p0.p_flag = SSYS;
2607c478bd9Sstevel@tonic-gate 	p0.p_tlist = &t0;
2617c478bd9Sstevel@tonic-gate 	p0.p_stksize = 2*PAGESIZE;
2627c478bd9Sstevel@tonic-gate 	p0.p_stkpageszc = 0;
2637c478bd9Sstevel@tonic-gate 	p0.p_as = &kas;
2647c478bd9Sstevel@tonic-gate 	p0.p_lockp = &p0lock;
2657c478bd9Sstevel@tonic-gate 	p0.p_brkpageszc = 0;
2667c478bd9Sstevel@tonic-gate 	sigorset(&p0.p_ignore, &ignoredefault);
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	CPU->cpu_thread = &t0;
2697c478bd9Sstevel@tonic-gate 	bzero(&cpu0_disp, sizeof (disp_t));
2707c478bd9Sstevel@tonic-gate 	CPU->cpu_disp = &cpu0_disp;
2717c478bd9Sstevel@tonic-gate 	CPU->cpu_disp->disp_cpu = CPU;
2727c478bd9Sstevel@tonic-gate 	CPU->cpu_dispthread = &t0;
2737c478bd9Sstevel@tonic-gate 	CPU->cpu_idle_thread = &t0;
2747c478bd9Sstevel@tonic-gate 	CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE;
2757c478bd9Sstevel@tonic-gate 	CPU->cpu_dispatch_pri = t0.t_pri;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	CPU->cpu_mask = 1;
2787c478bd9Sstevel@tonic-gate 	CPU->cpu_id = 0;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	CPU->cpu_tss = &ktss0;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	CPU->cpu_pri = 12;		/* initial PIL for the boot CPU */
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	CPU->cpu_ldt = ldt0_default;	/* default LDT */
2857c478bd9Sstevel@tonic-gate 	CPU->cpu_gdt = gdt0;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	/*
2887c478bd9Sstevel@tonic-gate 	 * This must be done _after_ init_tables(), called above, has set up
2897c478bd9Sstevel@tonic-gate 	 * ldt0_default_desc.
2907c478bd9Sstevel@tonic-gate 	 */
2917c478bd9Sstevel@tonic-gate #if defined(__amd64)
2927c478bd9Sstevel@tonic-gate 	/*
2937c478bd9Sstevel@tonic-gate 	 * ldt0_default64 contains all invalid entries. We use that as p0's LDT
2947c478bd9Sstevel@tonic-gate 	 * because p0 should never have any reason to use the LDT. This will
2957c478bd9Sstevel@tonic-gate 	 * catch things early if such a scenario should ever occur.
2967c478bd9Sstevel@tonic-gate 	 */
2977c478bd9Sstevel@tonic-gate 	p0.p_ldt_desc = ldt0_default64_desc;
2987c478bd9Sstevel@tonic-gate #else
2997c478bd9Sstevel@tonic-gate 	p0.p_ldt_desc = ldt0_default_desc;
3007c478bd9Sstevel@tonic-gate #endif /* __amd64 */
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	/*
3037c478bd9Sstevel@tonic-gate 	 * Kernel IDT.
3047c478bd9Sstevel@tonic-gate 	 */
3057c478bd9Sstevel@tonic-gate 	CPU->cpu_idt = idt0;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	/*
3087c478bd9Sstevel@tonic-gate 	 * Initialize thread/cpu microstate accounting here
3097c478bd9Sstevel@tonic-gate 	 */
3107c478bd9Sstevel@tonic-gate 	init_mstate(&t0, LMS_SYSTEM);
3117c478bd9Sstevel@tonic-gate 	init_cpu_mstate(CPU, CMS_SYSTEM);
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	/*
3147c478bd9Sstevel@tonic-gate 	 * Initialize lists of available and active CPUs.
3157c478bd9Sstevel@tonic-gate 	 */
3167c478bd9Sstevel@tonic-gate 	cpu_list_init(CPU);
3177c478bd9Sstevel@tonic-gate 
318affbd3ccSkchow 	cpu_vm_data_init(CPU);
319affbd3ccSkchow 
320c88420b3Sdmick 	/* lgrp_init() needs PCI config space access */
321c88420b3Sdmick 	pci_cfgspace_init();
322c88420b3Sdmick 
3237c478bd9Sstevel@tonic-gate 	/*
3247c478bd9Sstevel@tonic-gate 	 * Initialize the lgrp framework
3257c478bd9Sstevel@tonic-gate 	 */
3267c478bd9Sstevel@tonic-gate 	lgrp_init();
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	/*
3297c478bd9Sstevel@tonic-gate 	 * The lgroup code needs to at least know about a CPU's
3307c478bd9Sstevel@tonic-gate 	 * chip association, but it's too early to fully initialize
3317c478bd9Sstevel@tonic-gate 	 * cpu0_chip, since the device node for the boot CPU doesn't
3327c478bd9Sstevel@tonic-gate 	 * exist yet. Initialize enough of it to get by until formal
3337c478bd9Sstevel@tonic-gate 	 * initialization.
3347c478bd9Sstevel@tonic-gate 	 */
3357c478bd9Sstevel@tonic-gate 	CPU->cpu_rechoose = rechoose_interval;
3367c478bd9Sstevel@tonic-gate 	CPU->cpu_chip = &cpu0_chip;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	rp->r_fp = 0;	/* terminate kernel stack traces! */
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	prom_init("kernel", (void *)NULL);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	if (boothowto & RB_HALT) {
3437c478bd9Sstevel@tonic-gate 		prom_printf("unix: kernel halted by -h flag\n");
3447c478bd9Sstevel@tonic-gate 		prom_enter_mon();
3457c478bd9Sstevel@tonic-gate 	}
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	if (workaround_errata(CPU) != 0)
3507c478bd9Sstevel@tonic-gate 		panic("critical workaround(s) missing for boot cpu");
3517c478bd9Sstevel@tonic-gate }
352