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 /* 227417cfdeSKuriakose Kuruvilla * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 24a3114836SGerry Liu /* 25a3114836SGerry Liu * Copyright (c) 2010, Intel Corporation. 26a3114836SGerry Liu * All rights reserved. 27a3114836SGerry Liu */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 30ae115bc7Smrj #include <sys/sysmacros.h> 317c478bd9Sstevel@tonic-gate #include <sys/disp.h> 327c478bd9Sstevel@tonic-gate #include <sys/promif.h> 337c478bd9Sstevel@tonic-gate #include <sys/clock.h> 347c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 357c478bd9Sstevel@tonic-gate #include <sys/stack.h> 367c478bd9Sstevel@tonic-gate #include <vm/as.h> 377c478bd9Sstevel@tonic-gate #include <vm/hat.h> 387c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 397c478bd9Sstevel@tonic-gate #include <sys/avintr.h> 407c478bd9Sstevel@tonic-gate #include <sys/vtrace.h> 417c478bd9Sstevel@tonic-gate #include <sys/proc.h> 427c478bd9Sstevel@tonic-gate #include <sys/thread.h> 437c478bd9Sstevel@tonic-gate #include <sys/cpupart.h> 447c478bd9Sstevel@tonic-gate #include <sys/pset.h> 457c478bd9Sstevel@tonic-gate #include <sys/copyops.h> 46fb2f18f8Sesaxe #include <sys/pg.h> 477c478bd9Sstevel@tonic-gate #include <sys/disp.h> 487c478bd9Sstevel@tonic-gate #include <sys/debug.h> 497c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 507c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h> 517c478bd9Sstevel@tonic-gate #include <sys/privregs.h> 527c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 537c478bd9Sstevel@tonic-gate #include <sys/ontrap.h> 547c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 559db7147eSSherry Moore #include <sys/boot_console.h> 56ae115bc7Smrj #include <sys/kdi_machimpl.h> 577c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 587c478bd9Sstevel@tonic-gate #include <sys/promif.h> 59c88420b3Sdmick #include <sys/pci_cfgspace.h> 60843e1988Sjohnlev #ifdef __xpv 61843e1988Sjohnlev #include <sys/hypervisor.h> 62349b53ddSStuart Maybee #else 63349b53ddSStuart Maybee #include <sys/xpv_support.h> 64843e1988Sjohnlev #endif 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * some globals for patching the result of cpuid 687c478bd9Sstevel@tonic-gate * to solve problems w/ creative cpu vendors 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include; 727c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude; 737c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include; 747c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* 774961a633Sdmick * Dummy spl priority masks 784961a633Sdmick */ 794961a633Sdmick static unsigned char dummy_cpu_pri[MAXIPL + 1] = { 804961a633Sdmick 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 814961a633Sdmick 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf, 0xf 824961a633Sdmick }; 834961a633Sdmick 849db7147eSSherry Moore /* 859db7147eSSherry Moore * Set console mode 869db7147eSSherry Moore */ 879db7147eSSherry Moore static void 889db7147eSSherry Moore set_console_mode(uint8_t val) 899db7147eSSherry Moore { 909db7147eSSherry Moore struct bop_regs rp = {0}; 919db7147eSSherry Moore 929db7147eSSherry Moore rp.eax.byte.ah = 0x0; 939db7147eSSherry Moore rp.eax.byte.al = val; 949db7147eSSherry Moore rp.ebx.word.bx = 0x0; 959db7147eSSherry Moore 969db7147eSSherry Moore BOP_DOINT(bootops, 0x10, &rp); 979db7147eSSherry Moore } 989db7147eSSherry Moore 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 1027c478bd9Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 1037c478bd9Sstevel@tonic-gate */ 1047c478bd9Sstevel@tonic-gate void 1057c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp) 1067c478bd9Sstevel@tonic-gate { 1072baa66a0SJonathan Chew u_longlong_t prop_value; 1087c478bd9Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1097c478bd9Sstevel@tonic-gate extern disp_t cpu0_disp; 1107c478bd9Sstevel@tonic-gate extern char t0stack[]; 1119db7147eSSherry Moore extern int post_fastreboot; 1129db7147eSSherry Moore extern int console; 113a3114836SGerry Liu extern uint64_t plat_dr_options; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * initialize cpu_self 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate cpu[0]->cpu_self = cpu[0]; 1217c478bd9Sstevel@tonic-gate 122843e1988Sjohnlev #if defined(__xpv) 123843e1988Sjohnlev /* 124843e1988Sjohnlev * Point at the hypervisor's virtual cpu structure 125843e1988Sjohnlev */ 126843e1988Sjohnlev cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0]; 127843e1988Sjohnlev #endif 128843e1988Sjohnlev 1297c478bd9Sstevel@tonic-gate /* 1304961a633Sdmick * Set up dummy cpu_pri_data values till psm spl code is 1314961a633Sdmick * installed. This allows splx() to work on amd64. 1324961a633Sdmick */ 1334961a633Sdmick 1344961a633Sdmick cpu[0]->cpu_pri_data = dummy_cpu_pri; 1354961a633Sdmick 1364961a633Sdmick /* 1377c478bd9Sstevel@tonic-gate * check if we've got special bits to clear or set 1387c478bd9Sstevel@tonic-gate * when checking cpu features 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate 1412baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_ecx_include", &prop_value) != 0) 1422baa66a0SJonathan Chew cpuid_feature_ecx_include = 0; 1432baa66a0SJonathan Chew else 1442baa66a0SJonathan Chew cpuid_feature_ecx_include = (uint32_t)prop_value; 1452baa66a0SJonathan Chew 1462baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0) 1472baa66a0SJonathan Chew cpuid_feature_ecx_exclude = 0; 1482baa66a0SJonathan Chew else 1492baa66a0SJonathan Chew cpuid_feature_ecx_exclude = (uint32_t)prop_value; 1502baa66a0SJonathan Chew 1512baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0) 1522baa66a0SJonathan Chew cpuid_feature_edx_include = 0; 1532baa66a0SJonathan Chew else 1542baa66a0SJonathan Chew cpuid_feature_edx_include = (uint32_t)prop_value; 1552baa66a0SJonathan Chew 1562baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0) 1572baa66a0SJonathan Chew cpuid_feature_edx_exclude = 0; 1582baa66a0SJonathan Chew else 1592baa66a0SJonathan Chew cpuid_feature_edx_exclude = (uint32_t)prop_value; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate /* 16245e032f7SDan Mick * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss. 16345e032f7SDan Mick */ 16445e032f7SDan Mick init_desctbls(); 16545e032f7SDan Mick 16645e032f7SDan Mick /* 16745e032f7SDan Mick * lgrp_init() and possibly cpuid_pass1() need PCI config 16845e032f7SDan Mick * space access 16945e032f7SDan Mick */ 17045e032f7SDan Mick #if defined(__xpv) 17145e032f7SDan Mick if (DOMAIN_IS_INITDOMAIN(xen_info)) 17245e032f7SDan Mick pci_cfgspace_init(); 17345e032f7SDan Mick #else 17445e032f7SDan Mick pci_cfgspace_init(); 17545e032f7SDan Mick #endif 17645e032f7SDan Mick 17745e032f7SDan Mick /* 1787c478bd9Sstevel@tonic-gate * The first lightweight pass (pass0) through the cpuid data 1797c478bd9Sstevel@tonic-gate * was done in locore before mlsetup was called. Do the next 1807c478bd9Sstevel@tonic-gate * pass in C code. 1817c478bd9Sstevel@tonic-gate * 1827417cfdeSKuriakose Kuruvilla * The x86_featureset is initialized here based on the capabilities 1837c478bd9Sstevel@tonic-gate * of the boot CPU. Note that if we choose to support CPUs that have 1847c478bd9Sstevel@tonic-gate * different feature sets (at which point we would almost certainly 1857c478bd9Sstevel@tonic-gate * want to set the feature bits to correspond to the feature 1867c478bd9Sstevel@tonic-gate * minimum) this value may be altered. 1877c478bd9Sstevel@tonic-gate */ 188*dfea898aSKuriakose Kuruvilla cpuid_pass1(cpu[0], x86_featureset); 1897c478bd9Sstevel@tonic-gate 190247dbb3dSsudheer #if !defined(__xpv) 191247dbb3dSsudheer 192349b53ddSStuart Maybee if (get_hwenv() == HW_XEN_HVM) 193349b53ddSStuart Maybee xen_hvm_init(); 194349b53ddSStuart Maybee 195247dbb3dSsudheer /* 196247dbb3dSsudheer * Patch the tsc_read routine with appropriate set of instructions, 197247dbb3dSsudheer * depending on the processor family and architecure, to read the 198247dbb3dSsudheer * time-stamp counter while ensuring no out-of-order execution. 199247dbb3dSsudheer * Patch it while the kernel text is still writable. 200247dbb3dSsudheer * 201247dbb3dSsudheer * Note: tsc_read is not patched for intel processors whose family 202247dbb3dSsudheer * is >6 and for amd whose family >f (in case they don't support rdtscp 203247dbb3dSsudheer * instruction, unlikely). By default tsc_read will use cpuid for 204247dbb3dSsudheer * serialization in such cases. The following code needs to be 205247dbb3dSsudheer * revisited if intel processors of family >= f retains the 206247dbb3dSsudheer * instruction serialization nature of mfence instruction. 2072b0bcb26Ssudheer * Note: tsc_read is not patched for x86 processors which do 2082b0bcb26Ssudheer * not support "mfence". By default tsc_read will use cpuid for 2092b0bcb26Ssudheer * serialization in such cases. 210551bc2a6Smrj * 211551bc2a6Smrj * The Xen hypervisor does not correctly report whether rdtscp is 212551bc2a6Smrj * supported or not, so we must assume that it is not. 213247dbb3dSsudheer */ 2147417cfdeSKuriakose Kuruvilla if (get_hwenv() != HW_XEN_HVM && 2157417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_TSCP)) 216247dbb3dSsudheer patch_tsc_read(X86_HAVE_TSCP); 217247dbb3dSsudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_AMD && 2187417cfdeSKuriakose Kuruvilla cpuid_getfamily(CPU) <= 0xf && 2197417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_SSE2)) 220247dbb3dSsudheer patch_tsc_read(X86_TSC_MFENCE); 221247dbb3dSsudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_Intel && 2227417cfdeSKuriakose Kuruvilla cpuid_getfamily(CPU) <= 6 && 2237417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_SSE2)) 22415363b27Ssudheer patch_tsc_read(X86_TSC_LFENCE); 225247dbb3dSsudheer 226247dbb3dSsudheer #endif /* !__xpv */ 2277c478bd9Sstevel@tonic-gate 228843e1988Sjohnlev #if defined(__i386) && !defined(__xpv) 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * Some i386 processors do not implement the rdtsc instruction, 231247dbb3dSsudheer * or at least they do not implement it correctly. Patch them to 232247dbb3dSsudheer * return 0. 2337c478bd9Sstevel@tonic-gate */ 2347417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_TSC)) 235247dbb3dSsudheer patch_tsc_read(X86_NO_TSC); 236843e1988Sjohnlev #endif /* __i386 && !__xpv */ 237843e1988Sjohnlev 23822cc0e45SBill Holler #if defined(__amd64) && !defined(__xpv) 23922cc0e45SBill Holler patch_memops(cpuid_getvendor(CPU)); 24022cc0e45SBill Holler #endif /* __amd64 && !__xpv */ 24122cc0e45SBill Holler 242843e1988Sjohnlev #if !defined(__xpv) 243843e1988Sjohnlev /* XXPV what, if anything, should be dorked with here under xen? */ 244ae115bc7Smrj 245ae115bc7Smrj /* 246ae115bc7Smrj * While we're thinking about the TSC, let's set up %cr4 so that 247ae115bc7Smrj * userland can issue rdtsc, and initialize the TSC_AUX value 248ae115bc7Smrj * (the cpuid) for the rdtscp instruction on appropriately 249ae115bc7Smrj * capable hardware. 250ae115bc7Smrj */ 2517417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_TSC)) 252ae115bc7Smrj setcr4(getcr4() & ~CR4_TSD); 253ae115bc7Smrj 2547417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_TSCP)) 255ae115bc7Smrj (void) wrmsr(MSR_AMD_TSCAUX, 0); 256ae115bc7Smrj 2577417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_DE)) 258ae115bc7Smrj setcr4(getcr4() | CR4_DE); 259843e1988Sjohnlev #endif /* __xpv */ 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* 2627c478bd9Sstevel@tonic-gate * initialize t0 2637c478bd9Sstevel@tonic-gate */ 2647c478bd9Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - MINFRAME; 2657c478bd9Sstevel@tonic-gate t0.t_stkbase = t0stack; 2667c478bd9Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 2677c478bd9Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 2687c478bd9Sstevel@tonic-gate t0.t_procp = &p0; 2697c478bd9Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 2707c478bd9Sstevel@tonic-gate t0.t_lwp = &lwp0; 2717c478bd9Sstevel@tonic-gate t0.t_forw = &t0; 2727c478bd9Sstevel@tonic-gate t0.t_back = &t0; 2737c478bd9Sstevel@tonic-gate t0.t_next = &t0; 2747c478bd9Sstevel@tonic-gate t0.t_prev = &t0; 2757c478bd9Sstevel@tonic-gate t0.t_cpu = cpu[0]; 2767c478bd9Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 2777c478bd9Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 2787c478bd9Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 2790b70c467Sakolb t0.t_bindflag = (uchar_t)default_binding_mode; 2807c478bd9Sstevel@tonic-gate t0.t_cpupart = &cp_default; 2817c478bd9Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 2827c478bd9Sstevel@tonic-gate t0.t_copyops = NULL; 2837c478bd9Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate lwp0.lwp_thread = &t0; 2867c478bd9Sstevel@tonic-gate lwp0.lwp_regs = (void *)rp; 2877c478bd9Sstevel@tonic-gate lwp0.lwp_procp = &p0; 2887c478bd9Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate p0.p_exec = NULL; 2917c478bd9Sstevel@tonic-gate p0.p_stat = SRUN; 2927c478bd9Sstevel@tonic-gate p0.p_flag = SSYS; 2937c478bd9Sstevel@tonic-gate p0.p_tlist = &t0; 2947c478bd9Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 2957c478bd9Sstevel@tonic-gate p0.p_stkpageszc = 0; 2967c478bd9Sstevel@tonic-gate p0.p_as = &kas; 2977c478bd9Sstevel@tonic-gate p0.p_lockp = &p0lock; 2987c478bd9Sstevel@tonic-gate p0.p_brkpageszc = 0; 2992cb27123Saguzovsk p0.p_t1_lgrpid = LGRP_NONE; 3002cb27123Saguzovsk p0.p_tr_lgrpid = LGRP_NONE; 3017c478bd9Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate CPU->cpu_thread = &t0; 3047c478bd9Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 3057c478bd9Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 3067c478bd9Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 3077c478bd9Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 3087c478bd9Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 3097c478bd9Sstevel@tonic-gate CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE; 3107c478bd9Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate CPU->cpu_id = 0; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate CPU->cpu_pri = 12; /* initial PIL for the boot CPU */ 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate /* 3170baeff3dSrab * The kernel doesn't use LDTs unless a process explicitly requests one. 3187c478bd9Sstevel@tonic-gate */ 319843e1988Sjohnlev p0.p_ldt_desc = null_sdesc; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate /* 322ae115bc7Smrj * Initialize thread/cpu microstate accounting 3237c478bd9Sstevel@tonic-gate */ 3247c478bd9Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 3257c478bd9Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate /* 3287c478bd9Sstevel@tonic-gate * Initialize lists of available and active CPUs. 3297c478bd9Sstevel@tonic-gate */ 3307c478bd9Sstevel@tonic-gate cpu_list_init(CPU); 3317c478bd9Sstevel@tonic-gate 3320e751525SEric Saxe pg_cpu_bootstrap(CPU); 3330e751525SEric Saxe 334ae115bc7Smrj /* 335ae115bc7Smrj * Now that we have taken over the GDT, IDT and have initialized 336ae115bc7Smrj * active CPU list it's time to inform kmdb if present. 337ae115bc7Smrj */ 338ae115bc7Smrj if (boothowto & RB_DEBUG) 339ae115bc7Smrj kdi_idt_sync(); 340ae115bc7Smrj 341ae115bc7Smrj /* 3429db7147eSSherry Moore * Explicitly set console to text mode (0x3) if this is a boot 3439db7147eSSherry Moore * post Fast Reboot, and the console is set to CONS_SCREEN_TEXT. 3449db7147eSSherry Moore */ 3459db7147eSSherry Moore if (post_fastreboot && console == CONS_SCREEN_TEXT) 3469db7147eSSherry Moore set_console_mode(0x3); 3479db7147eSSherry Moore 3489db7147eSSherry Moore /* 349ae115bc7Smrj * If requested (boot -d) drop into kmdb. 350ae115bc7Smrj * 351ae115bc7Smrj * This must be done after cpu_list_init() on the 64-bit kernel 352ae115bc7Smrj * since taking a trap requires that we re-compute gsbase based 353ae115bc7Smrj * on the cpu list. 354ae115bc7Smrj */ 355ae115bc7Smrj if (boothowto & RB_DEBUGENTER) 356ae115bc7Smrj kmdb_enter(); 357ae115bc7Smrj 358affbd3ccSkchow cpu_vm_data_init(CPU); 359affbd3ccSkchow 3607c478bd9Sstevel@tonic-gate rp->r_fp = 0; /* terminate kernel stack traces! */ 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate prom_init("kernel", (void *)NULL); 3637c478bd9Sstevel@tonic-gate 364a3114836SGerry Liu /* User-set option overrides firmware value. */ 365a3114836SGerry Liu if (bootprop_getval(PLAT_DR_OPTIONS_NAME, &prop_value) == 0) { 366a3114836SGerry Liu plat_dr_options = (uint64_t)prop_value; 367a3114836SGerry Liu } 368a3114836SGerry Liu #if defined(__xpv) 369a3114836SGerry Liu /* No support of DR operations on xpv */ 370a3114836SGerry Liu plat_dr_options = 0; 371a3114836SGerry Liu #else /* __xpv */ 372a3114836SGerry Liu /* Flag PLAT_DR_FEATURE_ENABLED should only be set by DR driver. */ 373a3114836SGerry Liu plat_dr_options &= ~PLAT_DR_FEATURE_ENABLED; 374a3114836SGerry Liu #ifndef __amd64 375a3114836SGerry Liu /* Only enable CPU/memory DR on 64 bits kernel. */ 376a3114836SGerry Liu plat_dr_options &= ~PLAT_DR_FEATURE_MEMORY; 377a3114836SGerry Liu plat_dr_options &= ~PLAT_DR_FEATURE_CPU; 378a3114836SGerry Liu #endif /* __amd64 */ 379a3114836SGerry Liu #endif /* __xpv */ 380a3114836SGerry Liu 381a3114836SGerry Liu /* 382a3114836SGerry Liu * Get value of "plat_dr_physmax" boot option. 383a3114836SGerry Liu * It overrides values calculated from MSCT or SRAT table. 384a3114836SGerry Liu */ 385a3114836SGerry Liu if (bootprop_getval(PLAT_DR_PHYSMAX_NAME, &prop_value) == 0) { 386a3114836SGerry Liu plat_dr_physmax = ((uint64_t)prop_value) >> PAGESHIFT; 387a3114836SGerry Liu } 388a3114836SGerry Liu 389a3114836SGerry Liu /* Get value of boot_ncpus. */ 390a3114836SGerry Liu if (bootprop_getval(BOOT_NCPUS_NAME, &prop_value) != 0) { 3912baa66a0SJonathan Chew boot_ncpus = NCPU; 392a3114836SGerry Liu } else { 3932baa66a0SJonathan Chew boot_ncpus = (int)prop_value; 39441791439Sandrei if (boot_ncpus <= 0 || boot_ncpus > NCPU) 395ae115bc7Smrj boot_ncpus = NCPU; 3962baa66a0SJonathan Chew } 39741791439Sandrei 398a3114836SGerry Liu /* 399a3114836SGerry Liu * Set max_ncpus and boot_max_ncpus to boot_ncpus if platform doesn't 400a3114836SGerry Liu * support CPU DR operations. 401a3114836SGerry Liu */ 402a3114836SGerry Liu if (plat_dr_support_cpu() == 0) { 40341791439Sandrei max_ncpus = boot_max_ncpus = boot_ncpus; 404a3114836SGerry Liu } else { 405a3114836SGerry Liu if (bootprop_getval(PLAT_MAX_NCPUS_NAME, &prop_value) != 0) { 406a3114836SGerry Liu max_ncpus = NCPU; 407a3114836SGerry Liu } else { 408a3114836SGerry Liu max_ncpus = (int)prop_value; 409a3114836SGerry Liu if (max_ncpus <= 0 || max_ncpus > NCPU) { 410a3114836SGerry Liu max_ncpus = NCPU; 411a3114836SGerry Liu } 412a3114836SGerry Liu if (boot_ncpus > max_ncpus) { 413a3114836SGerry Liu boot_ncpus = max_ncpus; 414a3114836SGerry Liu } 415a3114836SGerry Liu } 416a3114836SGerry Liu 417a3114836SGerry Liu if (bootprop_getval(BOOT_MAX_NCPUS_NAME, &prop_value) != 0) { 418a3114836SGerry Liu boot_max_ncpus = boot_ncpus; 419a3114836SGerry Liu } else { 420a3114836SGerry Liu boot_max_ncpus = (int)prop_value; 421a3114836SGerry Liu if (boot_max_ncpus <= 0 || boot_max_ncpus > NCPU) { 422a3114836SGerry Liu boot_max_ncpus = boot_ncpus; 423a3114836SGerry Liu } else if (boot_max_ncpus > max_ncpus) { 424a3114836SGerry Liu boot_max_ncpus = max_ncpus; 425a3114836SGerry Liu } 426a3114836SGerry Liu } 427a3114836SGerry Liu } 42841791439Sandrei 4292e2c009bSjjc /* 4302e2c009bSjjc * Initialize the lgrp framework 4312e2c009bSjjc */ 432d5d7cf4eSJonathan Chew lgrp_init(LGRP_INIT_STAGE1); 4332e2c009bSjjc 4347c478bd9Sstevel@tonic-gate if (boothowto & RB_HALT) { 4357c478bd9Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 4367c478bd9Sstevel@tonic-gate prom_enter_mon(); 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate 4397c478bd9Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 4407c478bd9Sstevel@tonic-gate 4412449e17fSsherrym /* 4422449e17fSsherrym * Fill out cpu_ucode_info. Update microcode if necessary. 4432449e17fSsherrym */ 4442449e17fSsherrym ucode_check(CPU); 4452449e17fSsherrym 4467c478bd9Sstevel@tonic-gate if (workaround_errata(CPU) != 0) 4477c478bd9Sstevel@tonic-gate panic("critical workaround(s) missing for boot cpu"); 4487c478bd9Sstevel@tonic-gate } 449986fd29aSsetje 450986fd29aSsetje 451986fd29aSsetje void 452986fd29aSsetje mach_modpath(char *path, const char *filename) 453986fd29aSsetje { 454986fd29aSsetje /* 455986fd29aSsetje * Construct the directory path from the filename. 456986fd29aSsetje */ 457986fd29aSsetje 458986fd29aSsetje int len; 459986fd29aSsetje char *p; 460986fd29aSsetje const char isastr[] = "/amd64"; 461986fd29aSsetje size_t isalen = strlen(isastr); 462986fd29aSsetje 463986fd29aSsetje if ((p = strrchr(filename, '/')) == NULL) 464986fd29aSsetje return; 465986fd29aSsetje 466986fd29aSsetje while (p > filename && *(p - 1) == '/') 467986fd29aSsetje p--; /* remove trailing '/' characters */ 468986fd29aSsetje if (p == filename) 469986fd29aSsetje p++; /* so "/" -is- the modpath in this case */ 470986fd29aSsetje 471986fd29aSsetje /* 472986fd29aSsetje * Remove optional isa-dependent directory name - the module 473986fd29aSsetje * subsystem will put this back again (!) 474986fd29aSsetje */ 475986fd29aSsetje len = p - filename; 476986fd29aSsetje if (len > isalen && 477986fd29aSsetje strncmp(&filename[len - isalen], isastr, isalen) == 0) 478986fd29aSsetje p -= isalen; 479986fd29aSsetje 480986fd29aSsetje /* 481986fd29aSsetje * "/platform/mumblefrotz" + " " + MOD_DEFPATH 482986fd29aSsetje */ 483986fd29aSsetje len += (p - filename) + 1 + strlen(MOD_DEFPATH) + 1; 484986fd29aSsetje (void) strncpy(path, filename, p - filename); 485986fd29aSsetje } 486