mlsetup.c revision 2449e17f82f6097fd2c665b64723e31ceecbeca6
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
55da60b91d96984f12de050ce428373ea25c7f35Mark J Musante * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
beb562835cfbfcc73ae96a39ad1ef3e0446d299cShampavman * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * some globals for patching the result of cpuid
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * to solve problems w/ creative cpu vendors
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Dummy spl priority masks
fa9e4066f08beec538e775443c5be79dd423fcabahrens if ((BOP_GETPROPLEN(bootops, name) > sizeof (prop)) ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Setup routine called right before main(). Interposing this function
fa9e4066f08beec538e775443c5be79dd423fcabahrens * before main() allows us to call it in a machine-independent fashion.
fa9e4066f08beec538e775443c5be79dd423fcabahrens extern char t0stack[];
fa9e4066f08beec538e775443c5be79dd423fcabahrens * initialize cpu_self
28e4da25922bdfc5cba7ab29f47de911bbd78009Matthew Ahrens * Set up dummy cpu_pri_data values till psm spl code is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * installed. This allows splx() to work on amd64.
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * check if we've got special bits to clear or set
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * when checking cpu features
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * The first lightweight pass (pass0) through the cpuid data
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * was done in locore before mlsetup was called. Do the next
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * pass in C code.
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * The x86_feature bits are set here on the basis of the capabilities
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * of the boot CPU. Note that if we choose to support CPUs that have
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * different feature sets (at which point we would almost certainly
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * want to set the feature bits to correspond to the feature
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * minimum) this value may be altered.
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * Initialize idt0, gdt0, ldt0_default, ktss0 and dftss.
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * Some i386 processors do not implement the rdtsc instruction,
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * or at least they do not implement it correctly.
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * For those that do, patch in the rdtsc instructions in
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * various parts of the kernel right now while the text is
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * still writable.
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson#endif /* __i386 */
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * While we're thinking about the TSC, let's set up %cr4 so that
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * userland can issue rdtsc, and initialize the TSC_AUX value
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * (the cpuid) for the rdtscp instruction on appropriately
2e4c998613148111f2fc5371085331ffb39122ffGeorge Wilson * capable hardware.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * initialize t0
fa9e4066f08beec538e775443c5be79dd423fcabahrens t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
28e4da25922bdfc5cba7ab29f47de911bbd78009Matthew Ahrens CPU->cpu_flags = CPU_READY | CPU_RUNNING | CPU_EXISTS | CPU_ENABLE;
fa9e4066f08beec538e775443c5be79dd423fcabahrens CPU->cpu_pri = 12; /* initial PIL for the boot CPU */
28e4da25922bdfc5cba7ab29f47de911bbd78009Matthew Ahrens * The kernel doesn't use LDTs unless a process explicitly requests one.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize thread/cpu microstate accounting
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Initialize lists of available and active CPUs.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Now that we have taken over the GDT, IDT and have initialized
fa9e4066f08beec538e775443c5be79dd423fcabahrens * active CPU list it's time to inform kmdb if present.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If requested (boot -d) drop into kmdb.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * This must be done after cpu_list_init() on the 64-bit kernel
fa9e4066f08beec538e775443c5be79dd423fcabahrens * since taking a trap requires that we re-compute gsbase based
fa9e4066f08beec538e775443c5be79dd423fcabahrens * on the cpu list.
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* lgrp_init() needs PCI config space access */
28e4da25922bdfc5cba7ab29f47de911bbd78009Matthew Ahrens * Initialize the lgrp framework
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Fill out cpu_ucode_info. Update microcode if necessary.
fa9e4066f08beec538e775443c5be79dd423fcabahrens panic("critical workaround(s) missing for boot cpu");