xref: /illumos-gate/usr/src/uts/i86pc/os/mlsetup.c (revision 41791439485c85b85be39df263af7b95e79404b7)
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*41791439Sandrei  * Common Development and Distribution License (the "License").
6*41791439Sandrei  * 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 /*
220baeff3dSrab  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/disp.h>
307c478bd9Sstevel@tonic-gate #include <sys/promif.h>
317c478bd9Sstevel@tonic-gate #include <sys/clock.h>
327c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
337c478bd9Sstevel@tonic-gate #include <sys/stack.h>
347c478bd9Sstevel@tonic-gate #include <vm/as.h>
357c478bd9Sstevel@tonic-gate #include <vm/hat.h>
367c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
377c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
387c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
397c478bd9Sstevel@tonic-gate #include <sys/proc.h>
407c478bd9Sstevel@tonic-gate #include <sys/thread.h>
417c478bd9Sstevel@tonic-gate #include <sys/cpupart.h>
427c478bd9Sstevel@tonic-gate #include <sys/pset.h>
437c478bd9Sstevel@tonic-gate #include <sys/copyops.h>
447c478bd9Sstevel@tonic-gate #include <sys/chip.h>
457c478bd9Sstevel@tonic-gate #include <sys/disp.h>
467c478bd9Sstevel@tonic-gate #include <sys/debug.h>
477c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
487c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
497c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
507c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
517c478bd9Sstevel@tonic-gate #include <sys/ontrap.h>
527c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
537c478bd9Sstevel@tonic-gate #include <sys/kdi.h>
547c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
557c478bd9Sstevel@tonic-gate #include <sys/promif.h>
567c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
577c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
587c478bd9Sstevel@tonic-gate #include <sys/kobj_lex.h>
59c88420b3Sdmick #include <sys/pci_cfgspace.h>
607c478bd9Sstevel@tonic-gate #if defined(__amd64)
617c478bd9Sstevel@tonic-gate #include <sys/bootsvcs.h>
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * XX64	This stuff deals with switching stacks in case a trapping
657c478bd9Sstevel@tonic-gate  *	thread wants to call back into boot -after- boot has lost track
667c478bd9Sstevel@tonic-gate  *	of the mappings but before the kernel owns the console.
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  *	(A better way to hide this would be to add a 'this' pointer to
697c478bd9Sstevel@tonic-gate  *	every boot syscall so that vmx could get at the resulting save
707c478bd9Sstevel@tonic-gate  *	area.)
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate struct boot_syscalls *_vmx_sysp;
747c478bd9Sstevel@tonic-gate static struct boot_syscalls __kbootsvcs;
757c478bd9Sstevel@tonic-gate extern struct boot_syscalls *sysp;
767c478bd9Sstevel@tonic-gate extern void _stack_safe_putchar(int c);
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
807c478bd9Sstevel@tonic-gate  * some globals for patching the result of cpuid
817c478bd9Sstevel@tonic-gate  * to solve problems w/ creative cpu vendors
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include;
857c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude;
867c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include;
877c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude;
887c478bd9Sstevel@tonic-gate 
894961a633Sdmick /*
904961a633Sdmick  * Dummy spl priority masks
914961a633Sdmick  */
924961a633Sdmick static unsigned char	dummy_cpu_pri[MAXIPL + 1] = {
934961a633Sdmick 	0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
944961a633Sdmick 	0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf
954961a633Sdmick };
964961a633Sdmick 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * External Routines:
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate extern void init_tables(void);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate static uint32_t
105*41791439Sandrei bootprop_getval(char *name)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate 	char prop[32];
1087c478bd9Sstevel@tonic-gate 	u_longlong_t ll;
1097c478bd9Sstevel@tonic-gate 	extern struct bootops *bootops;
1107c478bd9Sstevel@tonic-gate 	if ((BOP_GETPROPLEN(bootops, name) > sizeof (prop)) ||
1117c478bd9Sstevel@tonic-gate 	    (BOP_GETPROP(bootops, name, prop) < 0) ||
1127c478bd9Sstevel@tonic-gate 	    (kobj_getvalue(prop, &ll) == -1))
1137c478bd9Sstevel@tonic-gate 		return (0);
1147c478bd9Sstevel@tonic-gate 	return ((uint32_t)ll);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Setup routine called right before main(). Interposing this function
1197c478bd9Sstevel@tonic-gate  * before main() allows us to call it in a machine-independent fashion.
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate void
1227c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp)
1237c478bd9Sstevel@tonic-gate {
1247c478bd9Sstevel@tonic-gate 	extern struct classfuncs sys_classfuncs;
1257c478bd9Sstevel@tonic-gate 	extern struct chip cpu0_chip;
1267c478bd9Sstevel@tonic-gate 	extern disp_t cpu0_disp;
1277c478bd9Sstevel@tonic-gate 	extern char t0stack[];
128*41791439Sandrei 	int boot_ncpus;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #if defined(__amd64)
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #if (BS_VERSION > 4)
1357c478bd9Sstevel@tonic-gate 	/*
1367c478bd9Sstevel@tonic-gate 	 * When new boot_syscalls are added to the vector, this routine
1377c478bd9Sstevel@tonic-gate 	 * must be modified to copy them into the kernel's copy of the
1387c478bd9Sstevel@tonic-gate 	 * vector.
1397c478bd9Sstevel@tonic-gate 	 */
1407c478bd9Sstevel@tonic-gate #error mlsetup() must be updated for amd64 to support new boot_syscalls
1417c478bd9Sstevel@tonic-gate #endif	/* (BS_VERSION > 4) */
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	/*
1447c478bd9Sstevel@tonic-gate 	 * XX64	This remaps vmx's putchar to use the kernel's version
1457c478bd9Sstevel@tonic-gate 	 *	that switches stacks before diving into vmx
1467c478bd9Sstevel@tonic-gate 	 *	See explanation/complaints in commentary above.
1477c478bd9Sstevel@tonic-gate 	 */
1487c478bd9Sstevel@tonic-gate 	_vmx_sysp = sysp;
1497c478bd9Sstevel@tonic-gate 	sysp = &__kbootsvcs;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate 	sysp->bsvc_getchar = _vmx_sysp->bsvc_getchar;
1527c478bd9Sstevel@tonic-gate 	sysp->bsvc_putchar = _stack_safe_putchar;
1537c478bd9Sstevel@tonic-gate 	sysp->bsvc_ischar = _vmx_sysp->bsvc_ischar;
1547c478bd9Sstevel@tonic-gate #endif
1557c478bd9Sstevel@tonic-gate 	/*
1567c478bd9Sstevel@tonic-gate 	 * initialize cpu_self
1577c478bd9Sstevel@tonic-gate 	 */
1587c478bd9Sstevel@tonic-gate 	cpu[0]->cpu_self = cpu[0];
1597c478bd9Sstevel@tonic-gate 
1604961a633Sdmick 	/*
1614961a633Sdmick 	 * Set up dummy cpu_pri_data values till psm spl code is
1624961a633Sdmick 	 * installed.  This allows splx() to work on amd64.
1634961a633Sdmick 	 */
1644961a633Sdmick 
1654961a633Sdmick 	cpu[0]->cpu_pri_data = dummy_cpu_pri;
1664961a633Sdmick 
1677c478bd9Sstevel@tonic-gate 	/*
1687c478bd9Sstevel@tonic-gate 	 * check if we've got special bits to clear or set
1697c478bd9Sstevel@tonic-gate 	 * when checking cpu features
1707c478bd9Sstevel@tonic-gate 	 */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	cpuid_feature_ecx_include =
173*41791439Sandrei 	    bootprop_getval("cpuid_feature_ecx_include");
1747c478bd9Sstevel@tonic-gate 	cpuid_feature_ecx_exclude =
175*41791439Sandrei 	    bootprop_getval("cpuid_feature_ecx_exclude");
1767c478bd9Sstevel@tonic-gate 	cpuid_feature_edx_include =
177*41791439Sandrei 	    bootprop_getval("cpuid_feature_edx_include");
1787c478bd9Sstevel@tonic-gate 	cpuid_feature_edx_exclude =
179*41791439Sandrei 	    bootprop_getval("cpuid_feature_edx_exclude");
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	/*
1827c478bd9Sstevel@tonic-gate 	 * The first lightweight pass (pass0) through the cpuid data
1837c478bd9Sstevel@tonic-gate 	 * was done in locore before mlsetup was called.  Do the next
1847c478bd9Sstevel@tonic-gate 	 * pass in C code.
1857c478bd9Sstevel@tonic-gate 	 *
1867c478bd9Sstevel@tonic-gate 	 * The x86_feature bits are set here on the basis of the capabilities
1877c478bd9Sstevel@tonic-gate 	 * of the boot CPU.  Note that if we choose to support CPUs that have
1887c478bd9Sstevel@tonic-gate 	 * different feature sets (at which point we would almost certainly
1897c478bd9Sstevel@tonic-gate 	 * want to set the feature bits to correspond to the feature
1907c478bd9Sstevel@tonic-gate 	 * minimum) this value may be altered.
1917c478bd9Sstevel@tonic-gate 	 */
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	x86_feature = cpuid_pass1(cpu[0]);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	/*
1967c478bd9Sstevel@tonic-gate 	 * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss.
1977c478bd9Sstevel@tonic-gate 	 */
1987c478bd9Sstevel@tonic-gate 	init_tables();
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate #if defined(__amd64)
2017c478bd9Sstevel@tonic-gate 	/*CSTYLED*/
2027c478bd9Sstevel@tonic-gate 	{
2037c478bd9Sstevel@tonic-gate 		/*
2047c478bd9Sstevel@tonic-gate 		 * setup %gs for the kernel
2057c478bd9Sstevel@tonic-gate 		 */
2060ac7d7d8Skucharsk 		wrmsr(MSR_AMD_GSBASE, (uint64_t)&cpus[0]);
2077c478bd9Sstevel@tonic-gate 		/*
2087c478bd9Sstevel@tonic-gate 		 * XX64 We should never dereference off "other gsbase" or
2097c478bd9Sstevel@tonic-gate 		 * "fsbase".  So, we should arrange to point FSBASE and
2107c478bd9Sstevel@tonic-gate 		 * KGSBASE somewhere truly awful e.g. point it at the last
2117c478bd9Sstevel@tonic-gate 		 * valid address below the hole so that any attempts to index
2127c478bd9Sstevel@tonic-gate 		 * off them cause an exception.
2137c478bd9Sstevel@tonic-gate 		 *
2147c478bd9Sstevel@tonic-gate 		 * For now, point it at 8G -- at least it should be unmapped
2157c478bd9Sstevel@tonic-gate 		 * until some 64-bit processes run.
2167c478bd9Sstevel@tonic-gate 		 */
2170ac7d7d8Skucharsk 		wrmsr(MSR_AMD_FSBASE, 0x200000000UL);
2180ac7d7d8Skucharsk 		wrmsr(MSR_AMD_KGSBASE, 0x200000000UL);
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate #elif defined(__i386)
2227c478bd9Sstevel@tonic-gate 	/*
2237c478bd9Sstevel@tonic-gate 	 * enable large page support right here.
2247c478bd9Sstevel@tonic-gate 	 */
2257c478bd9Sstevel@tonic-gate 	if (x86_feature & X86_LARGEPAGE) {
2267c478bd9Sstevel@tonic-gate 		cr4_value |= CR4_PSE;
2277c478bd9Sstevel@tonic-gate 		if (x86_feature & X86_PGE)
2287c478bd9Sstevel@tonic-gate 			cr4_value |= CR4_PGE;
2297c478bd9Sstevel@tonic-gate 		setup_121_andcall(enable_big_page_support, cr4_value);
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	/*
2337c478bd9Sstevel@tonic-gate 	 * Some i386 processors do not implement the rdtsc instruction,
2347c478bd9Sstevel@tonic-gate 	 * or at least they do not implement it correctly.
2357c478bd9Sstevel@tonic-gate 	 *
2367c478bd9Sstevel@tonic-gate 	 * For those that do, patch in the rdtsc instructions in
2377c478bd9Sstevel@tonic-gate 	 * various parts of the kernel right now while the text is
2387c478bd9Sstevel@tonic-gate 	 * still writable.
2397c478bd9Sstevel@tonic-gate 	 */
2407c478bd9Sstevel@tonic-gate 	if (x86_feature & X86_TSC)
2417c478bd9Sstevel@tonic-gate 		patch_tsc();
2427c478bd9Sstevel@tonic-gate #endif
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	/*
2457c478bd9Sstevel@tonic-gate 	 * initialize t0
2467c478bd9Sstevel@tonic-gate 	 */
2477c478bd9Sstevel@tonic-gate 	t0.t_stk = (caddr_t)rp - MINFRAME;
2487c478bd9Sstevel@tonic-gate 	t0.t_stkbase = t0stack;
2497c478bd9Sstevel@tonic-gate 	t0.t_pri = maxclsyspri - 3;
2507c478bd9Sstevel@tonic-gate 	t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
2517c478bd9Sstevel@tonic-gate 	t0.t_procp = &p0;
2527c478bd9Sstevel@tonic-gate 	t0.t_plockp = &p0lock.pl_lock;
2537c478bd9Sstevel@tonic-gate 	t0.t_lwp = &lwp0;
2547c478bd9Sstevel@tonic-gate 	t0.t_forw = &t0;
2557c478bd9Sstevel@tonic-gate 	t0.t_back = &t0;
2567c478bd9Sstevel@tonic-gate 	t0.t_next = &t0;
2577c478bd9Sstevel@tonic-gate 	t0.t_prev = &t0;
2587c478bd9Sstevel@tonic-gate 	t0.t_cpu = cpu[0];
2597c478bd9Sstevel@tonic-gate 	t0.t_disp_queue = &cpu0_disp;
2607c478bd9Sstevel@tonic-gate 	t0.t_bind_cpu = PBIND_NONE;
2617c478bd9Sstevel@tonic-gate 	t0.t_bind_pset = PS_NONE;
2627c478bd9Sstevel@tonic-gate 	t0.t_cpupart = &cp_default;
2637c478bd9Sstevel@tonic-gate 	t0.t_clfuncs = &sys_classfuncs.thread;
2647c478bd9Sstevel@tonic-gate 	t0.t_copyops = NULL;
2657c478bd9Sstevel@tonic-gate 	THREAD_ONPROC(&t0, CPU);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	lwp0.lwp_thread = &t0;
2687c478bd9Sstevel@tonic-gate 	lwp0.lwp_regs = (void *) rp;
2697c478bd9Sstevel@tonic-gate 	lwp0.lwp_procp = &p0;
2707c478bd9Sstevel@tonic-gate 	t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	p0.p_exec = NULL;
2737c478bd9Sstevel@tonic-gate 	p0.p_stat = SRUN;
2747c478bd9Sstevel@tonic-gate 	p0.p_flag = SSYS;
2757c478bd9Sstevel@tonic-gate 	p0.p_tlist = &t0;
2767c478bd9Sstevel@tonic-gate 	p0.p_stksize = 2*PAGESIZE;
2777c478bd9Sstevel@tonic-gate 	p0.p_stkpageszc = 0;
2787c478bd9Sstevel@tonic-gate 	p0.p_as = &kas;
2797c478bd9Sstevel@tonic-gate 	p0.p_lockp = &p0lock;
2807c478bd9Sstevel@tonic-gate 	p0.p_brkpageszc = 0;
2817c478bd9Sstevel@tonic-gate 	sigorset(&p0.p_ignore, &ignoredefault);
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	CPU->cpu_thread = &t0;
2847c478bd9Sstevel@tonic-gate 	bzero(&cpu0_disp, sizeof (disp_t));
2857c478bd9Sstevel@tonic-gate 	CPU->cpu_disp = &cpu0_disp;
2867c478bd9Sstevel@tonic-gate 	CPU->cpu_disp->disp_cpu = CPU;
2877c478bd9Sstevel@tonic-gate 	CPU->cpu_dispthread = &t0;
2887c478bd9Sstevel@tonic-gate 	CPU->cpu_idle_thread = &t0;
2897c478bd9Sstevel@tonic-gate 	CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE;
2907c478bd9Sstevel@tonic-gate 	CPU->cpu_dispatch_pri = t0.t_pri;
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	CPU->cpu_id = 0;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	CPU->cpu_tss = &ktss0;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	CPU->cpu_pri = 12;		/* initial PIL for the boot CPU */
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	CPU->cpu_gdt = gdt0;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	/*
3010baeff3dSrab 	 * The kernel doesn't use LDTs unless a process explicitly requests one.
3027c478bd9Sstevel@tonic-gate 	 */
3030baeff3dSrab 	p0.p_ldt_desc = zero_sdesc;
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	/*
3067c478bd9Sstevel@tonic-gate 	 * Kernel IDT.
3077c478bd9Sstevel@tonic-gate 	 */
3087c478bd9Sstevel@tonic-gate 	CPU->cpu_idt = idt0;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	/*
3117c478bd9Sstevel@tonic-gate 	 * Initialize thread/cpu microstate accounting here
3127c478bd9Sstevel@tonic-gate 	 */
3137c478bd9Sstevel@tonic-gate 	init_mstate(&t0, LMS_SYSTEM);
3147c478bd9Sstevel@tonic-gate 	init_cpu_mstate(CPU, CMS_SYSTEM);
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	/*
3177c478bd9Sstevel@tonic-gate 	 * Initialize lists of available and active CPUs.
3187c478bd9Sstevel@tonic-gate 	 */
3197c478bd9Sstevel@tonic-gate 	cpu_list_init(CPU);
3207c478bd9Sstevel@tonic-gate 
321affbd3ccSkchow 	cpu_vm_data_init(CPU);
322affbd3ccSkchow 
323c88420b3Sdmick 	/* lgrp_init() needs PCI config space access */
324c88420b3Sdmick 	pci_cfgspace_init();
325c88420b3Sdmick 
3267c478bd9Sstevel@tonic-gate 	/*
3277c478bd9Sstevel@tonic-gate 	 * Initialize the lgrp framework
3287c478bd9Sstevel@tonic-gate 	 */
3297c478bd9Sstevel@tonic-gate 	lgrp_init();
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	/*
3327c478bd9Sstevel@tonic-gate 	 * The lgroup code needs to at least know about a CPU's
3337c478bd9Sstevel@tonic-gate 	 * chip association, but it's too early to fully initialize
3347c478bd9Sstevel@tonic-gate 	 * cpu0_chip, since the device node for the boot CPU doesn't
3357c478bd9Sstevel@tonic-gate 	 * exist yet. Initialize enough of it to get by until formal
3367c478bd9Sstevel@tonic-gate 	 * initialization.
3377c478bd9Sstevel@tonic-gate 	 */
3387c478bd9Sstevel@tonic-gate 	CPU->cpu_rechoose = rechoose_interval;
3397c478bd9Sstevel@tonic-gate 	CPU->cpu_chip = &cpu0_chip;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	rp->r_fp = 0;	/* terminate kernel stack traces! */
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	prom_init("kernel", (void *)NULL);
3447c478bd9Sstevel@tonic-gate 
345*41791439Sandrei 	boot_ncpus = bootprop_getval("boot-ncpus");
346*41791439Sandrei 
347*41791439Sandrei 	/*
348*41791439Sandrei 	 * To avoid wasting kernel memory, we're temporarily limiting the
349*41791439Sandrei 	 * total number of processors to 32 by default until we get the
350*41791439Sandrei 	 * capability to scan ACPI tables early on boot to detect how many
351*41791439Sandrei 	 * processors are actually present.  However, 64-bit systems
352*41791439Sandrei 	 * can be booted with up to 64 processors by setting "boot-ncpus"
353*41791439Sandrei 	 * boot property to 64.
354*41791439Sandrei 	 */
355*41791439Sandrei 	if (boot_ncpus <= 0 || boot_ncpus > NCPU)
356*41791439Sandrei 		boot_ncpus = 32;
357*41791439Sandrei 
358*41791439Sandrei 	max_ncpus = boot_max_ncpus = boot_ncpus;
359*41791439Sandrei 
3607c478bd9Sstevel@tonic-gate 	if (boothowto & RB_HALT) {
3617c478bd9Sstevel@tonic-gate 		prom_printf("unix: kernel halted by -h flag\n");
3627c478bd9Sstevel@tonic-gate 		prom_enter_mon();
3637c478bd9Sstevel@tonic-gate 	}
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	if (workaround_errata(CPU) != 0)
3687c478bd9Sstevel@tonic-gate 		panic("critical workaround(s) missing for boot cpu");
3697c478bd9Sstevel@tonic-gate }
370