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 /* 220d928757SGary Mills * Copyright (c) 2012 Gary Mills 230d928757SGary Mills * 247417cfdeSKuriakose Kuruvilla * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved. 25cfe84b82SMatt Amdur * Copyright (c) 2011 by Delphix. All rights reserved. 267c478bd9Sstevel@tonic-gate */ 27a3114836SGerry Liu /* 28a3114836SGerry Liu * Copyright (c) 2010, Intel Corporation. 29a3114836SGerry Liu * All rights reserved. 30a3114836SGerry Liu */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 33ae115bc7Smrj #include <sys/sysmacros.h> 347c478bd9Sstevel@tonic-gate #include <sys/disp.h> 357c478bd9Sstevel@tonic-gate #include <sys/promif.h> 367c478bd9Sstevel@tonic-gate #include <sys/clock.h> 377c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 387c478bd9Sstevel@tonic-gate #include <sys/stack.h> 397c478bd9Sstevel@tonic-gate #include <vm/as.h> 407c478bd9Sstevel@tonic-gate #include <vm/hat.h> 417c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 427c478bd9Sstevel@tonic-gate #include <sys/avintr.h> 437c478bd9Sstevel@tonic-gate #include <sys/vtrace.h> 447c478bd9Sstevel@tonic-gate #include <sys/proc.h> 457c478bd9Sstevel@tonic-gate #include <sys/thread.h> 467c478bd9Sstevel@tonic-gate #include <sys/cpupart.h> 477c478bd9Sstevel@tonic-gate #include <sys/pset.h> 487c478bd9Sstevel@tonic-gate #include <sys/copyops.h> 49fb2f18f8Sesaxe #include <sys/pg.h> 507c478bd9Sstevel@tonic-gate #include <sys/disp.h> 517c478bd9Sstevel@tonic-gate #include <sys/debug.h> 527c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 537c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h> 547c478bd9Sstevel@tonic-gate #include <sys/privregs.h> 557c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 567c478bd9Sstevel@tonic-gate #include <sys/ontrap.h> 577c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 589db7147eSSherry Moore #include <sys/boot_console.h> 59ae115bc7Smrj #include <sys/kdi_machimpl.h> 607c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 617c478bd9Sstevel@tonic-gate #include <sys/promif.h> 62c88420b3Sdmick #include <sys/pci_cfgspace.h> 63*0181461bSKeith M Wesolowski #include <sys/bootvfs.h> 64843e1988Sjohnlev #ifdef __xpv 65843e1988Sjohnlev #include <sys/hypervisor.h> 66349b53ddSStuart Maybee #else 67349b53ddSStuart Maybee #include <sys/xpv_support.h> 68843e1988Sjohnlev #endif 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * some globals for patching the result of cpuid 727c478bd9Sstevel@tonic-gate * to solve problems w/ creative cpu vendors 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_include; 767c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_ecx_exclude; 777c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_include; 787c478bd9Sstevel@tonic-gate extern uint32_t cpuid_feature_edx_exclude; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 819db7147eSSherry Moore * Set console mode 829db7147eSSherry Moore */ 839db7147eSSherry Moore static void 849db7147eSSherry Moore set_console_mode(uint8_t val) 859db7147eSSherry Moore { 869db7147eSSherry Moore struct bop_regs rp = {0}; 879db7147eSSherry Moore 889db7147eSSherry Moore rp.eax.byte.ah = 0x0; 899db7147eSSherry Moore rp.eax.byte.al = val; 909db7147eSSherry Moore rp.ebx.word.bx = 0x0; 919db7147eSSherry Moore 929db7147eSSherry Moore BOP_DOINT(bootops, 0x10, &rp); 939db7147eSSherry Moore } 949db7147eSSherry Moore 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 987c478bd9Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate void 1017c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp) 1027c478bd9Sstevel@tonic-gate { 1032baa66a0SJonathan Chew u_longlong_t prop_value; 1047c478bd9Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1057c478bd9Sstevel@tonic-gate extern disp_t cpu0_disp; 1067c478bd9Sstevel@tonic-gate extern char t0stack[]; 1079db7147eSSherry Moore extern int post_fastreboot; 108a3114836SGerry Liu extern uint64_t plat_dr_options; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * initialize cpu_self 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate cpu[0]->cpu_self = cpu[0]; 1167c478bd9Sstevel@tonic-gate 117843e1988Sjohnlev #if defined(__xpv) 118843e1988Sjohnlev /* 119843e1988Sjohnlev * Point at the hypervisor's virtual cpu structure 120843e1988Sjohnlev */ 121843e1988Sjohnlev cpu[0]->cpu_m.mcpu_vcpu_info = &HYPERVISOR_shared_info->vcpu_info[0]; 122843e1988Sjohnlev #endif 123843e1988Sjohnlev 1247c478bd9Sstevel@tonic-gate /* 1257c478bd9Sstevel@tonic-gate * check if we've got special bits to clear or set 1267c478bd9Sstevel@tonic-gate * when checking cpu features 1277c478bd9Sstevel@tonic-gate */ 1287c478bd9Sstevel@tonic-gate 1292baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_ecx_include", &prop_value) != 0) 1302baa66a0SJonathan Chew cpuid_feature_ecx_include = 0; 1312baa66a0SJonathan Chew else 1322baa66a0SJonathan Chew cpuid_feature_ecx_include = (uint32_t)prop_value; 1332baa66a0SJonathan Chew 1342baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_ecx_exclude", &prop_value) != 0) 1352baa66a0SJonathan Chew cpuid_feature_ecx_exclude = 0; 1362baa66a0SJonathan Chew else 1372baa66a0SJonathan Chew cpuid_feature_ecx_exclude = (uint32_t)prop_value; 1382baa66a0SJonathan Chew 1392baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_edx_include", &prop_value) != 0) 1402baa66a0SJonathan Chew cpuid_feature_edx_include = 0; 1412baa66a0SJonathan Chew else 1422baa66a0SJonathan Chew cpuid_feature_edx_include = (uint32_t)prop_value; 1432baa66a0SJonathan Chew 1442baa66a0SJonathan Chew if (bootprop_getval("cpuid_feature_edx_exclude", &prop_value) != 0) 1452baa66a0SJonathan Chew cpuid_feature_edx_exclude = 0; 1462baa66a0SJonathan Chew else 1472baa66a0SJonathan Chew cpuid_feature_edx_exclude = (uint32_t)prop_value; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 15045e032f7SDan Mick * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss. 15145e032f7SDan Mick */ 15245e032f7SDan Mick init_desctbls(); 15345e032f7SDan Mick 15445e032f7SDan Mick /* 15545e032f7SDan Mick * lgrp_init() and possibly cpuid_pass1() need PCI config 15645e032f7SDan Mick * space access 15745e032f7SDan Mick */ 15845e032f7SDan Mick #if defined(__xpv) 15945e032f7SDan Mick if (DOMAIN_IS_INITDOMAIN(xen_info)) 16045e032f7SDan Mick pci_cfgspace_init(); 16145e032f7SDan Mick #else 16245e032f7SDan Mick pci_cfgspace_init(); 163cfe84b82SMatt Amdur /* 164cfe84b82SMatt Amdur * Initialize the platform type from CPU 0 to ensure that 165cfe84b82SMatt Amdur * determine_platform() is only ever called once. 166cfe84b82SMatt Amdur */ 167cfe84b82SMatt Amdur determine_platform(); 16845e032f7SDan Mick #endif 16945e032f7SDan Mick 17045e032f7SDan Mick /* 1717c478bd9Sstevel@tonic-gate * The first lightweight pass (pass0) through the cpuid data 1727c478bd9Sstevel@tonic-gate * was done in locore before mlsetup was called. Do the next 1737c478bd9Sstevel@tonic-gate * pass in C code. 1747c478bd9Sstevel@tonic-gate * 1757417cfdeSKuriakose Kuruvilla * The x86_featureset is initialized here based on the capabilities 1767c478bd9Sstevel@tonic-gate * of the boot CPU. Note that if we choose to support CPUs that have 1777c478bd9Sstevel@tonic-gate * different feature sets (at which point we would almost certainly 1787c478bd9Sstevel@tonic-gate * want to set the feature bits to correspond to the feature 1797c478bd9Sstevel@tonic-gate * minimum) this value may be altered. 1807c478bd9Sstevel@tonic-gate */ 181dfea898aSKuriakose Kuruvilla cpuid_pass1(cpu[0], x86_featureset); 1827c478bd9Sstevel@tonic-gate 183247dbb3dSsudheer #if !defined(__xpv) 18479ec9da8SYuri Pankov if ((get_hwenv() & HW_XEN_HVM) != 0) 185349b53ddSStuart Maybee xen_hvm_init(); 186349b53ddSStuart Maybee 187247dbb3dSsudheer /* 1884948216cSKeith M Wesolowski * Before we do anything with the TSCs, we need to work around 1894948216cSKeith M Wesolowski * Intel erratum BT81. On some CPUs, warm reset does not 1904948216cSKeith M Wesolowski * clear the TSC. If we are on such a CPU, we will clear TSC ourselves 1914948216cSKeith M Wesolowski * here. Other CPUs will clear it when we boot them later, and the 1924948216cSKeith M Wesolowski * resulting skew will be handled by tsc_sync_master()/_slave(); 1934948216cSKeith M Wesolowski * note that such skew already exists and has to be handled anyway. 1944948216cSKeith M Wesolowski * 1954948216cSKeith M Wesolowski * We do this only on metal. This same problem can occur with a 1964948216cSKeith M Wesolowski * hypervisor that does not happen to virtualise a TSC that starts from 1974948216cSKeith M Wesolowski * zero, regardless of CPU type; however, we do not expect hypervisors 1984948216cSKeith M Wesolowski * that do not virtualise TSC that way to handle writes to TSC 1994948216cSKeith M Wesolowski * correctly, either. 2004948216cSKeith M Wesolowski */ 2014948216cSKeith M Wesolowski if (get_hwenv() == HW_NATIVE && 2024948216cSKeith M Wesolowski cpuid_getvendor(CPU) == X86_VENDOR_Intel && 2034948216cSKeith M Wesolowski cpuid_getfamily(CPU) == 6 && 2044948216cSKeith M Wesolowski (cpuid_getmodel(CPU) == 0x2d || cpuid_getmodel(CPU) == 0x3e) && 2054948216cSKeith M Wesolowski is_x86_feature(x86_featureset, X86FSET_TSC)) { 2064948216cSKeith M Wesolowski (void) wrmsr(REG_TSC, 0UL); 2074948216cSKeith M Wesolowski } 2084948216cSKeith M Wesolowski 2094948216cSKeith M Wesolowski /* 210247dbb3dSsudheer * Patch the tsc_read routine with appropriate set of instructions, 211247dbb3dSsudheer * depending on the processor family and architecure, to read the 212247dbb3dSsudheer * time-stamp counter while ensuring no out-of-order execution. 213247dbb3dSsudheer * Patch it while the kernel text is still writable. 214247dbb3dSsudheer * 215247dbb3dSsudheer * Note: tsc_read is not patched for intel processors whose family 216247dbb3dSsudheer * is >6 and for amd whose family >f (in case they don't support rdtscp 217247dbb3dSsudheer * instruction, unlikely). By default tsc_read will use cpuid for 218247dbb3dSsudheer * serialization in such cases. The following code needs to be 219247dbb3dSsudheer * revisited if intel processors of family >= f retains the 220247dbb3dSsudheer * instruction serialization nature of mfence instruction. 2212b0bcb26Ssudheer * Note: tsc_read is not patched for x86 processors which do 2222b0bcb26Ssudheer * not support "mfence". By default tsc_read will use cpuid for 2232b0bcb26Ssudheer * serialization in such cases. 224551bc2a6Smrj * 225551bc2a6Smrj * The Xen hypervisor does not correctly report whether rdtscp is 226551bc2a6Smrj * supported or not, so we must assume that it is not. 227247dbb3dSsudheer */ 22879ec9da8SYuri Pankov if ((get_hwenv() & HW_XEN_HVM) == 0 && 2297417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_TSCP)) 230247dbb3dSsudheer patch_tsc_read(X86_HAVE_TSCP); 231247dbb3dSsudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_AMD && 2327417cfdeSKuriakose Kuruvilla cpuid_getfamily(CPU) <= 0xf && 2337417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_SSE2)) 234247dbb3dSsudheer patch_tsc_read(X86_TSC_MFENCE); 235247dbb3dSsudheer else if (cpuid_getvendor(CPU) == X86_VENDOR_Intel && 2367417cfdeSKuriakose Kuruvilla cpuid_getfamily(CPU) <= 6 && 2377417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_SSE2)) 23815363b27Ssudheer patch_tsc_read(X86_TSC_LFENCE); 239247dbb3dSsudheer 240247dbb3dSsudheer #endif /* !__xpv */ 2417c478bd9Sstevel@tonic-gate 242843e1988Sjohnlev #if defined(__i386) && !defined(__xpv) 2437c478bd9Sstevel@tonic-gate /* 2447c478bd9Sstevel@tonic-gate * Some i386 processors do not implement the rdtsc instruction, 245247dbb3dSsudheer * or at least they do not implement it correctly. Patch them to 246247dbb3dSsudheer * return 0. 2477c478bd9Sstevel@tonic-gate */ 2487417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_TSC)) 249247dbb3dSsudheer patch_tsc_read(X86_NO_TSC); 250843e1988Sjohnlev #endif /* __i386 && !__xpv */ 251843e1988Sjohnlev 25222cc0e45SBill Holler #if defined(__amd64) && !defined(__xpv) 25322cc0e45SBill Holler patch_memops(cpuid_getvendor(CPU)); 25422cc0e45SBill Holler #endif /* __amd64 && !__xpv */ 25522cc0e45SBill Holler 256843e1988Sjohnlev #if !defined(__xpv) 257843e1988Sjohnlev /* XXPV what, if anything, should be dorked with here under xen? */ 258ae115bc7Smrj 259ae115bc7Smrj /* 260ae115bc7Smrj * While we're thinking about the TSC, let's set up %cr4 so that 261ae115bc7Smrj * userland can issue rdtsc, and initialize the TSC_AUX value 262ae115bc7Smrj * (the cpuid) for the rdtscp instruction on appropriately 263ae115bc7Smrj * capable hardware. 264ae115bc7Smrj */ 2657417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_TSC)) 266ae115bc7Smrj setcr4(getcr4() & ~CR4_TSD); 267ae115bc7Smrj 2687417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_TSCP)) 269ae115bc7Smrj (void) wrmsr(MSR_AMD_TSCAUX, 0); 270ae115bc7Smrj 271799823bbSRobert Mustacchi /* 272799823bbSRobert Mustacchi * Let's get the other %cr4 stuff while we're here. 273799823bbSRobert Mustacchi */ 2747417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_DE)) 275ae115bc7Smrj setcr4(getcr4() | CR4_DE); 276799823bbSRobert Mustacchi 277799823bbSRobert Mustacchi if (is_x86_feature(x86_featureset, X86FSET_SMEP)) 278799823bbSRobert Mustacchi setcr4(getcr4() | CR4_SMEP); 279843e1988Sjohnlev #endif /* __xpv */ 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate /* 2827c478bd9Sstevel@tonic-gate * initialize t0 2837c478bd9Sstevel@tonic-gate */ 2847c478bd9Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - MINFRAME; 2857c478bd9Sstevel@tonic-gate t0.t_stkbase = t0stack; 2867c478bd9Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 2877c478bd9Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 2887c478bd9Sstevel@tonic-gate t0.t_procp = &p0; 2897c478bd9Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 2907c478bd9Sstevel@tonic-gate t0.t_lwp = &lwp0; 2917c478bd9Sstevel@tonic-gate t0.t_forw = &t0; 2927c478bd9Sstevel@tonic-gate t0.t_back = &t0; 2937c478bd9Sstevel@tonic-gate t0.t_next = &t0; 2947c478bd9Sstevel@tonic-gate t0.t_prev = &t0; 2957c478bd9Sstevel@tonic-gate t0.t_cpu = cpu[0]; 2967c478bd9Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 2977c478bd9Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 2987c478bd9Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 2990b70c467Sakolb t0.t_bindflag = (uchar_t)default_binding_mode; 3007c478bd9Sstevel@tonic-gate t0.t_cpupart = &cp_default; 3017c478bd9Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 3027c478bd9Sstevel@tonic-gate t0.t_copyops = NULL; 3037c478bd9Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate lwp0.lwp_thread = &t0; 3067c478bd9Sstevel@tonic-gate lwp0.lwp_regs = (void *)rp; 3077c478bd9Sstevel@tonic-gate lwp0.lwp_procp = &p0; 3087c478bd9Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate p0.p_exec = NULL; 3117c478bd9Sstevel@tonic-gate p0.p_stat = SRUN; 3127c478bd9Sstevel@tonic-gate p0.p_flag = SSYS; 3137c478bd9Sstevel@tonic-gate p0.p_tlist = &t0; 3147c478bd9Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 3157c478bd9Sstevel@tonic-gate p0.p_stkpageszc = 0; 3167c478bd9Sstevel@tonic-gate p0.p_as = &kas; 3177c478bd9Sstevel@tonic-gate p0.p_lockp = &p0lock; 3187c478bd9Sstevel@tonic-gate p0.p_brkpageszc = 0; 3192cb27123Saguzovsk p0.p_t1_lgrpid = LGRP_NONE; 3202cb27123Saguzovsk p0.p_tr_lgrpid = LGRP_NONE; 3217c478bd9Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate CPU->cpu_thread = &t0; 3247c478bd9Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 3257c478bd9Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 3267c478bd9Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 3277c478bd9Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 3287c478bd9Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 3297c478bd9Sstevel@tonic-gate CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE; 3307c478bd9Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate CPU->cpu_id = 0; 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate CPU->cpu_pri = 12; /* initial PIL for the boot CPU */ 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate /* 3370baeff3dSrab * The kernel doesn't use LDTs unless a process explicitly requests one. 3387c478bd9Sstevel@tonic-gate */ 339843e1988Sjohnlev p0.p_ldt_desc = null_sdesc; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate /* 342ae115bc7Smrj * Initialize thread/cpu microstate accounting 3437c478bd9Sstevel@tonic-gate */ 3447c478bd9Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 3457c478bd9Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate /* 3487c478bd9Sstevel@tonic-gate * Initialize lists of available and active CPUs. 3497c478bd9Sstevel@tonic-gate */ 3507c478bd9Sstevel@tonic-gate cpu_list_init(CPU); 3517c478bd9Sstevel@tonic-gate 3520e751525SEric Saxe pg_cpu_bootstrap(CPU); 3530e751525SEric Saxe 354ae115bc7Smrj /* 355ae115bc7Smrj * Now that we have taken over the GDT, IDT and have initialized 356ae115bc7Smrj * active CPU list it's time to inform kmdb if present. 357ae115bc7Smrj */ 358ae115bc7Smrj if (boothowto & RB_DEBUG) 359ae115bc7Smrj kdi_idt_sync(); 360ae115bc7Smrj 361ae115bc7Smrj /* 3629db7147eSSherry Moore * Explicitly set console to text mode (0x3) if this is a boot 3639db7147eSSherry Moore * post Fast Reboot, and the console is set to CONS_SCREEN_TEXT. 3649db7147eSSherry Moore */ 3650d928757SGary Mills if (post_fastreboot && boot_console_type(NULL) == CONS_SCREEN_TEXT) 3669db7147eSSherry Moore set_console_mode(0x3); 3679db7147eSSherry Moore 3689db7147eSSherry Moore /* 369ae115bc7Smrj * If requested (boot -d) drop into kmdb. 370ae115bc7Smrj * 371ae115bc7Smrj * This must be done after cpu_list_init() on the 64-bit kernel 372ae115bc7Smrj * since taking a trap requires that we re-compute gsbase based 373ae115bc7Smrj * on the cpu list. 374ae115bc7Smrj */ 375ae115bc7Smrj if (boothowto & RB_DEBUGENTER) 376ae115bc7Smrj kmdb_enter(); 377ae115bc7Smrj 378affbd3ccSkchow cpu_vm_data_init(CPU); 379affbd3ccSkchow 3807c478bd9Sstevel@tonic-gate rp->r_fp = 0; /* terminate kernel stack traces! */ 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate prom_init("kernel", (void *)NULL); 3837c478bd9Sstevel@tonic-gate 384a3114836SGerry Liu /* User-set option overrides firmware value. */ 385a3114836SGerry Liu if (bootprop_getval(PLAT_DR_OPTIONS_NAME, &prop_value) == 0) { 386a3114836SGerry Liu plat_dr_options = (uint64_t)prop_value; 387a3114836SGerry Liu } 388a3114836SGerry Liu #if defined(__xpv) 389a3114836SGerry Liu /* No support of DR operations on xpv */ 390a3114836SGerry Liu plat_dr_options = 0; 391a3114836SGerry Liu #else /* __xpv */ 392a3114836SGerry Liu /* Flag PLAT_DR_FEATURE_ENABLED should only be set by DR driver. */ 393a3114836SGerry Liu plat_dr_options &= ~PLAT_DR_FEATURE_ENABLED; 394a3114836SGerry Liu #ifndef __amd64 395a3114836SGerry Liu /* Only enable CPU/memory DR on 64 bits kernel. */ 396a3114836SGerry Liu plat_dr_options &= ~PLAT_DR_FEATURE_MEMORY; 397a3114836SGerry Liu plat_dr_options &= ~PLAT_DR_FEATURE_CPU; 398a3114836SGerry Liu #endif /* __amd64 */ 399a3114836SGerry Liu #endif /* __xpv */ 400a3114836SGerry Liu 401a3114836SGerry Liu /* 402a3114836SGerry Liu * Get value of "plat_dr_physmax" boot option. 403a3114836SGerry Liu * It overrides values calculated from MSCT or SRAT table. 404a3114836SGerry Liu */ 405a3114836SGerry Liu if (bootprop_getval(PLAT_DR_PHYSMAX_NAME, &prop_value) == 0) { 406a3114836SGerry Liu plat_dr_physmax = ((uint64_t)prop_value) >> PAGESHIFT; 407a3114836SGerry Liu } 408a3114836SGerry Liu 409a3114836SGerry Liu /* Get value of boot_ncpus. */ 410a3114836SGerry Liu if (bootprop_getval(BOOT_NCPUS_NAME, &prop_value) != 0) { 4112baa66a0SJonathan Chew boot_ncpus = NCPU; 412a3114836SGerry Liu } else { 4132baa66a0SJonathan Chew boot_ncpus = (int)prop_value; 41441791439Sandrei if (boot_ncpus <= 0 || boot_ncpus > NCPU) 415ae115bc7Smrj boot_ncpus = NCPU; 4162baa66a0SJonathan Chew } 41741791439Sandrei 418a3114836SGerry Liu /* 419a3114836SGerry Liu * Set max_ncpus and boot_max_ncpus to boot_ncpus if platform doesn't 420a3114836SGerry Liu * support CPU DR operations. 421a3114836SGerry Liu */ 422a3114836SGerry Liu if (plat_dr_support_cpu() == 0) { 42341791439Sandrei max_ncpus = boot_max_ncpus = boot_ncpus; 424a3114836SGerry Liu } else { 425a3114836SGerry Liu if (bootprop_getval(PLAT_MAX_NCPUS_NAME, &prop_value) != 0) { 426a3114836SGerry Liu max_ncpus = NCPU; 427a3114836SGerry Liu } else { 428a3114836SGerry Liu max_ncpus = (int)prop_value; 429a3114836SGerry Liu if (max_ncpus <= 0 || max_ncpus > NCPU) { 430a3114836SGerry Liu max_ncpus = NCPU; 431a3114836SGerry Liu } 432a3114836SGerry Liu if (boot_ncpus > max_ncpus) { 433a3114836SGerry Liu boot_ncpus = max_ncpus; 434a3114836SGerry Liu } 435a3114836SGerry Liu } 436a3114836SGerry Liu 437a3114836SGerry Liu if (bootprop_getval(BOOT_MAX_NCPUS_NAME, &prop_value) != 0) { 438a3114836SGerry Liu boot_max_ncpus = boot_ncpus; 439a3114836SGerry Liu } else { 440a3114836SGerry Liu boot_max_ncpus = (int)prop_value; 441a3114836SGerry Liu if (boot_max_ncpus <= 0 || boot_max_ncpus > NCPU) { 442a3114836SGerry Liu boot_max_ncpus = boot_ncpus; 443a3114836SGerry Liu } else if (boot_max_ncpus > max_ncpus) { 444a3114836SGerry Liu boot_max_ncpus = max_ncpus; 445a3114836SGerry Liu } 446a3114836SGerry Liu } 447a3114836SGerry Liu } 44841791439Sandrei 4492e2c009bSjjc /* 4502e2c009bSjjc * Initialize the lgrp framework 4512e2c009bSjjc */ 452d5d7cf4eSJonathan Chew lgrp_init(LGRP_INIT_STAGE1); 4532e2c009bSjjc 4547c478bd9Sstevel@tonic-gate if (boothowto & RB_HALT) { 4557c478bd9Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 4567c478bd9Sstevel@tonic-gate prom_enter_mon(); 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate ASSERT_STACK_ALIGNED(); 4607c478bd9Sstevel@tonic-gate 4612449e17fSsherrym /* 4622449e17fSsherrym * Fill out cpu_ucode_info. Update microcode if necessary. 4632449e17fSsherrym */ 4642449e17fSsherrym ucode_check(CPU); 4652449e17fSsherrym 4667c478bd9Sstevel@tonic-gate if (workaround_errata(CPU) != 0) 4677c478bd9Sstevel@tonic-gate panic("critical workaround(s) missing for boot cpu"); 4687c478bd9Sstevel@tonic-gate } 469986fd29aSsetje 470986fd29aSsetje 471986fd29aSsetje void 472986fd29aSsetje mach_modpath(char *path, const char *filename) 473986fd29aSsetje { 474986fd29aSsetje /* 475986fd29aSsetje * Construct the directory path from the filename. 476986fd29aSsetje */ 477986fd29aSsetje 478986fd29aSsetje int len; 479986fd29aSsetje char *p; 480986fd29aSsetje const char isastr[] = "/amd64"; 481986fd29aSsetje size_t isalen = strlen(isastr); 482986fd29aSsetje 483*0181461bSKeith M Wesolowski len = strlen(SYSTEM_BOOT_PATH "/kernel"); 484*0181461bSKeith M Wesolowski (void) strcpy(path, SYSTEM_BOOT_PATH "/kernel "); 485*0181461bSKeith M Wesolowski path += len + 1; 486*0181461bSKeith M Wesolowski 487986fd29aSsetje if ((p = strrchr(filename, '/')) == NULL) 488986fd29aSsetje return; 489986fd29aSsetje 490986fd29aSsetje while (p > filename && *(p - 1) == '/') 491986fd29aSsetje p--; /* remove trailing '/' characters */ 492986fd29aSsetje if (p == filename) 493986fd29aSsetje p++; /* so "/" -is- the modpath in this case */ 494986fd29aSsetje 495986fd29aSsetje /* 496986fd29aSsetje * Remove optional isa-dependent directory name - the module 497986fd29aSsetje * subsystem will put this back again (!) 498986fd29aSsetje */ 499986fd29aSsetje len = p - filename; 500986fd29aSsetje if (len > isalen && 501986fd29aSsetje strncmp(&filename[len - isalen], isastr, isalen) == 0) 502986fd29aSsetje p -= isalen; 503986fd29aSsetje 504986fd29aSsetje /* 505986fd29aSsetje * "/platform/mumblefrotz" + " " + MOD_DEFPATH 506986fd29aSsetje */ 507986fd29aSsetje len += (p - filename) + 1 + strlen(MOD_DEFPATH) + 1; 508986fd29aSsetje (void) strncpy(path, filename, p - filename); 509986fd29aSsetje } 510