#include <sys/cdefs.h>
#include "opt_cpu.h"
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/cpu.h>
#include <sys/eventhandler.h>
#include <sys/limits.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/power.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/asmacros.h>
#include <machine/clock.h>
#include <machine/cputypes.h>
#include <machine/frame.h>
#include <machine/intr_machdep.h>
#include <machine/md_var.h>
#include <machine/segments.h>
#include <machine/specialreg.h>
#include <amd64/vmm/intel/vmx_controls.h>
#include <x86/isa/icu.h>
#include <x86/vmware.h>
#ifdef XENHVM
#include <xen/xen-os.h>
#endif
#ifdef __i386__
#define IDENTBLUE_CYRIX486 0
#define IDENTBLUE_IBMCPU 1
#define IDENTBLUE_CYRIXM2 2
static void identifycyrix(void);
static void print_transmeta_info(void);
#endif
static u_int find_cpu_vendor_id(void);
static void print_AMD_info(void);
static void print_INTEL_info(void);
static void print_INTEL_TLB(u_int data);
static void print_hypervisor_info(void);
static void print_svm_info(void);
static void print_via_padlock_info(void);
static void print_vmx_info(void);
#ifdef __i386__
int cpu;
int cpu_class;
#endif
u_int cpu_feature;
u_int cpu_feature2;
u_int amd_feature;
u_int amd_feature2;
u_int amd_rascap;
u_int amd_pminfo;
u_int amd_extended_feature_extensions;
u_int via_feature_rng;
u_int via_feature_xcrypt;
u_int cpu_high;
u_int cpu_exthigh;
u_int cpu_id;
u_int cpu_procinfo;
u_int cpu_procinfo2;
u_int cpu_procinfo3;
char cpu_vendor[20];
u_int cpu_vendor_id;
u_int cpu_mxcsr_mask;
u_int cpu_clflush_line_size = 32;
u_int cpu_stdext_feature;
u_int cpu_stdext_feature2;
u_int cpu_stdext_feature3;
u_int cpu_stdext_feature4;
uint64_t cpu_ia32_arch_caps;
u_int cpu_max_ext_state_size;
u_int cpu_mon_mwait_flags;
u_int cpu_mon_mwait_edx;
u_int cpu_mon_min_size;
u_int cpu_mon_max_size;
u_int cpu_maxphyaddr;
u_int cpu_power_eax;
u_int cpu_power_ebx;
u_int cpu_power_ecx;
u_int cpu_power_edx;
const char machine[] = MACHINE;
SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
&via_feature_rng, 0,
"VIA RNG feature available in CPU");
SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
&via_feature_xcrypt, 0,
"VIA xcrypt feature available in CPU");
#ifdef __amd64__
#ifdef SCTL_MASK32
extern int adaptive_machine_arch;
#endif
static int
sysctl_hw_machine(SYSCTL_HANDLER_ARGS)
{
#ifdef SCTL_MASK32
static const char machine32[] = "i386";
#endif
int error;
#ifdef SCTL_MASK32
if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch)
error = SYSCTL_OUT(req, machine32, sizeof(machine32));
else
#endif
error = SYSCTL_OUT(req, machine, sizeof(machine));
return (error);
}
SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD |
CTLFLAG_CAPRD | CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine, "A", "Machine class");
#else
SYSCTL_CONST_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD,
machine, "Machine class");
#endif
char cpu_model[128];
SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD | CTLFLAG_CAPRD,
cpu_model, 0, "Machine model");
static int hw_clockrate;
SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD,
&hw_clockrate, 0, "CPU instruction clock rate");
u_int hv_base;
u_int hv_high;
char hv_vendor[16];
SYSCTL_STRING(_hw, OID_AUTO, hv_vendor, CTLFLAG_RD, hv_vendor,
0, "Hypervisor vendor");
static eventhandler_tag tsc_post_tag;
static char cpu_brand[48];
#ifdef __i386__
#define MAX_BRAND_INDEX 8
static const char *cpu_brandtable[MAX_BRAND_INDEX + 1] = {
NULL,
"Intel Celeron",
"Intel Pentium III",
"Intel Pentium III Xeon",
NULL,
NULL,
NULL,
NULL,
"Intel Pentium 4"
};
static struct {
char *cpu_name;
int cpu_class;
} cpus[] = {
{ "Intel 80286", CPUCLASS_286 },
{ "i386SX", CPUCLASS_386 },
{ "i386DX", CPUCLASS_386 },
{ "i486SX", CPUCLASS_486 },
{ "i486DX", CPUCLASS_486 },
{ "Pentium", CPUCLASS_586 },
{ "Cyrix 486", CPUCLASS_486 },
{ "Pentium Pro", CPUCLASS_686 },
{ "Cyrix 5x86", CPUCLASS_486 },
{ "Cyrix 6x86", CPUCLASS_486 },
{ "Blue Lightning", CPUCLASS_486 },
{ "Cyrix 6x86MX", CPUCLASS_686 },
{ "NexGen 586", CPUCLASS_386 },
{ "Cyrix 486S/DX", CPUCLASS_486 },
{ "Pentium II", CPUCLASS_686 },
{ "Pentium III", CPUCLASS_686 },
{ "Pentium 4", CPUCLASS_686 },
};
#endif
static struct {
char *vendor;
u_int vendor_id;
} cpu_vendors[] = {
{ INTEL_VENDOR_ID, CPU_VENDOR_INTEL },
{ AMD_VENDOR_ID, CPU_VENDOR_AMD },
{ HYGON_VENDOR_ID, CPU_VENDOR_HYGON },
{ CENTAUR_VENDOR_ID, CPU_VENDOR_CENTAUR },
#ifdef __i386__
{ NSC_VENDOR_ID, CPU_VENDOR_NSC },
{ CYRIX_VENDOR_ID, CPU_VENDOR_CYRIX },
{ TRANSMETA_VENDOR_ID, CPU_VENDOR_TRANSMETA },
{ SIS_VENDOR_ID, CPU_VENDOR_SIS },
{ UMC_VENDOR_ID, CPU_VENDOR_UMC },
{ NEXGEN_VENDOR_ID, CPU_VENDOR_NEXGEN },
{ RISE_VENDOR_ID, CPU_VENDOR_RISE },
#if 0
{ "TransmetaCPU", CPU_VENDOR_TRANSMETA },
#endif
#endif
};
void
printcpuinfo(void)
{
u_int regs[4], i;
char *brand;
printf("CPU: ");
#ifdef __i386__
cpu_class = cpus[cpu].cpu_class;
strncpy(cpu_model, cpus[cpu].cpu_name, sizeof (cpu_model));
#else
strncpy(cpu_model, "Hammer", sizeof (cpu_model));
#endif
if (cpu_exthigh >= 0x80000004) {
brand = cpu_brand;
for (i = 0x80000002; i < 0x80000005; i++) {
do_cpuid(i, regs);
memcpy(brand, regs, sizeof(regs));
brand += sizeof(regs);
}
}
switch (cpu_vendor_id) {
case CPU_VENDOR_INTEL:
#ifdef __i386__
if ((cpu_id & 0xf00) > 0x300) {
u_int brand_index;
cpu_model[0] = '\0';
switch (cpu_id & 0x3000) {
case 0x1000:
strcpy(cpu_model, "Overdrive ");
break;
case 0x2000:
strcpy(cpu_model, "Dual ");
break;
}
switch (cpu_id & 0xf00) {
case 0x400:
strcat(cpu_model, "i486 ");
switch (cpu_id & 0xf0) {
case 0x00:
case 0x10:
strcat(cpu_model, "DX");
break;
case 0x20:
strcat(cpu_model, "SX");
break;
case 0x30:
strcat(cpu_model, "DX2");
break;
case 0x40:
strcat(cpu_model, "SL");
break;
case 0x50:
strcat(cpu_model, "SX2");
break;
case 0x70:
strcat(cpu_model,
"DX2 Write-Back Enhanced");
break;
case 0x80:
strcat(cpu_model, "DX4");
break;
}
break;
case 0x500:
strcat(cpu_model, "Pentium");
switch (cpu_id & 0xf0) {
case 0x00:
strcat(cpu_model, " A-step");
break;
case 0x10:
strcat(cpu_model, "/P5");
break;
case 0x20:
strcat(cpu_model, "/P54C");
break;
case 0x30:
strcat(cpu_model, "/P24T");
break;
case 0x40:
strcat(cpu_model, "/P55C");
break;
case 0x70:
strcat(cpu_model, "/P54C");
break;
case 0x80:
strcat(cpu_model, "/P55C (quarter-micron)");
break;
default:
break;
}
#if defined(I586_CPU) && !defined(NO_F00F_HACK)
has_f00f_bug = 1;
#endif
break;
case 0x600:
switch (cpu_id & 0xf0) {
case 0x00:
strcat(cpu_model, "Pentium Pro A-step");
break;
case 0x10:
strcat(cpu_model, "Pentium Pro");
break;
case 0x30:
case 0x50:
case 0x60:
strcat(cpu_model,
"Pentium II/Pentium II Xeon/Celeron");
cpu = CPU_PII;
break;
case 0x70:
case 0x80:
case 0xa0:
case 0xb0:
strcat(cpu_model,
"Pentium III/Pentium III Xeon/Celeron");
cpu = CPU_PIII;
break;
default:
strcat(cpu_model, "Unknown 80686");
break;
}
break;
case 0xf00:
strcat(cpu_model, "Pentium 4");
cpu = CPU_P4;
break;
default:
strcat(cpu_model, "unknown");
break;
}
if (cpu_high > 0 && *cpu_brand == '\0') {
brand_index = cpu_procinfo & CPUID_BRAND_INDEX;
if (brand_index <= MAX_BRAND_INDEX &&
cpu_brandtable[brand_index] != NULL)
strcpy(cpu_brand,
cpu_brandtable[brand_index]);
}
}
#else
strcat(cpu_model, "EM64T");
#endif
break;
case CPU_VENDOR_AMD:
strcpy(cpu_model, "AMD ");
#ifdef __i386__
switch (cpu_id & 0xFF0) {
case 0x410:
strcat(cpu_model, "Standard Am486DX");
break;
case 0x430:
strcat(cpu_model, "Enhanced Am486DX2 Write-Through");
break;
case 0x470:
strcat(cpu_model, "Enhanced Am486DX2 Write-Back");
break;
case 0x480:
strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Through");
break;
case 0x490:
strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Back");
break;
case 0x4E0:
strcat(cpu_model, "Am5x86 Write-Through");
break;
case 0x4F0:
strcat(cpu_model, "Am5x86 Write-Back");
break;
case 0x500:
strcat(cpu_model, "K5 model 0");
break;
case 0x510:
strcat(cpu_model, "K5 model 1");
break;
case 0x520:
strcat(cpu_model, "K5 PR166 (model 2)");
break;
case 0x530:
strcat(cpu_model, "K5 PR200 (model 3)");
break;
case 0x560:
strcat(cpu_model, "K6");
break;
case 0x570:
strcat(cpu_model, "K6 266 (model 1)");
break;
case 0x580:
strcat(cpu_model, "K6-2");
break;
case 0x590:
strcat(cpu_model, "K6-III");
break;
case 0x5a0:
strcat(cpu_model, "Geode LX");
break;
default:
strcat(cpu_model, "Unknown");
break;
}
#else
if ((cpu_id & 0xf00) == 0xf00)
strcat(cpu_model, "AMD64 Processor");
else
strcat(cpu_model, "Unknown");
#endif
break;
#ifdef __i386__
case CPU_VENDOR_CYRIX:
strcpy(cpu_model, "Cyrix ");
switch (cpu_id & 0xff0) {
case 0x440:
strcat(cpu_model, "MediaGX");
break;
case 0x520:
strcat(cpu_model, "6x86");
break;
case 0x540:
cpu_class = CPUCLASS_586;
strcat(cpu_model, "GXm");
break;
case 0x600:
strcat(cpu_model, "6x86MX");
break;
default:
switch (cyrix_did & 0xf0) {
case 0x00:
switch (cyrix_did & 0x0f) {
case 0x00:
strcat(cpu_model, "486SLC");
break;
case 0x01:
strcat(cpu_model, "486DLC");
break;
case 0x02:
strcat(cpu_model, "486SLC2");
break;
case 0x03:
strcat(cpu_model, "486DLC2");
break;
case 0x04:
strcat(cpu_model, "486SRx");
break;
case 0x05:
strcat(cpu_model, "486DRx");
break;
case 0x06:
strcat(cpu_model, "486SRx2");
break;
case 0x07:
strcat(cpu_model, "486DRx2");
break;
case 0x08:
strcat(cpu_model, "486SRu");
break;
case 0x09:
strcat(cpu_model, "486DRu");
break;
case 0x0a:
strcat(cpu_model, "486SRu2");
break;
case 0x0b:
strcat(cpu_model, "486DRu2");
break;
default:
strcat(cpu_model, "Unknown");
break;
}
break;
case 0x10:
switch (cyrix_did & 0x0f) {
case 0x00:
strcat(cpu_model, "486S");
break;
case 0x01:
strcat(cpu_model, "486S2");
break;
case 0x02:
strcat(cpu_model, "486Se");
break;
case 0x03:
strcat(cpu_model, "486S2e");
break;
case 0x0a:
strcat(cpu_model, "486DX");
break;
case 0x0b:
strcat(cpu_model, "486DX2");
break;
case 0x0f:
strcat(cpu_model, "486DX4");
break;
default:
strcat(cpu_model, "Unknown");
break;
}
break;
case 0x20:
if ((cyrix_did & 0x0f) < 8)
strcat(cpu_model, "6x86");
else
strcat(cpu_model, "5x86");
break;
case 0x30:
strcat(cpu_model, "6x86");
break;
case 0x40:
if ((cyrix_did & 0xf000) == 0x3000) {
cpu_class = CPUCLASS_586;
strcat(cpu_model, "GXm");
} else
strcat(cpu_model, "MediaGX");
break;
case 0x50:
strcat(cpu_model, "6x86MX");
break;
case 0xf0:
switch (cyrix_did & 0x0f) {
case 0x0d:
strcat(cpu_model, "Overdrive CPU");
break;
case 0x0e:
strcpy(cpu_model, "Texas Instruments 486SXL");
break;
case 0x0f:
strcat(cpu_model, "486SLC/DLC");
break;
default:
strcat(cpu_model, "Unknown");
break;
}
break;
default:
strcat(cpu_model, "Unknown");
break;
}
break;
}
break;
case CPU_VENDOR_RISE:
strcpy(cpu_model, "Rise ");
switch (cpu_id & 0xff0) {
case 0x500:
case 0x520:
strcat(cpu_model, "mP6");
break;
default:
strcat(cpu_model, "Unknown");
}
break;
#endif
case CPU_VENDOR_CENTAUR:
#ifdef __i386__
switch (cpu_id & 0xff0) {
case 0x540:
strcpy(cpu_model, "IDT WinChip C6");
break;
case 0x580:
strcpy(cpu_model, "IDT WinChip 2");
break;
case 0x590:
strcpy(cpu_model, "IDT WinChip 3");
break;
case 0x660:
strcpy(cpu_model, "VIA C3 Samuel");
break;
case 0x670:
if (cpu_id & 0x8)
strcpy(cpu_model, "VIA C3 Ezra");
else
strcpy(cpu_model, "VIA C3 Samuel 2");
break;
case 0x680:
strcpy(cpu_model, "VIA C3 Ezra-T");
break;
case 0x690:
strcpy(cpu_model, "VIA C3 Nehemiah");
break;
case 0x6a0:
case 0x6d0:
strcpy(cpu_model, "VIA C7 Esther");
break;
case 0x6f0:
strcpy(cpu_model, "VIA Nano");
break;
default:
strcpy(cpu_model, "VIA/IDT Unknown");
}
#else
strcpy(cpu_model, "VIA ");
if ((cpu_id & 0xff0) == 0x6f0)
strcat(cpu_model, "Nano Processor");
else
strcat(cpu_model, "Unknown");
#endif
break;
#ifdef __i386__
case CPU_VENDOR_IBM:
strcpy(cpu_model, "Blue Lightning CPU");
break;
case CPU_VENDOR_NSC:
switch (cpu_id & 0xff0) {
case 0x540:
strcpy(cpu_model, "Geode SC1100");
cpu = CPU_GEODE1100;
break;
default:
strcpy(cpu_model, "Geode/NSC unknown");
break;
}
break;
#endif
case CPU_VENDOR_HYGON:
strcpy(cpu_model, "Hygon ");
#ifdef __i386__
strcat(cpu_model, "Unknown");
#else
if ((cpu_id & 0xf00) == 0xf00)
strcat(cpu_model, "AMD64 Processor");
else
strcat(cpu_model, "Unknown");
#endif
break;
default:
strcat(cpu_model, "Unknown");
break;
}
brand = cpu_brand;
while (*brand == ' ')
++brand;
if (*brand != '\0')
strcpy(cpu_model, brand);
printf("%s (", cpu_model);
if (tsc_freq != 0) {
hw_clockrate = (tsc_freq + 5000) / 1000000;
printf("%jd.%02d-MHz ",
(intmax_t)(tsc_freq + 4999) / 1000000,
(u_int)((tsc_freq + 4999) / 10000) % 100);
}
#ifdef __i386__
switch(cpu_class) {
case CPUCLASS_286:
printf("286");
break;
case CPUCLASS_386:
printf("386");
break;
#if defined(I486_CPU)
case CPUCLASS_486:
printf("486");
break;
#endif
#if defined(I586_CPU)
case CPUCLASS_586:
printf("586");
break;
#endif
#if defined(I686_CPU)
case CPUCLASS_686:
printf("686");
break;
#endif
default:
printf("Unknown");
}
#else
printf("K8");
#endif
printf("-class CPU)\n");
if (*cpu_vendor)
printf(" Origin=\"%s\"", cpu_vendor);
if (cpu_id)
printf(" Id=0x%x", cpu_id);
if (cpu_vendor_id == CPU_VENDOR_INTEL ||
cpu_vendor_id == CPU_VENDOR_AMD ||
cpu_vendor_id == CPU_VENDOR_HYGON ||
cpu_vendor_id == CPU_VENDOR_CENTAUR ||
#ifdef __i386__
cpu_vendor_id == CPU_VENDOR_TRANSMETA ||
cpu_vendor_id == CPU_VENDOR_RISE ||
cpu_vendor_id == CPU_VENDOR_NSC ||
(cpu_vendor_id == CPU_VENDOR_CYRIX && ((cpu_id & 0xf00) > 0x500)) ||
#endif
0) {
printf(" Family=0x%x", CPUID_TO_FAMILY(cpu_id));
printf(" Model=0x%x", CPUID_TO_MODEL(cpu_id));
printf(" Stepping=%u", cpu_id & CPUID_STEPPING);
#ifdef __i386__
if (cpu_vendor_id == CPU_VENDOR_CYRIX)
printf("\n DIR=0x%04x", cyrix_did);
#endif
if (cpu_high > 0) {
printf("\n Features=0x%b", cpu_feature,
"\020"
"\001FPU"
"\002VME"
"\003DE"
"\004PSE"
"\005TSC"
"\006MSR"
"\007PAE"
"\010MCE"
"\011CX8"
"\012APIC"
"\013oldMTRR"
"\014SEP"
"\015MTRR"
"\016PGE"
"\017MCA"
"\020CMOV"
"\021PAT"
"\022PSE36"
"\023PN"
"\024CLFLUSH"
"\025<b20>"
"\026DTS"
"\027ACPI"
"\030MMX"
"\031FXSR"
"\032SSE"
"\033SSE2"
"\034SS"
"\035HTT"
"\036TM"
"\037IA64"
"\040PBE"
);
if (cpu_feature2 != 0) {
printf("\n Features2=0x%b", cpu_feature2,
"\020"
"\001SSE3"
"\002PCLMULQDQ"
"\003DTES64"
"\004MON"
"\005DS_CPL"
"\006VMX"
"\007SMX"
"\010EST"
"\011TM2"
"\012SSSE3"
"\013CNXT-ID"
"\014SDBG"
"\015FMA"
"\016CX16"
"\017xTPR"
"\020PDCM"
"\021<b16>"
"\022PCID"
"\023DCA"
"\024SSE4.1"
"\025SSE4.2"
"\026x2APIC"
"\027MOVBE"
"\030POPCNT"
"\031TSCDLT"
"\032AESNI"
"\033XSAVE"
"\034OSXSAVE"
"\035AVX"
"\036F16C"
"\037RDRAND"
"\040HV"
);
}
if (amd_feature != 0) {
printf("\n AMD Features=0x%b", amd_feature,
"\020"
"\001<s0>"
"\002<s1>"
"\003<s2>"
"\004<s3>"
"\005<s4>"
"\006<s5>"
"\007<s6>"
"\010<s7>"
"\011<s8>"
"\012<s9>"
"\013<b10>"
"\014SYSCALL"
"\015<s12>"
"\016<s13>"
"\017<s14>"
"\020<s15>"
"\021<s16>"
"\022<s17>"
"\023<b18>"
"\024MP"
"\025NX"
"\026<b21>"
"\027MMX+"
"\030<s23>"
"\031<s24>"
"\032FFXSR"
"\033Page1GB"
"\034RDTSCP"
"\035<b28>"
"\036LM"
"\0373DNow!+"
"\0403DNow!"
);
}
if (amd_feature2 != 0) {
printf("\n AMD Features2=0x%b", amd_feature2,
"\020"
"\001LAHF"
"\002CMP"
"\003SVM"
"\004ExtAPIC"
"\005CR8"
"\006ABM"
"\007SSE4A"
"\010MAS"
"\011Prefetch"
"\012OSVW"
"\013IBS"
"\014XOP"
"\015SKINIT"
"\016WDT"
"\017<b14>"
"\020LWP"
"\021FMA4"
"\022TCE"
"\023<b18>"
"\024NodeId"
"\025<b20>"
"\026TBM"
"\027Topology"
"\030PCXC"
"\031PNXC"
"\032<b25>"
"\033DBE"
"\034PTSC"
"\035PL2I"
"\036MWAITX"
"\037ADMSKX"
"\040<b31>"
);
}
if (cpu_stdext_feature != 0) {
printf("\n Structured Extended Features=0x%b",
cpu_stdext_feature,
"\020"
"\001FSGSBASE"
"\002TSCADJ"
"\003SGX"
"\004BMI1"
"\005HLE"
"\006AVX2"
"\007FDPEXC"
"\010SMEP"
"\011BMI2"
"\012ERMS"
"\013INVPCID"
"\014RTM"
"\015PQM"
"\016NFPUSG"
"\017MPX"
"\020PQE"
"\021AVX512F"
"\022AVX512DQ"
"\023RDSEED"
"\024ADX"
"\025SMAP"
"\026AVX512IFMA"
"\027<b22>"
"\030CLFLUSHOPT"
"\031CLWB"
"\032PROCTRACE"
"\033AVX512PF"
"\034AVX512ER"
"\035AVX512CD"
"\036SHA"
"\037AVX512BW"
"\040AVX512VL"
);
}
if (cpu_stdext_feature2 != 0) {
printf("\n Structured Extended Features2=0x%b",
cpu_stdext_feature2,
"\020"
"\001PREFETCHWT1"
"\002AVX512VBMI"
"\003UMIP"
"\004PKU"
"\005OSPKE"
"\006WAITPKG"
"\007AVX512VBMI2"
"\011GFNI"
"\012VAES"
"\013VPCLMULQDQ"
"\014AVX512VNNI"
"\015AVX512BITALG"
"\016TME"
"\017AVX512VPOPCNTDQ"
"\021LA57"
"\027RDPID"
"\032CLDEMOTE"
"\034MOVDIRI"
"\035MOVDIR64B"
"\036ENQCMD"
"\037SGXLC"
);
}
if (cpu_stdext_feature3 != 0) {
printf("\n Structured Extended Features3=0x%b",
cpu_stdext_feature3,
"\020"
"\003AVX512_4VNNIW"
"\004AVX512_4FMAPS"
"\005FSRM"
"\011AVX512VP2INTERSECT"
"\012MCUOPT"
"\013MD_CLEAR"
"\016TSXFA"
"\023PCONFIG"
"\025IBT"
"\033IBPB"
"\034STIBP"
"\035L1DFL"
"\036ARCH_CAP"
"\037CORE_CAP"
"\040SSBD"
);
}
if (cpu_stdext_feature4 != 0) {
printf("\n Structured Extended Features4=0x%b",
cpu_stdext_feature4,
"\020"
"\007LASS"
"\022FRED"
"\023LKGS"
"\024WRMSRNS"
"\025NMISRC"
"\033LAM"
);
}
if ((cpu_feature2 & CPUID2_XSAVE) != 0) {
cpuid_count(0xd, 0x1, regs);
if (regs[0] != 0) {
printf("\n XSAVE Features=0x%b",
regs[0],
"\020"
"\001XSAVEOPT"
"\002XSAVEC"
"\003XINUSE"
"\004XSAVES");
}
}
if (cpu_ia32_arch_caps != 0) {
printf("\n IA32_ARCH_CAPS=0x%b",
(u_int)cpu_ia32_arch_caps,
"\020"
"\001RDCL_NO"
"\002IBRS_ALL"
"\003RSBA"
"\004SKIP_L1DFL_VME"
"\005SSB_NO"
"\006MDS_NO"
"\010TSX_CTRL"
"\011TAA_NO"
);
}
if (amd_extended_feature_extensions != 0) {
u_int amd_fe_masked;
amd_fe_masked = amd_extended_feature_extensions;
if ((amd_fe_masked & AMDFEID_IBRS) == 0)
amd_fe_masked &=
~(AMDFEID_IBRS_ALWAYSON |
AMDFEID_PREFER_IBRS);
if ((amd_fe_masked & AMDFEID_STIBP) == 0)
amd_fe_masked &=
~AMDFEID_STIBP_ALWAYSON;
printf("\n "
"AMD Extended Feature Extensions ID EBX="
"0x%b", amd_fe_masked,
"\020"
"\001CLZERO"
"\002IRPerf"
"\003XSaveErPtr"
"\004INVLPGB"
"\005RDPRU"
"\007BE"
"\011MCOMMIT"
"\012WBNOINVD"
"\015IBPB"
"\016INT_WBINVD"
"\017IBRS"
"\020STIBP"
"\021IBRS_ALWAYSON"
"\022STIBP_ALWAYSON"
"\023PREFER_IBRS"
"\024SAMEMODE_IBRS"
"\025NOLMSLE"
"\026INVLPGBNEST"
"\030PPIN"
"\031SSBD"
"\032VIRT_SSBD"
"\033SSB_NO"
"\034CPPC"
"\035PSFD"
"\036BTC_NO"
"\037IBPB_RET"
);
}
if (via_feature_rng != 0 || via_feature_xcrypt != 0)
print_via_padlock_info();
if (cpu_feature2 & CPUID2_VMX)
print_vmx_info();
if (amd_feature2 & AMDID2_SVM)
print_svm_info();
if ((cpu_feature & CPUID_HTT) &&
(cpu_vendor_id == CPU_VENDOR_AMD ||
cpu_vendor_id == CPU_VENDOR_HYGON))
cpu_feature &= ~CPUID_HTT;
if (tsc_is_invariant) {
printf("\n TSC: P-state invariant");
if (tsc_perf_stat)
printf(", performance statistics");
}
}
#ifdef __i386__
} else if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
printf(" DIR=0x%04x", cyrix_did);
printf(" Stepping=%u", (cyrix_did & 0xf000) >> 12);
printf(" Revision=%u", (cyrix_did & 0x0f00) >> 8);
#ifndef CYRIX_CACHE_REALLY_WORKS
if (cpu == CPU_M1 && (cyrix_did & 0xff00) < 0x1700)
printf("\n CPU cache: write-through mode");
#endif
#endif
}
if (*cpu_vendor || cpu_id)
printf("\n");
if (bootverbose) {
if (cpu_vendor_id == CPU_VENDOR_AMD ||
cpu_vendor_id == CPU_VENDOR_HYGON)
print_AMD_info();
else if (cpu_vendor_id == CPU_VENDOR_INTEL)
print_INTEL_info();
#ifdef __i386__
else if (cpu_vendor_id == CPU_VENDOR_TRANSMETA)
print_transmeta_info();
#endif
}
print_hypervisor_info();
}
#ifdef __i386__
void
panicifcpuunsupported(void)
{
#if !defined(lint)
#if !defined(I486_CPU) && !defined(I586_CPU) && !defined(I686_CPU)
#error This kernel is not configured for one of the supported CPUs
#endif
#else
#endif
switch (cpu_class) {
case CPUCLASS_286:
case CPUCLASS_386:
#if !defined(I486_CPU)
case CPUCLASS_486:
#endif
#if !defined(I586_CPU)
case CPUCLASS_586:
#endif
#if !defined(I686_CPU)
case CPUCLASS_686:
#endif
panic("CPU class not configured");
default:
break;
}
}
static volatile u_int trap_by_rdmsr;
inthand_t bluetrap6;
__asm
(" \n\
.text \n\
.p2align 2,0x90 \n\
.type " __XSTRING(CNAME(bluetrap6)) ",@function \n\
" __XSTRING(CNAME(bluetrap6)) ": \n\
ss \n\
movl $0xa8c1d," __XSTRING(CNAME(trap_by_rdmsr)) " \n\
addl $2, (%esp) /* rdmsr is a 2-byte instruction */ \n\
iret \n\
");
inthand_t bluetrap13;
__asm
(" \n\
.text \n\
.p2align 2,0x90 \n\
.type " __XSTRING(CNAME(bluetrap13)) ",@function \n\
" __XSTRING(CNAME(bluetrap13)) ": \n\
ss \n\
movl $0xa89c4," __XSTRING(CNAME(trap_by_rdmsr)) " \n\
popl %eax /* discard error code */ \n\
addl $2, (%esp) /* rdmsr is a 2-byte instruction */ \n\
iret \n\
");
static int
identblue(void)
{
trap_by_rdmsr = 0;
setidt(IDT_UD, bluetrap6, SDT_SYS386TGT, SEL_KPL,
GSEL(GCODE_SEL, SEL_KPL));
setidt(IDT_GP, bluetrap13, SDT_SYS386TGT, SEL_KPL,
GSEL(GCODE_SEL, SEL_KPL));
rdmsr(0x1002);
if (trap_by_rdmsr == 0xa8c1d)
return IDENTBLUE_CYRIX486;
else if (trap_by_rdmsr == 0xa89c4)
return IDENTBLUE_CYRIXM2;
return IDENTBLUE_IBMCPU;
}
static void
identifycyrix(void)
{
register_t saveintr;
int ccr2_test = 0, dir_test = 0;
u_char ccr2, ccr3;
saveintr = intr_disable();
ccr2 = read_cyrix_reg(CCR2);
write_cyrix_reg(CCR2, ccr2 ^ CCR2_LOCK_NW);
read_cyrix_reg(CCR2);
if (read_cyrix_reg(CCR2) != ccr2)
ccr2_test = 1;
write_cyrix_reg(CCR2, ccr2);
ccr3 = read_cyrix_reg(CCR3);
write_cyrix_reg(CCR3, ccr3 ^ CCR3_MAPEN3);
read_cyrix_reg(CCR3);
if (read_cyrix_reg(CCR3) != ccr3)
dir_test = 1;
write_cyrix_reg(CCR3, ccr3);
if (dir_test) {
cyrix_did = read_cyrix_reg(DIR1) << 8;
cyrix_did += read_cyrix_reg(DIR0);
} else if (ccr2_test)
cyrix_did = 0x0010;
else
cyrix_did = 0x00ff;
intr_restore(saveintr);
}
#endif
static void
tsc_freq_changed(void *arg __unused, const struct cf_level *level, int status)
{
if (status != 0)
return;
hw_clockrate = level->total_set.freq;
}
static void
hook_tsc_freq(void *arg __unused)
{
if (tsc_is_invariant)
return;
tsc_post_tag = EVENTHANDLER_REGISTER(cpufreq_post_change,
tsc_freq_changed, NULL, EVENTHANDLER_PRI_ANY);
}
SYSINIT(hook_tsc_freq, SI_SUB_CONFIGURE, SI_ORDER_ANY, hook_tsc_freq, NULL);
static struct {
const char *vm_cpuid;
int vm_guest;
void (*init)(void);
} vm_cpuids[] = {
{ "XenVMMXenVMM", VM_GUEST_XEN,
#ifdef XENHVM
&xen_early_init,
#endif
},
{ "Microsoft Hv", VM_GUEST_HV },
{ "VMwareVMware", VM_GUEST_VMWARE },
{ "KVMKVMKVM", VM_GUEST_KVM },
{ "bhyve bhyve ", VM_GUEST_BHYVE },
{ "VBoxVBoxVBox", VM_GUEST_VBOX },
{ "___ NVMM ___", VM_GUEST_NVMM },
};
static void
identify_hypervisor_cpuid_base(void)
{
void (*init_fn)(void) = NULL;
u_int leaf, regs[4];
int i;
for (leaf = 0x40000000; leaf < 0x40010000; leaf += 0x100) {
do_cpuid(leaf, regs);
if (regs[0] == 0 && regs[1] == 0x4b4d564b &&
regs[2] == 0x564b4d56 && regs[3] == 0x0000004d)
regs[0] = leaf + 1;
if (regs[0] >= leaf) {
enum VM_GUEST prev_vm_guest = vm_guest;
for (i = 0; i < nitems(vm_cpuids); i++)
if (strncmp((const char *)®s[1],
vm_cpuids[i].vm_cpuid, 12) == 0) {
vm_guest = vm_cpuids[i].vm_guest;
init_fn = vm_cpuids[i].init;
break;
}
if (vm_guest != prev_vm_guest || leaf == 0x40000000) {
hv_base = leaf;
hv_high = regs[0];
((u_int *)&hv_vendor)[0] = regs[1];
((u_int *)&hv_vendor)[1] = regs[2];
((u_int *)&hv_vendor)[2] = regs[3];
hv_vendor[12] = '\0';
if (vm_guest != VM_GUEST_VM &&
vm_guest != VM_GUEST_HV)
break;
}
}
}
if (init_fn != NULL)
init_fn();
}
void
identify_hypervisor(void)
{
u_int regs[4];
char *p;
TSENTER();
if (cpu_feature2 & CPUID2_HV) {
vm_guest = VM_GUEST_VM;
identify_hypervisor_cpuid_base();
if (*hv_vendor != '\0') {
TSEXIT();
return;
}
}
p = kern_getenv("smbios.system.serial");
if (p != NULL) {
if (strncmp(p, "VMware-", 7) == 0 || strncmp(p, "VMW", 3) == 0) {
vmware_hvcall(0, VMW_HVCMD_GETVERSION,
VMW_HVCMD_DEFAULT_PARAM, regs);
if (regs[1] == VMW_HVMAGIC) {
vm_guest = VM_GUEST_VMWARE;
freeenv(p);
TSEXIT();
return;
}
}
freeenv(p);
}
TSEXIT();
}
bool
fix_cpuid(void)
{
uint64_t msr;
if (cpu_vendor_id == CPU_VENDOR_INTEL &&
((CPUID_TO_FAMILY(cpu_id) == 0xf &&
CPUID_TO_MODEL(cpu_id) >= 0x3) ||
(CPUID_TO_FAMILY(cpu_id) == 0x6 &&
CPUID_TO_MODEL(cpu_id) >= 0xe))) {
msr = rdmsr(MSR_IA32_MISC_ENABLE);
if ((msr & IA32_MISC_EN_LIMCPUID) != 0) {
msr &= ~IA32_MISC_EN_LIMCPUID;
wrmsr(MSR_IA32_MISC_ENABLE, msr);
return (true);
}
}
if (vm_guest == VM_GUEST_NO && cpu_vendor_id == CPU_VENDOR_AMD &&
CPUID_TO_FAMILY(cpu_id) == 0x15) {
msr = rdmsr(MSR_EXTFEATURES);
if ((msr & ((uint64_t)1 << 54)) == 0) {
msr |= (uint64_t)1 << 54;
wrmsr(MSR_EXTFEATURES, msr);
return (true);
}
}
return (false);
}
void
identify_cpu1(void)
{
u_int regs[4];
do_cpuid(0, regs);
cpu_high = regs[0];
((u_int *)&cpu_vendor)[0] = regs[1];
((u_int *)&cpu_vendor)[1] = regs[3];
((u_int *)&cpu_vendor)[2] = regs[2];
cpu_vendor[12] = '\0';
do_cpuid(1, regs);
cpu_id = regs[0];
cpu_procinfo = regs[1];
cpu_feature = regs[3];
cpu_feature2 = regs[2];
}
void
identify_cpu2(void)
{
u_int regs[4], cpu_stdext_disable, max_eax_l7;
if (cpu_high >= 6) {
cpuid_count(6, 0, regs);
cpu_power_eax = regs[0];
cpu_power_ebx = regs[1];
cpu_power_ecx = regs[2];
cpu_power_edx = regs[3];
}
if (cpu_high >= 7) {
cpuid_count(7, 0, regs);
cpu_stdext_feature = regs[1];
max_eax_l7 = regs[0];
cpu_stdext_disable = 0;
TUNABLE_INT_FETCH("hw.cpu_stdext_disable", &cpu_stdext_disable);
cpu_stdext_feature &= ~cpu_stdext_disable;
cpu_stdext_feature2 = regs[2];
cpu_stdext_feature3 = regs[3];
if ((cpu_stdext_feature3 & CPUID_STDEXT3_ARCH_CAP) != 0)
cpu_ia32_arch_caps = rdmsr(MSR_IA32_ARCH_CAP);
if (max_eax_l7 >= 1) {
cpuid_count(7, 1, regs);
cpu_stdext_feature4 = regs[0];
}
}
}
void
identify_cpu_ext_features(void)
{
u_int regs[4];
if (cpu_high >= 7) {
cpuid_count(7, 0, regs);
cpu_stdext_feature2 = regs[2];
cpu_stdext_feature3 = regs[3];
}
}
void
identify_cpu_fixup_bsp(void)
{
u_int regs[4];
cpu_vendor_id = find_cpu_vendor_id();
if (fix_cpuid()) {
do_cpuid(0, regs);
cpu_high = regs[0];
}
}
void
finishidentcpu(void)
{
u_int regs[4];
#ifdef __i386__
u_char ccr3;
#endif
identify_cpu_fixup_bsp();
if (cpu_high >= 5 && (cpu_feature2 & CPUID2_MON) != 0) {
do_cpuid(5, regs);
cpu_mon_mwait_flags = regs[2];
cpu_mon_mwait_edx = regs[3];
cpu_mon_min_size = regs[0] & CPUID5_MON_MIN_SIZE;
cpu_mon_max_size = regs[1] & CPUID5_MON_MAX_SIZE;
}
identify_cpu2();
#ifdef __i386__
if (cpu_high > 0 &&
(cpu_vendor_id == CPU_VENDOR_INTEL ||
cpu_vendor_id == CPU_VENDOR_AMD ||
cpu_vendor_id == CPU_VENDOR_HYGON ||
cpu_vendor_id == CPU_VENDOR_TRANSMETA ||
cpu_vendor_id == CPU_VENDOR_CENTAUR ||
cpu_vendor_id == CPU_VENDOR_NSC)) {
do_cpuid(0x80000000, regs);
if (regs[0] >= 0x80000000)
cpu_exthigh = regs[0];
}
#else
if (cpu_vendor_id == CPU_VENDOR_INTEL ||
cpu_vendor_id == CPU_VENDOR_AMD ||
cpu_vendor_id == CPU_VENDOR_HYGON ||
cpu_vendor_id == CPU_VENDOR_CENTAUR) {
do_cpuid(0x80000000, regs);
cpu_exthigh = regs[0];
}
#endif
if (cpu_exthigh >= 0x80000001) {
do_cpuid(0x80000001, regs);
amd_feature = regs[3] & ~(cpu_feature & 0x0183f3ff);
amd_feature2 = regs[2];
}
if (cpu_exthigh >= 0x80000007) {
do_cpuid(0x80000007, regs);
amd_rascap = regs[1];
amd_pminfo = regs[3];
}
if (cpu_exthigh >= 0x80000008) {
do_cpuid(0x80000008, regs);
cpu_maxphyaddr = regs[0] & 0xff;
amd_extended_feature_extensions = regs[1];
cpu_procinfo2 = regs[2];
cpu_procinfo3 = regs[3];
} else {
cpu_maxphyaddr = (cpu_feature & CPUID_PAE) != 0 ? 36 : 32;
}
#ifdef __i386__
if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
if (cpu == CPU_486) {
if (identblue() == IDENTBLUE_IBMCPU) {
strcpy(cpu_vendor, "IBM");
cpu_vendor_id = CPU_VENDOR_IBM;
cpu = CPU_BLUE;
return;
}
}
switch (cpu_id & 0xf00) {
case 0x600:
identifycyrix();
cpu = CPU_M2;
break;
default:
identifycyrix();
switch (cyrix_did & 0x00f0) {
case 0x00:
case 0xf0:
cpu = CPU_486DLC;
break;
case 0x10:
cpu = CPU_CY486DX;
break;
case 0x20:
if ((cyrix_did & 0x000f) < 8)
cpu = CPU_M1;
else
cpu = CPU_M1SC;
break;
case 0x30:
cpu = CPU_M1;
break;
case 0x40:
cpu = CPU_M1SC;
break;
default:
cpu = CPU_M2;
ccr3 = read_cyrix_reg(CCR3);
write_cyrix_reg(CCR3, CCR3_MAPEN0);
write_cyrix_reg(CCR4, read_cyrix_reg(CCR4) | CCR4_CPUID);
write_cyrix_reg(CCR3, ccr3);
do_cpuid(0, regs);
cpu_high = regs[0];
do_cpuid(1, regs);
cpu_id = regs[0];
cpu_feature = regs[3];
break;
}
}
} else if (cpu == CPU_486 && *cpu_vendor == '\0') {
if (identblue() == IDENTBLUE_IBMCPU) {
strcpy(cpu_vendor, "IBM");
cpu_vendor_id = CPU_VENDOR_IBM;
cpu = CPU_BLUE;
return;
}
}
#endif
}
int
pti_get_default(void)
{
if (strcmp(cpu_vendor, AMD_VENDOR_ID) == 0 ||
strcmp(cpu_vendor, HYGON_VENDOR_ID) == 0)
return (0);
if ((cpu_ia32_arch_caps & IA32_ARCH_CAP_RDCL_NO) != 0)
return (0);
return (1);
}
static u_int
find_cpu_vendor_id(void)
{
int i;
for (i = 0; i < nitems(cpu_vendors); i++)
if (strcmp(cpu_vendor, cpu_vendors[i].vendor) == 0)
return (cpu_vendors[i].vendor_id);
return (0);
}
static void
print_AMD_assoc(int i)
{
if (i == 255)
printf(", fully associative\n");
else
printf(", %d-way associative\n", i);
}
static void
print_AMD_l2_assoc(int i)
{
switch (i & 0x0f) {
case 0: printf(", disabled/not present\n"); break;
case 1: printf(", direct mapped\n"); break;
case 2: printf(", 2-way associative\n"); break;
case 4: printf(", 4-way associative\n"); break;
case 6: printf(", 8-way associative\n"); break;
case 8: printf(", 16-way associative\n"); break;
case 15: printf(", fully associative\n"); break;
default: printf(", reserved configuration\n"); break;
}
}
static void
print_AMD_info(void)
{
#ifdef __i386__
uint64_t amd_whcr;
#endif
u_int regs[4];
if (cpu_exthigh >= 0x80000005) {
do_cpuid(0x80000005, regs);
printf("L1 2MB data TLB: %d entries", (regs[0] >> 16) & 0xff);
print_AMD_assoc(regs[0] >> 24);
printf("L1 2MB instruction TLB: %d entries", regs[0] & 0xff);
print_AMD_assoc((regs[0] >> 8) & 0xff);
printf("L1 4KB data TLB: %d entries", (regs[1] >> 16) & 0xff);
print_AMD_assoc(regs[1] >> 24);
printf("L1 4KB instruction TLB: %d entries", regs[1] & 0xff);
print_AMD_assoc((regs[1] >> 8) & 0xff);
printf("L1 data cache: %d kbytes", regs[2] >> 24);
printf(", %d bytes/line", regs[2] & 0xff);
printf(", %d lines/tag", (regs[2] >> 8) & 0xff);
print_AMD_assoc((regs[2] >> 16) & 0xff);
printf("L1 instruction cache: %d kbytes", regs[3] >> 24);
printf(", %d bytes/line", regs[3] & 0xff);
printf(", %d lines/tag", (regs[3] >> 8) & 0xff);
print_AMD_assoc((regs[3] >> 16) & 0xff);
}
if (cpu_exthigh >= 0x80000006) {
do_cpuid(0x80000006, regs);
if ((regs[0] >> 16) != 0) {
printf("L2 2MB data TLB: %d entries",
(regs[0] >> 16) & 0xfff);
print_AMD_l2_assoc(regs[0] >> 28);
printf("L2 2MB instruction TLB: %d entries",
regs[0] & 0xfff);
print_AMD_l2_assoc((regs[0] >> 28) & 0xf);
} else {
printf("L2 2MB unified TLB: %d entries",
regs[0] & 0xfff);
print_AMD_l2_assoc((regs[0] >> 28) & 0xf);
}
if ((regs[1] >> 16) != 0) {
printf("L2 4KB data TLB: %d entries",
(regs[1] >> 16) & 0xfff);
print_AMD_l2_assoc(regs[1] >> 28);
printf("L2 4KB instruction TLB: %d entries",
(regs[1] >> 16) & 0xfff);
print_AMD_l2_assoc((regs[1] >> 28) & 0xf);
} else {
printf("L2 4KB unified TLB: %d entries",
(regs[1] >> 16) & 0xfff);
print_AMD_l2_assoc((regs[1] >> 28) & 0xf);
}
printf("L2 unified cache: %d kbytes", regs[2] >> 16);
printf(", %d bytes/line", regs[2] & 0xff);
printf(", %d lines/tag", (regs[2] >> 8) & 0x0f);
print_AMD_l2_assoc((regs[2] >> 12) & 0x0f);
}
#ifdef __i386__
if (((cpu_id & 0xf00) == 0x500)
&& (((cpu_id & 0x0f0) > 0x80)
|| (((cpu_id & 0x0f0) == 0x80)
&& (cpu_id & 0x00f) > 0x07))) {
amd_whcr = rdmsr(0xc0000082);
if (!(amd_whcr & (0x3ff << 22))) {
printf("Write Allocate Disable\n");
} else {
printf("Write Allocate Enable Limit: %dM bytes\n",
(u_int32_t)((amd_whcr & (0x3ff << 22)) >> 22) * 4);
printf("Write Allocate 15-16M bytes: %s\n",
(amd_whcr & (1 << 16)) ? "Enable" : "Disable");
}
} else if (((cpu_id & 0xf00) == 0x500)
&& ((cpu_id & 0x0f0) > 0x50)) {
amd_whcr = rdmsr(0xc0000082);
if (!(amd_whcr & (0x7f << 1))) {
printf("Write Allocate Disable\n");
} else {
printf("Write Allocate Enable Limit: %dM bytes\n",
(u_int32_t)((amd_whcr & (0x7f << 1)) >> 1) * 4);
printf("Write Allocate 15-16M bytes: %s\n",
(amd_whcr & 0x0001) ? "Enable" : "Disable");
printf("Hardware Write Allocate Control: %s\n",
(amd_whcr & 0x0100) ? "Enable" : "Disable");
}
}
#endif
if (CPUID_TO_FAMILY(cpu_id) == 0xf && CPUID_TO_MODEL(cpu_id) >= 0x20 &&
CPUID_TO_MODEL(cpu_id) <= 0x3f)
printf("WARNING: This architecture revision has known SMP "
"hardware bugs which may cause random instability\n");
}
static void
print_INTEL_info(void)
{
u_int regs[4];
u_int rounds, regnum;
u_int nwaycode, nway;
if (cpu_high >= 2) {
rounds = 0;
do {
do_cpuid(0x2, regs);
if (rounds == 0 && (rounds = (regs[0] & 0xff)) == 0)
break;
for (regnum = 0; regnum <= 3; ++regnum) {
if (regs[regnum] & (1<<31))
continue;
if (regnum != 0)
print_INTEL_TLB(regs[regnum] & 0xff);
print_INTEL_TLB((regs[regnum] >> 8) & 0xff);
print_INTEL_TLB((regs[regnum] >> 16) & 0xff);
print_INTEL_TLB((regs[regnum] >> 24) & 0xff);
}
} while (--rounds > 0);
}
if (cpu_exthigh >= 0x80000006) {
do_cpuid(0x80000006, regs);
nwaycode = (regs[2] >> 12) & 0x0f;
if (nwaycode >= 0x02 && nwaycode <= 0x08)
nway = 1 << (nwaycode / 2);
else
nway = 0;
printf("L2 cache: %u kbytes, %u-way associative, %u bytes/line\n",
(regs[2] >> 16) & 0xffff, nway, regs[2] & 0xff);
}
}
static void
print_INTEL_TLB(u_int data)
{
switch (data) {
case 0x0:
case 0x40:
default:
break;
case 0x1:
printf("Instruction TLB: 4 KB pages, 4-way set associative, 32 entries\n");
break;
case 0x2:
printf("Instruction TLB: 4 MB pages, fully associative, 2 entries\n");
break;
case 0x3:
printf("Data TLB: 4 KB pages, 4-way set associative, 64 entries\n");
break;
case 0x4:
printf("Data TLB: 4 MB Pages, 4-way set associative, 8 entries\n");
break;
case 0x6:
printf("1st-level instruction cache: 8 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x8:
printf("1st-level instruction cache: 16 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x9:
printf("1st-level instruction cache: 32 KB, 4-way set associative, 64 byte line size\n");
break;
case 0xa:
printf("1st-level data cache: 8 KB, 2-way set associative, 32 byte line size\n");
break;
case 0xb:
printf("Instruction TLB: 4 MByte pages, 4-way set associative, 4 entries\n");
break;
case 0xc:
printf("1st-level data cache: 16 KB, 4-way set associative, 32 byte line size\n");
break;
case 0xd:
printf("1st-level data cache: 16 KBytes, 4-way set associative, 64 byte line size");
break;
case 0xe:
printf("1st-level data cache: 24 KBytes, 6-way set associative, 64 byte line size\n");
break;
case 0x1d:
printf("2nd-level cache: 128 KBytes, 2-way set associative, 64 byte line size\n");
break;
case 0x21:
printf("2nd-level cache: 256 KBytes, 8-way set associative, 64 byte line size\n");
break;
case 0x22:
printf("3rd-level cache: 512 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x23:
printf("3rd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x24:
printf("2nd-level cache: 1 MBytes, 16-way set associative, 64 byte line size\n");
break;
case 0x25:
printf("3rd-level cache: 2 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x29:
printf("3rd-level cache: 4 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x2c:
printf("1st-level data cache: 32 KB, 8-way set associative, 64 byte line size\n");
break;
case 0x30:
printf("1st-level instruction cache: 32 KB, 8-way set associative, 64 byte line size\n");
break;
case 0x39:
printf("2nd-level cache: 128 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x3b:
printf("2nd-level cache: 128 KB, 2-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x3c:
printf("2nd-level cache: 256 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x41:
printf("2nd-level cache: 128 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x42:
printf("2nd-level cache: 256 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x43:
printf("2nd-level cache: 512 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x44:
printf("2nd-level cache: 1 MB, 4-way set associative, 32 byte line size\n");
break;
case 0x45:
printf("2nd-level cache: 2 MB, 4-way set associative, 32 byte line size\n");
break;
case 0x46:
printf("3rd-level cache: 4 MB, 4-way set associative, 64 byte line size\n");
break;
case 0x47:
printf("3rd-level cache: 8 MB, 8-way set associative, 64 byte line size\n");
break;
case 0x48:
printf("2nd-level cache: 3MByte, 12-way set associative, 64 byte line size\n");
break;
case 0x49:
if (CPUID_TO_FAMILY(cpu_id) == 0xf &&
CPUID_TO_MODEL(cpu_id) == 0x6)
printf("3rd-level cache: 4MB, 16-way set associative, 64-byte line size\n");
else
printf("2nd-level cache: 4 MByte, 16-way set associative, 64 byte line size");
break;
case 0x4a:
printf("3rd-level cache: 6MByte, 12-way set associative, 64 byte line size\n");
break;
case 0x4b:
printf("3rd-level cache: 8MByte, 16-way set associative, 64 byte line size\n");
break;
case 0x4c:
printf("3rd-level cache: 12MByte, 12-way set associative, 64 byte line size\n");
break;
case 0x4d:
printf("3rd-level cache: 16MByte, 16-way set associative, 64 byte line size\n");
break;
case 0x4e:
printf("2nd-level cache: 6MByte, 24-way set associative, 64 byte line size\n");
break;
case 0x4f:
printf("Instruction TLB: 4 KByte pages, 32 entries\n");
break;
case 0x50:
printf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 64 entries\n");
break;
case 0x51:
printf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 128 entries\n");
break;
case 0x52:
printf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 256 entries\n");
break;
case 0x55:
printf("Instruction TLB: 2-MByte or 4-MByte pages, fully associative, 7 entries\n");
break;
case 0x56:
printf("Data TLB0: 4 MByte pages, 4-way set associative, 16 entries\n");
break;
case 0x57:
printf("Data TLB0: 4 KByte pages, 4-way associative, 16 entries\n");
break;
case 0x59:
printf("Data TLB0: 4 KByte pages, fully associative, 16 entries\n");
break;
case 0x5a:
printf("Data TLB0: 2-MByte or 4 MByte pages, 4-way set associative, 32 entries\n");
break;
case 0x5b:
printf("Data TLB: 4 KB or 4 MB pages, fully associative, 64 entries\n");
break;
case 0x5c:
printf("Data TLB: 4 KB or 4 MB pages, fully associative, 128 entries\n");
break;
case 0x5d:
printf("Data TLB: 4 KB or 4 MB pages, fully associative, 256 entries\n");
break;
case 0x60:
printf("1st-level data cache: 16 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x61:
printf("Instruction TLB: 4 KByte pages, fully associative, 48 entries\n");
break;
case 0x63:
printf("Data TLB: 2 MByte or 4 MByte pages, 4-way set associative, 32 entries and a separate array with 1 GByte pages, 4-way set associative, 4 entries\n");
break;
case 0x64:
printf("Data TLB: 4 KBytes pages, 4-way set associative, 512 entries\n");
break;
case 0x66:
printf("1st-level data cache: 8 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x67:
printf("1st-level data cache: 16 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x68:
printf("1st-level data cache: 32 KB, 4 way set associative, sectored cache, 64 byte line size\n");
break;
case 0x6a:
printf("uTLB: 4KByte pages, 8-way set associative, 64 entries\n");
break;
case 0x6b:
printf("DTLB: 4KByte pages, 8-way set associative, 256 entries\n");
break;
case 0x6c:
printf("DTLB: 2M/4M pages, 8-way set associative, 128 entries\n");
break;
case 0x6d:
printf("DTLB: 1 GByte pages, fully associative, 16 entries\n");
break;
case 0x70:
printf("Trace cache: 12K-uops, 8-way set associative\n");
break;
case 0x71:
printf("Trace cache: 16K-uops, 8-way set associative\n");
break;
case 0x72:
printf("Trace cache: 32K-uops, 8-way set associative\n");
break;
case 0x76:
printf("Instruction TLB: 2M/4M pages, fully associative, 8 entries\n");
break;
case 0x78:
printf("2nd-level cache: 1 MB, 4-way set associative, 64-byte line size\n");
break;
case 0x79:
printf("2nd-level cache: 128 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7a:
printf("2nd-level cache: 256 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7b:
printf("2nd-level cache: 512 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7c:
printf("2nd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7d:
printf("2nd-level cache: 2-MB, 8-way set associative, 64-byte line size\n");
break;
case 0x7f:
printf("2nd-level cache: 512-KB, 2-way set associative, 64-byte line size\n");
break;
case 0x80:
printf("2nd-level cache: 512 KByte, 8-way set associative, 64-byte line size\n");
break;
case 0x82:
printf("2nd-level cache: 256 KB, 8-way set associative, 32 byte line size\n");
break;
case 0x83:
printf("2nd-level cache: 512 KB, 8-way set associative, 32 byte line size\n");
break;
case 0x84:
printf("2nd-level cache: 1 MB, 8-way set associative, 32 byte line size\n");
break;
case 0x85:
printf("2nd-level cache: 2 MB, 8-way set associative, 32 byte line size\n");
break;
case 0x86:
printf("2nd-level cache: 512 KB, 4-way set associative, 64 byte line size\n");
break;
case 0x87:
printf("2nd-level cache: 1 MB, 8-way set associative, 64 byte line size\n");
break;
case 0xa0:
printf("DTLB: 4k pages, fully associative, 32 entries\n");
break;
case 0xb0:
printf("Instruction TLB: 4 KB Pages, 4-way set associative, 128 entries\n");
break;
case 0xb1:
printf("Instruction TLB: 2M pages, 4-way, 8 entries or 4M pages, 4-way, 4 entries\n");
break;
case 0xb2:
printf("Instruction TLB: 4KByte pages, 4-way set associative, 64 entries\n");
break;
case 0xb3:
printf("Data TLB: 4 KB Pages, 4-way set associative, 128 entries\n");
break;
case 0xb4:
printf("Data TLB1: 4 KByte pages, 4-way associative, 256 entries\n");
break;
case 0xb5:
printf("Instruction TLB: 4KByte pages, 8-way set associative, 64 entries\n");
break;
case 0xb6:
printf("Instruction TLB: 4KByte pages, 8-way set associative, 128 entries\n");
break;
case 0xba:
printf("Data TLB1: 4 KByte pages, 4-way associative, 64 entries\n");
break;
case 0xc0:
printf("Data TLB: 4 KByte and 4 MByte pages, 4-way associative, 8 entries\n");
break;
case 0xc1:
printf("Shared 2nd-Level TLB: 4 KByte/2MByte pages, 8-way associative, 1024 entries\n");
break;
case 0xc2:
printf("DTLB: 4 KByte/2 MByte pages, 4-way associative, 16 entries\n");
break;
case 0xc3:
printf("Shared 2nd-Level TLB: 4 KByte /2 MByte pages, 6-way associative, 1536 entries. Also 1GBbyte pages, 4-way, 16 entries\n");
break;
case 0xc4:
printf("DTLB: 2M/4M Byte pages, 4-way associative, 32 entries\n");
break;
case 0xca:
printf("Shared 2nd-Level TLB: 4 KByte pages, 4-way associative, 512 entries\n");
break;
case 0xd0:
printf("3rd-level cache: 512 KByte, 4-way set associative, 64 byte line size\n");
break;
case 0xd1:
printf("3rd-level cache: 1 MByte, 4-way set associative, 64 byte line size\n");
break;
case 0xd2:
printf("3rd-level cache: 2 MByte, 4-way set associative, 64 byte line size\n");
break;
case 0xd6:
printf("3rd-level cache: 1 MByte, 8-way set associative, 64 byte line size\n");
break;
case 0xd7:
printf("3rd-level cache: 2 MByte, 8-way set associative, 64 byte line size\n");
break;
case 0xd8:
printf("3rd-level cache: 4 MByte, 8-way set associative, 64 byte line size\n");
break;
case 0xdc:
printf("3rd-level cache: 1.5 MByte, 12-way set associative, 64 byte line size\n");
break;
case 0xdd:
printf("3rd-level cache: 3 MByte, 12-way set associative, 64 byte line size\n");
break;
case 0xde:
printf("3rd-level cache: 6 MByte, 12-way set associative, 64 byte line size\n");
break;
case 0xe2:
printf("3rd-level cache: 2 MByte, 16-way set associative, 64 byte line size\n");
break;
case 0xe3:
printf("3rd-level cache: 4 MByte, 16-way set associative, 64 byte line size\n");
break;
case 0xe4:
printf("3rd-level cache: 8 MByte, 16-way set associative, 64 byte line size\n");
break;
case 0xea:
printf("3rd-level cache: 12MByte, 24-way set associative, 64 byte line size\n");
break;
case 0xeb:
printf("3rd-level cache: 18MByte, 24-way set associative, 64 byte line size\n");
break;
case 0xec:
printf("3rd-level cache: 24MByte, 24-way set associative, 64 byte line size\n");
break;
case 0xf0:
printf("64-Byte prefetching\n");
break;
case 0xf1:
printf("128-Byte prefetching\n");
break;
}
}
static void
print_svm_info(void)
{
u_int features, regs[4];
uint64_t msr;
int comma;
printf("\n SVM: ");
do_cpuid(0x8000000A, regs);
features = regs[3];
msr = rdmsr(MSR_VM_CR);
if ((msr & VM_CR_SVMDIS) == VM_CR_SVMDIS)
printf("(disabled in BIOS) ");
if (!bootverbose) {
comma = 0;
if (features & (1 << 0)) {
printf("%sNP", comma ? "," : "");
comma = 1;
}
if (features & (1 << 3)) {
printf("%sNRIP", comma ? "," : "");
comma = 1;
}
if (features & (1 << 5)) {
printf("%sVClean", comma ? "," : "");
comma = 1;
}
if (features & (1 << 6)) {
printf("%sAFlush", comma ? "," : "");
comma = 1;
}
if (features & (1 << 7)) {
printf("%sDAssist", comma ? "," : "");
comma = 1;
}
printf("%sNAsids=%d", comma ? "," : "", regs[1]);
return;
}
printf("Features=0x%b", features,
"\020"
"\001NP"
"\002LbrVirt"
"\003SVML"
"\004NRIPS"
"\005TscRateMsr"
"\006VmcbClean"
"\007FlushByAsid"
"\010DecodeAssist"
"\011<b8>"
"\012<b9>"
"\013PauseFilter"
"\014EncryptedMcodePatch"
"\015PauseFilterThreshold"
"\016AVIC"
"\017<b14>"
"\020V_VMSAVE_VMLOAD"
"\021vGIF"
"\022GMET"
"\023<b18>"
"\024<b19>"
"\025GuesSpecCtl"
"\026<b21>"
"\027<b22>"
"\030<b23>"
"\031<b24>"
"\032<b25>"
"\033<b26>"
"\034<b27>"
"\035<b28>"
"\036<b29>"
"\037<b30>"
"\040<b31>"
);
printf("\nRevision=%d, ASIDs=%d", regs[0] & 0xff, regs[1]);
}
#ifdef __i386__
static void
print_transmeta_info(void)
{
u_int regs[4], nreg = 0;
do_cpuid(0x80860000, regs);
nreg = regs[0];
if (nreg >= 0x80860001) {
do_cpuid(0x80860001, regs);
printf(" Processor revision %u.%u.%u.%u\n",
(regs[1] >> 24) & 0xff,
(regs[1] >> 16) & 0xff,
(regs[1] >> 8) & 0xff,
regs[1] & 0xff);
}
if (nreg >= 0x80860002) {
do_cpuid(0x80860002, regs);
printf(" Code Morphing Software revision %u.%u.%u-%u-%u\n",
(regs[1] >> 24) & 0xff,
(regs[1] >> 16) & 0xff,
(regs[1] >> 8) & 0xff,
regs[1] & 0xff,
regs[2]);
}
if (nreg >= 0x80860006) {
char info[65];
do_cpuid(0x80860003, (u_int*) &info[0]);
do_cpuid(0x80860004, (u_int*) &info[16]);
do_cpuid(0x80860005, (u_int*) &info[32]);
do_cpuid(0x80860006, (u_int*) &info[48]);
info[64] = 0;
printf(" %s\n", info);
}
}
#endif
static void
print_via_padlock_info(void)
{
u_int regs[4];
do_cpuid(0xc0000001, regs);
printf("\n VIA Padlock Features=0x%b", regs[3],
"\020"
"\003RNG"
"\007AES"
"\011AES-CTR"
"\013SHA1,SHA256"
"\015RSA"
);
}
static uint32_t
vmx_settable(uint64_t basic, int msr, int true_msr)
{
uint64_t val;
if (basic & (1ULL << 55))
val = rdmsr(true_msr);
else
val = rdmsr(msr);
return (val >> 32);
}
static void
print_vmx_info(void)
{
uint64_t basic, msr;
uint32_t entry, exit, mask, pin, proc, proc2;
int comma;
printf("\n VT-x: ");
msr = rdmsr(MSR_IA32_FEATURE_CONTROL);
if (!(msr & IA32_FEATURE_CONTROL_VMX_EN))
printf("(disabled in BIOS) ");
basic = rdmsr(MSR_VMX_BASIC);
pin = vmx_settable(basic, MSR_VMX_PINBASED_CTLS,
MSR_VMX_TRUE_PINBASED_CTLS);
proc = vmx_settable(basic, MSR_VMX_PROCBASED_CTLS,
MSR_VMX_TRUE_PROCBASED_CTLS);
if (proc & PROCBASED_SECONDARY_CONTROLS)
proc2 = vmx_settable(basic, MSR_VMX_PROCBASED_CTLS2,
MSR_VMX_PROCBASED_CTLS2);
else
proc2 = 0;
exit = vmx_settable(basic, MSR_VMX_EXIT_CTLS, MSR_VMX_TRUE_EXIT_CTLS);
entry = vmx_settable(basic, MSR_VMX_ENTRY_CTLS, MSR_VMX_TRUE_ENTRY_CTLS);
if (!bootverbose) {
comma = 0;
if (exit & VM_EXIT_SAVE_PAT && exit & VM_EXIT_LOAD_PAT &&
entry & VM_ENTRY_LOAD_PAT) {
printf("%sPAT", comma ? "," : "");
comma = 1;
}
if (proc & PROCBASED_HLT_EXITING) {
printf("%sHLT", comma ? "," : "");
comma = 1;
}
if (proc & PROCBASED_MTF) {
printf("%sMTF", comma ? "," : "");
comma = 1;
}
if (proc & PROCBASED_PAUSE_EXITING) {
printf("%sPAUSE", comma ? "," : "");
comma = 1;
}
if (proc2 & PROCBASED2_ENABLE_EPT) {
printf("%sEPT", comma ? "," : "");
comma = 1;
}
if (proc2 & PROCBASED2_UNRESTRICTED_GUEST) {
printf("%sUG", comma ? "," : "");
comma = 1;
}
if (proc2 & PROCBASED2_ENABLE_VPID) {
printf("%sVPID", comma ? "," : "");
comma = 1;
}
if (proc & PROCBASED_USE_TPR_SHADOW &&
proc2 & PROCBASED2_VIRTUALIZE_APIC_ACCESSES &&
proc2 & PROCBASED2_VIRTUALIZE_X2APIC_MODE &&
proc2 & PROCBASED2_APIC_REGISTER_VIRTUALIZATION &&
proc2 & PROCBASED2_VIRTUAL_INTERRUPT_DELIVERY) {
printf("%sVID", comma ? "," : "");
comma = 1;
if (pin & PINBASED_POSTED_INTERRUPT)
printf(",PostIntr");
}
return;
}
mask = basic >> 32;
printf("Basic Features=0x%b", mask,
"\020"
"\02132PA"
"\022SMM"
"\027INS/OUTS"
"\030TRUE"
);
printf("\n Pin-Based Controls=0x%b", pin,
"\020"
"\001ExtINT"
"\004NMI"
"\006VNMI"
"\007PreTmr"
"\010PostIntr"
);
printf("\n Primary Processor Controls=0x%b", proc,
"\020"
"\003INTWIN"
"\004TSCOff"
"\010HLT"
"\012INVLPG"
"\013MWAIT"
"\014RDPMC"
"\015RDTSC"
"\020CR3-LD"
"\021CR3-ST"
"\024CR8-LD"
"\025CR8-ST"
"\026TPR"
"\027NMIWIN"
"\030MOV-DR"
"\031IO"
"\032IOmap"
"\034MTF"
"\035MSRmap"
"\036MONITOR"
"\037PAUSE"
);
if (proc & PROCBASED_SECONDARY_CONTROLS)
printf("\n Secondary Processor Controls=0x%b", proc2,
"\020"
"\001APIC"
"\002EPT"
"\003DT"
"\004RDTSCP"
"\005x2APIC"
"\006VPID"
"\007WBINVD"
"\010UG"
"\011APIC-reg"
"\012VID"
"\013PAUSE-loop"
"\014RDRAND"
"\015INVPCID"
"\016VMFUNC"
"\017VMCS"
"\020EPT#VE"
"\021XSAVES"
);
printf("\n Exit Controls=0x%b", exit,
"\020"
"\003DR"
"\015PERF"
"\020AckInt"
"\023PAT-SV"
"\024PAT-LD"
"\025EFER-SV"
"\026EFER-LD"
"\027PTMR-SV"
);
printf("\n Entry Controls=0x%b", entry,
"\020"
"\003DR"
"\016PERF"
"\017PAT"
"\020EFER"
);
if (proc & PROCBASED_SECONDARY_CONTROLS &&
(proc2 & (PROCBASED2_ENABLE_EPT | PROCBASED2_ENABLE_VPID)) != 0) {
msr = rdmsr(MSR_VMX_EPT_VPID_CAP);
mask = msr;
printf("\n EPT Features=0x%b", mask,
"\020"
"\001XO"
"\007PW4"
"\011UC"
"\017WB"
"\0212M"
"\0221G"
"\025INVEPT"
"\026AD"
"\032single"
"\033all"
);
mask = msr >> 32;
printf("\n VPID Features=0x%b", mask,
"\020"
"\001INVVPID"
"\011individual"
"\012single"
"\013all"
"\014single-globals"
);
}
}
static void
print_hypervisor_info(void)
{
if (*hv_vendor != '\0')
printf("Hypervisor: Origin = \"%s\"\n", hv_vendor);
}
vm_paddr_t
cpu_getmaxphyaddr(void)
{
#if defined(__i386__)
if (!pae_mode)
return (0xffffffff);
#endif
return ((1ULL << cpu_maxphyaddr) - 1);
}