xref: /illumos-gate/usr/src/uts/i86pc/os/mlsetup.c (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/disp.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/promif.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/clock.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/stack.h>
35*7c478bd9Sstevel@tonic-gate #include <vm/as.h>
36*7c478bd9Sstevel@tonic-gate #include <vm/hat.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/proc.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/thread.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/cpupart.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/pset.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/copyops.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/chip.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/disp.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/debug.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/ontrap.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/kdi.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
56*7c478bd9Sstevel@tonic-gate #include <sys/promif.h>
57*7c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/kobj_lex.h>
60*7c478bd9Sstevel@tonic-gate #if defined(__amd64)
61*7c478bd9Sstevel@tonic-gate #include <sys/bootsvcs.h>
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate /*
64*7c478bd9Sstevel@tonic-gate  * XX64	This stuff deals with switching stacks in case a trapping
65*7c478bd9Sstevel@tonic-gate  *	thread wants to call back into boot -after- boot has lost track
66*7c478bd9Sstevel@tonic-gate  *	of the mappings but before the kernel owns the console.
67*7c478bd9Sstevel@tonic-gate  *
68*7c478bd9Sstevel@tonic-gate  *	(A better way to hide this would be to add a 'this' pointer to
69*7c478bd9Sstevel@tonic-gate  *	every boot syscall so that vmx could get at the resulting save
70*7c478bd9Sstevel@tonic-gate  *	area.)
71*7c478bd9Sstevel@tonic-gate  */
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate struct boot_syscalls *_vmx_sysp;
74*7c478bd9Sstevel@tonic-gate static struct boot_syscalls __kbootsvcs;
75*7c478bd9Sstevel@tonic-gate extern struct boot_syscalls *sysp;
76*7c478bd9Sstevel@tonic-gate extern void _stack_safe_putchar(int c);
77*7c478bd9Sstevel@tonic-gate #endif
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate  * some globals for patching the result of cpuid
81*7c478bd9Sstevel@tonic-gate  * to solve problems w/ creative cpu vendors
82*7c478bd9Sstevel@tonic-gate  */
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include;
85*7c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude;
86*7c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include;
87*7c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude;
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate  * External Routines:
91*7c478bd9Sstevel@tonic-gate  */
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate extern void init_tables(void);
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate static uint32_t
97*7c478bd9Sstevel@tonic-gate cpuid_getval(char *name)
98*7c478bd9Sstevel@tonic-gate {
99*7c478bd9Sstevel@tonic-gate 	char prop[32];
100*7c478bd9Sstevel@tonic-gate 	u_longlong_t ll;
101*7c478bd9Sstevel@tonic-gate 	extern struct bootops *bootops;
102*7c478bd9Sstevel@tonic-gate 	if ((BOP_GETPROPLEN(bootops, name) > sizeof (prop)) ||
103*7c478bd9Sstevel@tonic-gate 	    (BOP_GETPROP(bootops, name, prop) < 0) ||
104*7c478bd9Sstevel@tonic-gate 	    (kobj_getvalue(prop, &ll) == -1))
105*7c478bd9Sstevel@tonic-gate 		return (0);
106*7c478bd9Sstevel@tonic-gate 	return ((uint32_t)ll);
107*7c478bd9Sstevel@tonic-gate }
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /*
110*7c478bd9Sstevel@tonic-gate  * Setup routine called right before main(). Interposing this function
111*7c478bd9Sstevel@tonic-gate  * before main() allows us to call it in a machine-independent fashion.
112*7c478bd9Sstevel@tonic-gate  */
113*7c478bd9Sstevel@tonic-gate void
114*7c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp)
115*7c478bd9Sstevel@tonic-gate {
116*7c478bd9Sstevel@tonic-gate 	extern struct classfuncs sys_classfuncs;
117*7c478bd9Sstevel@tonic-gate 	extern struct chip cpu0_chip;
118*7c478bd9Sstevel@tonic-gate 	extern disp_t cpu0_disp;
119*7c478bd9Sstevel@tonic-gate 	extern char t0stack[];
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate #if defined(__amd64)
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate #if (BS_VERSION > 4)
126*7c478bd9Sstevel@tonic-gate 	/*
127*7c478bd9Sstevel@tonic-gate 	 * When new boot_syscalls are added to the vector, this routine
128*7c478bd9Sstevel@tonic-gate 	 * must be modified to copy them into the kernel's copy of the
129*7c478bd9Sstevel@tonic-gate 	 * vector.
130*7c478bd9Sstevel@tonic-gate 	 */
131*7c478bd9Sstevel@tonic-gate #error mlsetup() must be updated for amd64 to support new boot_syscalls
132*7c478bd9Sstevel@tonic-gate #endif	/* (BS_VERSION > 4) */
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate 	/*
135*7c478bd9Sstevel@tonic-gate 	 * XX64	This remaps vmx's putchar to use the kernel's version
136*7c478bd9Sstevel@tonic-gate 	 *	that switches stacks before diving into vmx
137*7c478bd9Sstevel@tonic-gate 	 *	See explanation/complaints in commentary above.
138*7c478bd9Sstevel@tonic-gate 	 */
139*7c478bd9Sstevel@tonic-gate 	_vmx_sysp = sysp;
140*7c478bd9Sstevel@tonic-gate 	sysp = &__kbootsvcs;
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	sysp->bsvc_getchar = _vmx_sysp->bsvc_getchar;
143*7c478bd9Sstevel@tonic-gate 	sysp->bsvc_putchar = _stack_safe_putchar;
144*7c478bd9Sstevel@tonic-gate 	sysp->bsvc_ischar = _vmx_sysp->bsvc_ischar;
145*7c478bd9Sstevel@tonic-gate #endif
146*7c478bd9Sstevel@tonic-gate 	/*
147*7c478bd9Sstevel@tonic-gate 	 * initialize cpu_self
148*7c478bd9Sstevel@tonic-gate 	 */
149*7c478bd9Sstevel@tonic-gate 	cpu[0]->cpu_self = cpu[0];
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 	/*
152*7c478bd9Sstevel@tonic-gate 	 * check if we've got special bits to clear or set
153*7c478bd9Sstevel@tonic-gate 	 * when checking cpu features
154*7c478bd9Sstevel@tonic-gate 	 */
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	cpuid_feature_ecx_include =
157*7c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_ecx_include");
158*7c478bd9Sstevel@tonic-gate 	cpuid_feature_ecx_exclude =
159*7c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_ecx_exclude");
160*7c478bd9Sstevel@tonic-gate 	cpuid_feature_edx_include =
161*7c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_edx_include");
162*7c478bd9Sstevel@tonic-gate 	cpuid_feature_edx_exclude =
163*7c478bd9Sstevel@tonic-gate 	    cpuid_getval("cpuid_feature_edx_exclude");
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	/*
166*7c478bd9Sstevel@tonic-gate 	 * The first lightweight pass (pass0) through the cpuid data
167*7c478bd9Sstevel@tonic-gate 	 * was done in locore before mlsetup was called.  Do the next
168*7c478bd9Sstevel@tonic-gate 	 * pass in C code.
169*7c478bd9Sstevel@tonic-gate 	 *
170*7c478bd9Sstevel@tonic-gate 	 * The x86_feature bits are set here on the basis of the capabilities
171*7c478bd9Sstevel@tonic-gate 	 * of the boot CPU.  Note that if we choose to support CPUs that have
172*7c478bd9Sstevel@tonic-gate 	 * different feature sets (at which point we would almost certainly
173*7c478bd9Sstevel@tonic-gate 	 * want to set the feature bits to correspond to the feature
174*7c478bd9Sstevel@tonic-gate 	 * minimum) this value may be altered.
175*7c478bd9Sstevel@tonic-gate 	 */
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	x86_feature = cpuid_pass1(cpu[0]);
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	/*
180*7c478bd9Sstevel@tonic-gate 	 * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss.
181*7c478bd9Sstevel@tonic-gate 	 */
182*7c478bd9Sstevel@tonic-gate 	init_tables();
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate #if defined(__amd64)
185*7c478bd9Sstevel@tonic-gate 	/*CSTYLED*/
186*7c478bd9Sstevel@tonic-gate 	{
187*7c478bd9Sstevel@tonic-gate 		/*
188*7c478bd9Sstevel@tonic-gate 		 * setup %gs for the kernel
189*7c478bd9Sstevel@tonic-gate 		 */
190*7c478bd9Sstevel@tonic-gate 		uint64_t addr64 = (uint64_t)&cpus[0];
191*7c478bd9Sstevel@tonic-gate 		wrmsr(MSR_AMD_GSBASE, &addr64);
192*7c478bd9Sstevel@tonic-gate 		/*
193*7c478bd9Sstevel@tonic-gate 		 * XX64 We should never dereference off "other gsbase" or
194*7c478bd9Sstevel@tonic-gate 		 * "fsbase".  So, we should arrange to point FSBASE and
195*7c478bd9Sstevel@tonic-gate 		 * KGSBASE somewhere truly awful e.g. point it at the last
196*7c478bd9Sstevel@tonic-gate 		 * valid address below the hole so that any attempts to index
197*7c478bd9Sstevel@tonic-gate 		 * off them cause an exception.
198*7c478bd9Sstevel@tonic-gate 		 *
199*7c478bd9Sstevel@tonic-gate 		 * For now, point it at 8G -- at least it should be unmapped
200*7c478bd9Sstevel@tonic-gate 		 * until some 64-bit processes run.
201*7c478bd9Sstevel@tonic-gate 		 */
202*7c478bd9Sstevel@tonic-gate 		addr64 = 0x200000000ul;
203*7c478bd9Sstevel@tonic-gate 		wrmsr(MSR_AMD_FSBASE, &addr64);
204*7c478bd9Sstevel@tonic-gate 		wrmsr(MSR_AMD_KGSBASE, &addr64);
205*7c478bd9Sstevel@tonic-gate 	}
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate #elif defined(__i386)
208*7c478bd9Sstevel@tonic-gate 	/*
209*7c478bd9Sstevel@tonic-gate 	 * enable large page support right here.
210*7c478bd9Sstevel@tonic-gate 	 */
211*7c478bd9Sstevel@tonic-gate 	if (x86_feature & X86_LARGEPAGE) {
212*7c478bd9Sstevel@tonic-gate 		cr4_value |= CR4_PSE;
213*7c478bd9Sstevel@tonic-gate 		if (x86_feature & X86_PGE)
214*7c478bd9Sstevel@tonic-gate 			cr4_value |= CR4_PGE;
215*7c478bd9Sstevel@tonic-gate 		setup_121_andcall(enable_big_page_support, cr4_value);
216*7c478bd9Sstevel@tonic-gate 	}
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 	/*
219*7c478bd9Sstevel@tonic-gate 	 * Some i386 processors do not implement the rdtsc instruction,
220*7c478bd9Sstevel@tonic-gate 	 * or at least they do not implement it correctly.
221*7c478bd9Sstevel@tonic-gate 	 *
222*7c478bd9Sstevel@tonic-gate 	 * For those that do, patch in the rdtsc instructions in
223*7c478bd9Sstevel@tonic-gate 	 * various parts of the kernel right now while the text is
224*7c478bd9Sstevel@tonic-gate 	 * still writable.
225*7c478bd9Sstevel@tonic-gate 	 */
226*7c478bd9Sstevel@tonic-gate 	if (x86_feature & X86_TSC)
227*7c478bd9Sstevel@tonic-gate 		patch_tsc();
228*7c478bd9Sstevel@tonic-gate #endif
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	/*
231*7c478bd9Sstevel@tonic-gate 	 * initialize t0
232*7c478bd9Sstevel@tonic-gate 	 */
233*7c478bd9Sstevel@tonic-gate 	t0.t_stk = (caddr_t)rp - MINFRAME;
234*7c478bd9Sstevel@tonic-gate 	t0.t_stkbase = t0stack;
235*7c478bd9Sstevel@tonic-gate 	t0.t_pri = maxclsyspri - 3;
236*7c478bd9Sstevel@tonic-gate 	t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
237*7c478bd9Sstevel@tonic-gate 	t0.t_procp = &p0;
238*7c478bd9Sstevel@tonic-gate 	t0.t_plockp = &p0lock.pl_lock;
239*7c478bd9Sstevel@tonic-gate 	t0.t_lwp = &lwp0;
240*7c478bd9Sstevel@tonic-gate 	t0.t_forw = &t0;
241*7c478bd9Sstevel@tonic-gate 	t0.t_back = &t0;
242*7c478bd9Sstevel@tonic-gate 	t0.t_next = &t0;
243*7c478bd9Sstevel@tonic-gate 	t0.t_prev = &t0;
244*7c478bd9Sstevel@tonic-gate 	t0.t_cpu = cpu[0];
245*7c478bd9Sstevel@tonic-gate 	t0.t_disp_queue = &cpu0_disp;
246*7c478bd9Sstevel@tonic-gate 	t0.t_bind_cpu = PBIND_NONE;
247*7c478bd9Sstevel@tonic-gate 	t0.t_bind_pset = PS_NONE;
248*7c478bd9Sstevel@tonic-gate 	t0.t_cpupart = &cp_default;
249*7c478bd9Sstevel@tonic-gate 	t0.t_clfuncs = &sys_classfuncs.thread;
250*7c478bd9Sstevel@tonic-gate 	t0.t_copyops = NULL;
251*7c478bd9Sstevel@tonic-gate 	THREAD_ONPROC(&t0, CPU);
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 	lwp0.lwp_thread = &t0;
254*7c478bd9Sstevel@tonic-gate 	lwp0.lwp_regs = (void *) rp;
255*7c478bd9Sstevel@tonic-gate 	lwp0.lwp_procp = &p0;
256*7c478bd9Sstevel@tonic-gate 	t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	p0.p_exec = NULL;
259*7c478bd9Sstevel@tonic-gate 	p0.p_stat = SRUN;
260*7c478bd9Sstevel@tonic-gate 	p0.p_flag = SSYS;
261*7c478bd9Sstevel@tonic-gate 	p0.p_tlist = &t0;
262*7c478bd9Sstevel@tonic-gate 	p0.p_stksize = 2*PAGESIZE;
263*7c478bd9Sstevel@tonic-gate 	p0.p_stkpageszc = 0;
264*7c478bd9Sstevel@tonic-gate 	p0.p_as = &kas;
265*7c478bd9Sstevel@tonic-gate 	p0.p_lockp = &p0lock;
266*7c478bd9Sstevel@tonic-gate 	p0.p_brkpageszc = 0;
267*7c478bd9Sstevel@tonic-gate 	sigorset(&p0.p_ignore, &ignoredefault);
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate 	CPU->cpu_thread = &t0;
270*7c478bd9Sstevel@tonic-gate 	bzero(&cpu0_disp, sizeof (disp_t));
271*7c478bd9Sstevel@tonic-gate 	CPU->cpu_disp = &cpu0_disp;
272*7c478bd9Sstevel@tonic-gate 	CPU->cpu_disp->disp_cpu = CPU;
273*7c478bd9Sstevel@tonic-gate 	CPU->cpu_dispthread = &t0;
274*7c478bd9Sstevel@tonic-gate 	CPU->cpu_idle_thread = &t0;
275*7c478bd9Sstevel@tonic-gate 	CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE;
276*7c478bd9Sstevel@tonic-gate 	CPU->cpu_dispatch_pri = t0.t_pri;
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 	CPU->cpu_mask = 1;
279*7c478bd9Sstevel@tonic-gate 	CPU->cpu_id = 0;
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate 	CPU->cpu_tss = &ktss0;
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate 	CPU->cpu_pri = 12;		/* initial PIL for the boot CPU */
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 	CPU->cpu_ldt = ldt0_default;	/* default LDT */
286*7c478bd9Sstevel@tonic-gate 	CPU->cpu_gdt = gdt0;
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate 	/*
289*7c478bd9Sstevel@tonic-gate 	 * This must be done _after_ init_tables(), called above, has set up
290*7c478bd9Sstevel@tonic-gate 	 * ldt0_default_desc.
291*7c478bd9Sstevel@tonic-gate 	 */
292*7c478bd9Sstevel@tonic-gate #if defined(__amd64)
293*7c478bd9Sstevel@tonic-gate 	/*
294*7c478bd9Sstevel@tonic-gate 	 * ldt0_default64 contains all invalid entries. We use that as p0's LDT
295*7c478bd9Sstevel@tonic-gate 	 * because p0 should never have any reason to use the LDT. This will
296*7c478bd9Sstevel@tonic-gate 	 * catch things early if such a scenario should ever occur.
297*7c478bd9Sstevel@tonic-gate 	 */
298*7c478bd9Sstevel@tonic-gate 	p0.p_ldt_desc = ldt0_default64_desc;
299*7c478bd9Sstevel@tonic-gate #else
300*7c478bd9Sstevel@tonic-gate 	p0.p_ldt_desc = ldt0_default_desc;
301*7c478bd9Sstevel@tonic-gate #endif /* __amd64 */
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	/*
304*7c478bd9Sstevel@tonic-gate 	 * Kernel IDT.
305*7c478bd9Sstevel@tonic-gate 	 */
306*7c478bd9Sstevel@tonic-gate 	CPU->cpu_idt = idt0;
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate 	/*
309*7c478bd9Sstevel@tonic-gate 	 * Initialize thread/cpu microstate accounting here
310*7c478bd9Sstevel@tonic-gate 	 */
311*7c478bd9Sstevel@tonic-gate 	init_mstate(&t0, LMS_SYSTEM);
312*7c478bd9Sstevel@tonic-gate 	init_cpu_mstate(CPU, CMS_SYSTEM);
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	/*
315*7c478bd9Sstevel@tonic-gate 	 * Initialize lists of available and active CPUs.
316*7c478bd9Sstevel@tonic-gate 	 */
317*7c478bd9Sstevel@tonic-gate 	cpu_list_init(CPU);
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate 	/*
320*7c478bd9Sstevel@tonic-gate 	 * Initialize the lgrp framework
321*7c478bd9Sstevel@tonic-gate 	 */
322*7c478bd9Sstevel@tonic-gate 	lgrp_init();
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate 	/*
325*7c478bd9Sstevel@tonic-gate 	 * The lgroup code needs to at least know about a CPU's
326*7c478bd9Sstevel@tonic-gate 	 * chip association, but it's too early to fully initialize
327*7c478bd9Sstevel@tonic-gate 	 * cpu0_chip, since the device node for the boot CPU doesn't
328*7c478bd9Sstevel@tonic-gate 	 * exist yet. Initialize enough of it to get by until formal
329*7c478bd9Sstevel@tonic-gate 	 * initialization.
330*7c478bd9Sstevel@tonic-gate 	 */
331*7c478bd9Sstevel@tonic-gate 	CPU->cpu_rechoose = rechoose_interval;
332*7c478bd9Sstevel@tonic-gate 	CPU->cpu_chip = &cpu0_chip;
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	rp->r_fp = 0;	/* terminate kernel stack traces! */
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 	prom_init("kernel", (void *)NULL);
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 	if (boothowto & RB_HALT) {
339*7c478bd9Sstevel@tonic-gate 		prom_printf("unix: kernel halted by -h flag\n");
340*7c478bd9Sstevel@tonic-gate 		prom_enter_mon();
341*7c478bd9Sstevel@tonic-gate 	}
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate 	if (workaround_errata(CPU) != 0)
346*7c478bd9Sstevel@tonic-gate 		panic("critical workaround(s) missing for boot cpu");
347*7c478bd9Sstevel@tonic-gate }
348