xref: /titanic_51/usr/src/uts/i86pc/os/mlsetup.c (revision a31148363f598def767ac48c5d82e1572e44b935)
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
541791439Sandrei  * Common Development and Distribution License (the "License").
641791439Sandrei  * 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 /*
220e751525SEric Saxe  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25*a3114836SGerry Liu /*
26*a3114836SGerry Liu  * Copyright (c) 2010, Intel Corporation.
27*a3114836SGerry Liu  * All rights reserved.
28*a3114836SGerry Liu  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
31ae115bc7Smrj #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate #include <sys/disp.h>
337c478bd9Sstevel@tonic-gate #include <sys/promif.h>
347c478bd9Sstevel@tonic-gate #include <sys/clock.h>
357c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
367c478bd9Sstevel@tonic-gate #include <sys/stack.h>
377c478bd9Sstevel@tonic-gate #include <vm/as.h>
387c478bd9Sstevel@tonic-gate #include <vm/hat.h>
397c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
407c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
417c478bd9Sstevel@tonic-gate #include <sys/vtrace.h>
427c478bd9Sstevel@tonic-gate #include <sys/proc.h>
437c478bd9Sstevel@tonic-gate #include <sys/thread.h>
447c478bd9Sstevel@tonic-gate #include <sys/cpupart.h>
457c478bd9Sstevel@tonic-gate #include <sys/pset.h>
467c478bd9Sstevel@tonic-gate #include <sys/copyops.h>
47fb2f18f8Sesaxe #include <sys/pg.h>
487c478bd9Sstevel@tonic-gate #include <sys/disp.h>
497c478bd9Sstevel@tonic-gate #include <sys/debug.h>
507c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
517c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
527c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
537c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
547c478bd9Sstevel@tonic-gate #include <sys/ontrap.h>
557c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
569db7147eSSherry Moore #include <sys/boot_console.h>
57ae115bc7Smrj #include <sys/kdi_machimpl.h>
587c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
597c478bd9Sstevel@tonic-gate #include <sys/promif.h>
60c88420b3Sdmick #include <sys/pci_cfgspace.h>
61843e1988Sjohnlev #ifdef __xpv
62843e1988Sjohnlev #include <sys/hypervisor.h>
63349b53ddSStuart Maybee #else
64349b53ddSStuart Maybee #include <sys/xpv_support.h>
65843e1988Sjohnlev #endif
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * some globals for patching the result of cpuid
697c478bd9Sstevel@tonic-gate  * to solve problems w/ creative cpu vendors
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include;
737c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude;
747c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include;
757c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
784961a633Sdmick  * Dummy spl priority masks
794961a633Sdmick  */
804961a633Sdmick static unsigned char dummy_cpu_pri[MAXIPL + 1] = {
814961a633Sdmick 	0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf,
824961a633Sdmick 	0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf
834961a633Sdmick };
844961a633Sdmick 
859db7147eSSherry Moore /*
869db7147eSSherry Moore  * Set console mode
879db7147eSSherry Moore  */
889db7147eSSherry Moore static void
899db7147eSSherry Moore set_console_mode(uint8_t val)
909db7147eSSherry Moore {
919db7147eSSherry Moore 	struct bop_regs rp = {0};
929db7147eSSherry Moore 
939db7147eSSherry Moore 	rp.eax.byte.ah = 0x0;
949db7147eSSherry Moore 	rp.eax.byte.al = val;
959db7147eSSherry Moore 	rp.ebx.word.bx = 0x0;
969db7147eSSherry Moore 
979db7147eSSherry Moore 	BOP_DOINT(bootops, 0x10, &rp);
989db7147eSSherry Moore }
999db7147eSSherry Moore 
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * Setup routine called right before main(). Interposing this function
1037c478bd9Sstevel@tonic-gate  * before main() allows us to call it in a machine-independent fashion.
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate void
1067c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp)
1077c478bd9Sstevel@tonic-gate {
1082baa66a0SJonathan Chew 	u_longlong_t prop_value;
1097c478bd9Sstevel@tonic-gate 	extern struct classfuncs sys_classfuncs;
1107c478bd9Sstevel@tonic-gate 	extern disp_t cpu0_disp;
1117c478bd9Sstevel@tonic-gate 	extern char t0stack[];
1129db7147eSSherry Moore 	extern int post_fastreboot;
1139db7147eSSherry Moore 	extern int console;
114*a3114836SGerry Liu 	extern uint64_t plat_dr_options;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	/*
1197c478bd9Sstevel@tonic-gate 	 * initialize cpu_self
1207c478bd9Sstevel@tonic-gate 	 */
1217c478bd9Sstevel@tonic-gate 	cpu[0]->cpu_self = cpu[0];
1227c478bd9Sstevel@tonic-gate 
123843e1988Sjohnlev #if defined(__xpv)
124843e1988Sjohnlev 	/*
125843e1988Sjohnlev 	 * Point at the hypervisor's virtual cpu structure
126843e1988Sjohnlev 	 */
127843e1988Sjohnlev 	cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0];
128843e1988Sjohnlev #endif
129843e1988Sjohnlev 
1307c478bd9Sstevel@tonic-gate 	/*
1314961a633Sdmick 	 * Set up dummy cpu_pri_data values till psm spl code is
1324961a633Sdmick 	 * installed.  This allows splx() to work on amd64.
1334961a633Sdmick 	 */
1344961a633Sdmick 
1354961a633Sdmick 	cpu[0]->cpu_pri_data = dummy_cpu_pri;
1364961a633Sdmick 
1374961a633Sdmick 	/*
1387c478bd9Sstevel@tonic-gate 	 * check if we've got special bits to clear or set
1397c478bd9Sstevel@tonic-gate 	 * when checking cpu features
1407c478bd9Sstevel@tonic-gate 	 */
1417c478bd9Sstevel@tonic-gate 
1422baa66a0SJonathan Chew 	if (bootprop_getval("cpuid_feature_ecx_include", &prop_value) != 0)
1432baa66a0SJonathan Chew 		cpuid_feature_ecx_include = 0;
1442baa66a0SJonathan Chew 	else
1452baa66a0SJonathan Chew 		cpuid_feature_ecx_include = (uint32_t)prop_value;
1462baa66a0SJonathan Chew 
1472baa66a0SJonathan Chew 	if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0)
1482baa66a0SJonathan Chew 		cpuid_feature_ecx_exclude = 0;
1492baa66a0SJonathan Chew 	else
1502baa66a0SJonathan Chew 		cpuid_feature_ecx_exclude = (uint32_t)prop_value;
1512baa66a0SJonathan Chew 
1522baa66a0SJonathan Chew 	if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0)
1532baa66a0SJonathan Chew 		cpuid_feature_edx_include = 0;
1542baa66a0SJonathan Chew 	else
1552baa66a0SJonathan Chew 		cpuid_feature_edx_include = (uint32_t)prop_value;
1562baa66a0SJonathan Chew 
1572baa66a0SJonathan Chew 	if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0)
1582baa66a0SJonathan Chew 		cpuid_feature_edx_exclude = 0;
1592baa66a0SJonathan Chew 	else
1602baa66a0SJonathan Chew 		cpuid_feature_edx_exclude = (uint32_t)prop_value;
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	/*
16345e032f7SDan Mick 	 * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss.
16445e032f7SDan Mick 	 */
16545e032f7SDan Mick 	init_desctbls();
16645e032f7SDan Mick 
16745e032f7SDan Mick 	/*
16845e032f7SDan Mick 	 * lgrp_init() and possibly cpuid_pass1() need PCI config
16945e032f7SDan Mick 	 * space access
17045e032f7SDan Mick 	 */
17145e032f7SDan Mick #if defined(__xpv)
17245e032f7SDan Mick 	if (DOMAIN_IS_INITDOMAIN(xen_info))
17345e032f7SDan Mick 		pci_cfgspace_init();
17445e032f7SDan Mick #else
17545e032f7SDan Mick 	pci_cfgspace_init();
17645e032f7SDan Mick #endif
17745e032f7SDan Mick 
17845e032f7SDan Mick 	/*
1797c478bd9Sstevel@tonic-gate 	 * The first lightweight pass (pass0) through the cpuid data
1807c478bd9Sstevel@tonic-gate 	 * was done in locore before mlsetup was called.  Do the next
1817c478bd9Sstevel@tonic-gate 	 * pass in C code.
1827c478bd9Sstevel@tonic-gate 	 *
1837c478bd9Sstevel@tonic-gate 	 * The x86_feature bits are set here on the basis of the capabilities
1847c478bd9Sstevel@tonic-gate 	 * of the boot CPU.  Note that if we choose to support CPUs that have
1857c478bd9Sstevel@tonic-gate 	 * different feature sets (at which point we would almost certainly
1867c478bd9Sstevel@tonic-gate 	 * want to set the feature bits to correspond to the feature
1877c478bd9Sstevel@tonic-gate 	 * minimum) this value may be altered.
1887c478bd9Sstevel@tonic-gate 	 */
1897c478bd9Sstevel@tonic-gate 	x86_feature = cpuid_pass1(cpu[0]);
1907c478bd9Sstevel@tonic-gate 
191247dbb3dSsudheer #if !defined(__xpv)
192247dbb3dSsudheer 
193349b53ddSStuart Maybee 	if (get_hwenv() == HW_XEN_HVM)
194349b53ddSStuart Maybee 		xen_hvm_init();
195349b53ddSStuart Maybee 
196247dbb3dSsudheer 	/*
197247dbb3dSsudheer 	 * Patch the tsc_read routine with appropriate set of instructions,
198247dbb3dSsudheer 	 * depending on the processor family and architecure, to read the
199247dbb3dSsudheer 	 * time-stamp counter while ensuring no out-of-order execution.
200247dbb3dSsudheer 	 * Patch it while the kernel text is still writable.
201247dbb3dSsudheer 	 *
202247dbb3dSsudheer 	 * Note: tsc_read is not patched for intel processors whose family
203247dbb3dSsudheer 	 * is >6 and for amd whose family >f (in case they don't support rdtscp
204247dbb3dSsudheer 	 * instruction, unlikely). By default tsc_read will use cpuid for
205247dbb3dSsudheer 	 * serialization in such cases. The following code needs to be
206247dbb3dSsudheer 	 * revisited if intel processors of family >= f retains the
207247dbb3dSsudheer 	 * instruction serialization nature of mfence instruction.
2082b0bcb26Ssudheer 	 * Note: tsc_read is not patched for x86 processors which do
2092b0bcb26Ssudheer 	 * not support "mfence". By default tsc_read will use cpuid for
2102b0bcb26Ssudheer 	 * serialization in such cases.
211551bc2a6Smrj 	 *
212551bc2a6Smrj 	 * The Xen hypervisor does not correctly report whether rdtscp is
213551bc2a6Smrj 	 * supported or not, so we must assume that it is not.
214247dbb3dSsudheer 	 */
215b9bfdccdSStuart Maybee 	if (get_hwenv() != HW_XEN_HVM && (x86_feature & X86_TSCP))
216247dbb3dSsudheer 		patch_tsc_read(X86_HAVE_TSCP);
217247dbb3dSsudheer 	else if (cpuid_getvendor(CPU) == X86_VENDOR_AMD &&
2182b0bcb26Ssudheer 	    cpuid_getfamily(CPU) <= 0xf && (x86_feature & X86_SSE2) != 0)
219247dbb3dSsudheer 		patch_tsc_read(X86_TSC_MFENCE);
220247dbb3dSsudheer 	else if (cpuid_getvendor(CPU) == X86_VENDOR_Intel &&
2212b0bcb26Ssudheer 	    cpuid_getfamily(CPU) <= 6 && (x86_feature & X86_SSE2) != 0)
22215363b27Ssudheer 		patch_tsc_read(X86_TSC_LFENCE);
223247dbb3dSsudheer 
224247dbb3dSsudheer #endif	/* !__xpv */
2257c478bd9Sstevel@tonic-gate 
226843e1988Sjohnlev #if defined(__i386) && !defined(__xpv)
2277c478bd9Sstevel@tonic-gate 	/*
2287c478bd9Sstevel@tonic-gate 	 * Some i386 processors do not implement the rdtsc instruction,
229247dbb3dSsudheer 	 * or at least they do not implement it correctly. Patch them to
230247dbb3dSsudheer 	 * return 0.
2317c478bd9Sstevel@tonic-gate 	 */
232247dbb3dSsudheer 	if ((x86_feature & X86_TSC) == 0)
233247dbb3dSsudheer 		patch_tsc_read(X86_NO_TSC);
234843e1988Sjohnlev #endif	/* __i386 && !__xpv */
235843e1988Sjohnlev 
23622cc0e45SBill Holler #if defined(__amd64) && !defined(__xpv)
23722cc0e45SBill Holler 	patch_memops(cpuid_getvendor(CPU));
23822cc0e45SBill Holler #endif	/* __amd64 && !__xpv */
23922cc0e45SBill Holler 
240843e1988Sjohnlev #if !defined(__xpv)
241843e1988Sjohnlev 	/* XXPV	what, if anything, should be dorked with here under xen? */
242ae115bc7Smrj 
243ae115bc7Smrj 	/*
244ae115bc7Smrj 	 * While we're thinking about the TSC, let's set up %cr4 so that
245ae115bc7Smrj 	 * userland can issue rdtsc, and initialize the TSC_AUX value
246ae115bc7Smrj 	 * (the cpuid) for the rdtscp instruction on appropriately
247ae115bc7Smrj 	 * capable hardware.
248ae115bc7Smrj 	 */
249ae115bc7Smrj 	if (x86_feature & X86_TSC)
250ae115bc7Smrj 		setcr4(getcr4() & ~CR4_TSD);
251ae115bc7Smrj 
252ae115bc7Smrj 	if (x86_feature & X86_TSCP)
253ae115bc7Smrj 		(void) wrmsr(MSR_AMD_TSCAUX, 0);
254ae115bc7Smrj 
255ae115bc7Smrj 	if (x86_feature & X86_DE)
256ae115bc7Smrj 		setcr4(getcr4() | CR4_DE);
257843e1988Sjohnlev #endif /* __xpv */
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	/*
2607c478bd9Sstevel@tonic-gate 	 * initialize t0
2617c478bd9Sstevel@tonic-gate 	 */
2627c478bd9Sstevel@tonic-gate 	t0.t_stk = (caddr_t)rp - MINFRAME;
2637c478bd9Sstevel@tonic-gate 	t0.t_stkbase = t0stack;
2647c478bd9Sstevel@tonic-gate 	t0.t_pri = maxclsyspri - 3;
2657c478bd9Sstevel@tonic-gate 	t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
2667c478bd9Sstevel@tonic-gate 	t0.t_procp = &p0;
2677c478bd9Sstevel@tonic-gate 	t0.t_plockp = &p0lock.pl_lock;
2687c478bd9Sstevel@tonic-gate 	t0.t_lwp = &lwp0;
2697c478bd9Sstevel@tonic-gate 	t0.t_forw = &t0;
2707c478bd9Sstevel@tonic-gate 	t0.t_back = &t0;
2717c478bd9Sstevel@tonic-gate 	t0.t_next = &t0;
2727c478bd9Sstevel@tonic-gate 	t0.t_prev = &t0;
2737c478bd9Sstevel@tonic-gate 	t0.t_cpu = cpu[0];
2747c478bd9Sstevel@tonic-gate 	t0.t_disp_queue = &cpu0_disp;
2757c478bd9Sstevel@tonic-gate 	t0.t_bind_cpu = PBIND_NONE;
2767c478bd9Sstevel@tonic-gate 	t0.t_bind_pset = PS_NONE;
2770b70c467Sakolb 	t0.t_bindflag = (uchar_t)default_binding_mode;
2787c478bd9Sstevel@tonic-gate 	t0.t_cpupart = &cp_default;
2797c478bd9Sstevel@tonic-gate 	t0.t_clfuncs = &sys_classfuncs.thread;
2807c478bd9Sstevel@tonic-gate 	t0.t_copyops = NULL;
2817c478bd9Sstevel@tonic-gate 	THREAD_ONPROC(&t0, CPU);
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	lwp0.lwp_thread = &t0;
2847c478bd9Sstevel@tonic-gate 	lwp0.lwp_regs = (void *)rp;
2857c478bd9Sstevel@tonic-gate 	lwp0.lwp_procp = &p0;
2867c478bd9Sstevel@tonic-gate 	t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	p0.p_exec = NULL;
2897c478bd9Sstevel@tonic-gate 	p0.p_stat = SRUN;
2907c478bd9Sstevel@tonic-gate 	p0.p_flag = SSYS;
2917c478bd9Sstevel@tonic-gate 	p0.p_tlist = &t0;
2927c478bd9Sstevel@tonic-gate 	p0.p_stksize = 2*PAGESIZE;
2937c478bd9Sstevel@tonic-gate 	p0.p_stkpageszc = 0;
2947c478bd9Sstevel@tonic-gate 	p0.p_as = &kas;
2957c478bd9Sstevel@tonic-gate 	p0.p_lockp = &p0lock;
2967c478bd9Sstevel@tonic-gate 	p0.p_brkpageszc = 0;
2972cb27123Saguzovsk 	p0.p_t1_lgrpid = LGRP_NONE;
2982cb27123Saguzovsk 	p0.p_tr_lgrpid = LGRP_NONE;
2997c478bd9Sstevel@tonic-gate 	sigorset(&p0.p_ignore, &ignoredefault);
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 	CPU->cpu_thread = &t0;
3027c478bd9Sstevel@tonic-gate 	bzero(&cpu0_disp, sizeof (disp_t));
3037c478bd9Sstevel@tonic-gate 	CPU->cpu_disp = &cpu0_disp;
3047c478bd9Sstevel@tonic-gate 	CPU->cpu_disp->disp_cpu = CPU;
3057c478bd9Sstevel@tonic-gate 	CPU->cpu_dispthread = &t0;
3067c478bd9Sstevel@tonic-gate 	CPU->cpu_idle_thread = &t0;
3077c478bd9Sstevel@tonic-gate 	CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE;
3087c478bd9Sstevel@tonic-gate 	CPU->cpu_dispatch_pri = t0.t_pri;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	CPU->cpu_id = 0;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	CPU->cpu_pri = 12;		/* initial PIL for the boot CPU */
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	/*
3150baeff3dSrab 	 * The kernel doesn't use LDTs unless a process explicitly requests one.
3167c478bd9Sstevel@tonic-gate 	 */
317843e1988Sjohnlev 	p0.p_ldt_desc = null_sdesc;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	/*
320ae115bc7Smrj 	 * Initialize thread/cpu microstate accounting
3217c478bd9Sstevel@tonic-gate 	 */
3227c478bd9Sstevel@tonic-gate 	init_mstate(&t0, LMS_SYSTEM);
3237c478bd9Sstevel@tonic-gate 	init_cpu_mstate(CPU, CMS_SYSTEM);
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	/*
3267c478bd9Sstevel@tonic-gate 	 * Initialize lists of available and active CPUs.
3277c478bd9Sstevel@tonic-gate 	 */
3287c478bd9Sstevel@tonic-gate 	cpu_list_init(CPU);
3297c478bd9Sstevel@tonic-gate 
3300e751525SEric Saxe 	pg_cpu_bootstrap(CPU);
3310e751525SEric Saxe 
332ae115bc7Smrj 	/*
333ae115bc7Smrj 	 * Now that we have taken over the GDT, IDT and have initialized
334ae115bc7Smrj 	 * active CPU list it's time to inform kmdb if present.
335ae115bc7Smrj 	 */
336ae115bc7Smrj 	if (boothowto & RB_DEBUG)
337ae115bc7Smrj 		kdi_idt_sync();
338ae115bc7Smrj 
339ae115bc7Smrj 	/*
3409db7147eSSherry Moore 	 * Explicitly set console to text mode (0x3) if this is a boot
3419db7147eSSherry Moore 	 * post Fast Reboot, and the console is set to CONS_SCREEN_TEXT.
3429db7147eSSherry Moore 	 */
3439db7147eSSherry Moore 	if (post_fastreboot && console == CONS_SCREEN_TEXT)
3449db7147eSSherry Moore 		set_console_mode(0x3);
3459db7147eSSherry Moore 
3469db7147eSSherry Moore 	/*
347ae115bc7Smrj 	 * If requested (boot -d) drop into kmdb.
348ae115bc7Smrj 	 *
349ae115bc7Smrj 	 * This must be done after cpu_list_init() on the 64-bit kernel
350ae115bc7Smrj 	 * since taking a trap requires that we re-compute gsbase based
351ae115bc7Smrj 	 * on the cpu list.
352ae115bc7Smrj 	 */
353ae115bc7Smrj 	if (boothowto & RB_DEBUGENTER)
354ae115bc7Smrj 		kmdb_enter();
355ae115bc7Smrj 
356affbd3ccSkchow 	cpu_vm_data_init(CPU);
357affbd3ccSkchow 
3587c478bd9Sstevel@tonic-gate 	rp->r_fp = 0;	/* terminate kernel stack traces! */
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate 	prom_init("kernel", (void *)NULL);
3617c478bd9Sstevel@tonic-gate 
362*a3114836SGerry Liu 	/* User-set option overrides firmware value. */
363*a3114836SGerry Liu 	if (bootprop_getval(PLAT_DR_OPTIONS_NAME, &prop_value) == 0) {
364*a3114836SGerry Liu 		plat_dr_options = (uint64_t)prop_value;
365*a3114836SGerry Liu 	}
366*a3114836SGerry Liu #if defined(__xpv)
367*a3114836SGerry Liu 	/* No support of DR operations on xpv */
368*a3114836SGerry Liu 	plat_dr_options = 0;
369*a3114836SGerry Liu #else	/* __xpv */
370*a3114836SGerry Liu 	/* Flag PLAT_DR_FEATURE_ENABLED should only be set by DR driver. */
371*a3114836SGerry Liu 	plat_dr_options &= ~PLAT_DR_FEATURE_ENABLED;
372*a3114836SGerry Liu #ifndef	__amd64
373*a3114836SGerry Liu 	/* Only enable CPU/memory DR on 64 bits kernel. */
374*a3114836SGerry Liu 	plat_dr_options &= ~PLAT_DR_FEATURE_MEMORY;
375*a3114836SGerry Liu 	plat_dr_options &= ~PLAT_DR_FEATURE_CPU;
376*a3114836SGerry Liu #endif	/* __amd64 */
377*a3114836SGerry Liu #endif	/* __xpv */
378*a3114836SGerry Liu 
379*a3114836SGerry Liu 	/*
380*a3114836SGerry Liu 	 * Get value of "plat_dr_physmax" boot option.
381*a3114836SGerry Liu 	 * It overrides values calculated from MSCT or SRAT table.
382*a3114836SGerry Liu 	 */
383*a3114836SGerry Liu 	if (bootprop_getval(PLAT_DR_PHYSMAX_NAME, &prop_value) == 0) {
384*a3114836SGerry Liu 		plat_dr_physmax = ((uint64_t)prop_value) >> PAGESHIFT;
385*a3114836SGerry Liu 	}
386*a3114836SGerry Liu 
387*a3114836SGerry Liu 	/* Get value of boot_ncpus. */
388*a3114836SGerry Liu 	if (bootprop_getval(BOOT_NCPUS_NAME, &prop_value) != 0) {
3892baa66a0SJonathan Chew 		boot_ncpus = NCPU;
390*a3114836SGerry Liu 	} else {
3912baa66a0SJonathan Chew 		boot_ncpus = (int)prop_value;
39241791439Sandrei 		if (boot_ncpus <= 0 || boot_ncpus > NCPU)
393ae115bc7Smrj 			boot_ncpus = NCPU;
3942baa66a0SJonathan Chew 	}
39541791439Sandrei 
396*a3114836SGerry Liu 	/*
397*a3114836SGerry Liu 	 * Set max_ncpus and boot_max_ncpus to boot_ncpus if platform doesn't
398*a3114836SGerry Liu 	 * support CPU DR operations.
399*a3114836SGerry Liu 	 */
400*a3114836SGerry Liu 	if (plat_dr_support_cpu() == 0) {
40141791439Sandrei 		max_ncpus = boot_max_ncpus = boot_ncpus;
402*a3114836SGerry Liu 	} else {
403*a3114836SGerry Liu 		if (bootprop_getval(PLAT_MAX_NCPUS_NAME, &prop_value) != 0) {
404*a3114836SGerry Liu 			max_ncpus = NCPU;
405*a3114836SGerry Liu 		} else {
406*a3114836SGerry Liu 			max_ncpus = (int)prop_value;
407*a3114836SGerry Liu 			if (max_ncpus <= 0 || max_ncpus > NCPU) {
408*a3114836SGerry Liu 				max_ncpus = NCPU;
409*a3114836SGerry Liu 			}
410*a3114836SGerry Liu 			if (boot_ncpus > max_ncpus) {
411*a3114836SGerry Liu 				boot_ncpus = max_ncpus;
412*a3114836SGerry Liu 			}
413*a3114836SGerry Liu 		}
414*a3114836SGerry Liu 
415*a3114836SGerry Liu 		if (bootprop_getval(BOOT_MAX_NCPUS_NAME, &prop_value) != 0) {
416*a3114836SGerry Liu 			boot_max_ncpus = boot_ncpus;
417*a3114836SGerry Liu 		} else {
418*a3114836SGerry Liu 			boot_max_ncpus = (int)prop_value;
419*a3114836SGerry Liu 			if (boot_max_ncpus <= 0 || boot_max_ncpus > NCPU) {
420*a3114836SGerry Liu 				boot_max_ncpus = boot_ncpus;
421*a3114836SGerry Liu 			} else if (boot_max_ncpus > max_ncpus) {
422*a3114836SGerry Liu 				boot_max_ncpus = max_ncpus;
423*a3114836SGerry Liu 			}
424*a3114836SGerry Liu 		}
425*a3114836SGerry Liu 	}
42641791439Sandrei 
4272e2c009bSjjc 	/*
4282e2c009bSjjc 	 * Initialize the lgrp framework
4292e2c009bSjjc 	 */
430d5d7cf4eSJonathan Chew 	lgrp_init(LGRP_INIT_STAGE1);
4312e2c009bSjjc 
4327c478bd9Sstevel@tonic-gate 	if (boothowto & RB_HALT) {
4337c478bd9Sstevel@tonic-gate 		prom_printf("unix: kernel halted by -h flag\n");
4347c478bd9Sstevel@tonic-gate 		prom_enter_mon();
4357c478bd9Sstevel@tonic-gate 	}
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	ASSERT_STACK_ALIGNED();
4387c478bd9Sstevel@tonic-gate 
4392449e17fSsherrym 	/*
4402449e17fSsherrym 	 * Fill out cpu_ucode_info.  Update microcode if necessary.
4412449e17fSsherrym 	 */
4422449e17fSsherrym 	ucode_check(CPU);
4432449e17fSsherrym 
4447c478bd9Sstevel@tonic-gate 	if (workaround_errata(CPU) != 0)
4457c478bd9Sstevel@tonic-gate 		panic("critical workaround(s) missing for boot cpu");
4467c478bd9Sstevel@tonic-gate }
447986fd29aSsetje 
448986fd29aSsetje 
449986fd29aSsetje void
450986fd29aSsetje mach_modpath(char *path, const char *filename)
451986fd29aSsetje {
452986fd29aSsetje 	/*
453986fd29aSsetje 	 * Construct the directory path from the filename.
454986fd29aSsetje 	 */
455986fd29aSsetje 
456986fd29aSsetje 	int len;
457986fd29aSsetje 	char *p;
458986fd29aSsetje 	const char isastr[] = "/amd64";
459986fd29aSsetje 	size_t isalen = strlen(isastr);
460986fd29aSsetje 
461986fd29aSsetje 	if ((p = strrchr(filename, '/')) == NULL)
462986fd29aSsetje 		return;
463986fd29aSsetje 
464986fd29aSsetje 	while (p > filename && *(p - 1) == '/')
465986fd29aSsetje 		p--;	/* remove trailing '/' characters */
466986fd29aSsetje 	if (p == filename)
467986fd29aSsetje 		p++;	/* so "/" -is- the modpath in this case */
468986fd29aSsetje 
469986fd29aSsetje 	/*
470986fd29aSsetje 	 * Remove optional isa-dependent directory name - the module
471986fd29aSsetje 	 * subsystem will put this back again (!)
472986fd29aSsetje 	 */
473986fd29aSsetje 	len = p - filename;
474986fd29aSsetje 	if (len > isalen &&
475986fd29aSsetje 	    strncmp(&filename[len - isalen], isastr, isalen) == 0)
476986fd29aSsetje 		p -= isalen;
477986fd29aSsetje 
478986fd29aSsetje 	/*
479986fd29aSsetje 	 * "/platform/mumblefrotz" + " " + MOD_DEFPATH
480986fd29aSsetje 	 */
481986fd29aSsetje 	len += (p - filename) + 1 + strlen(MOD_DEFPATH) + 1;
482986fd29aSsetje 	(void) strncpy(path, filename, p - filename);
483986fd29aSsetje }
484