+ /* get processor signature and decode */
+ do_cpuid(1, cpuid_reg);
+ info_p->cpuid_signature = cpuid_reg[eax];
+ info_p->cpuid_stepping = bitfield(cpuid_reg[eax], 3, 0);
+ info_p->cpuid_model = bitfield(cpuid_reg[eax], 7, 4);
+ info_p->cpuid_family = bitfield(cpuid_reg[eax], 11, 8);
+ info_p->cpuid_type = bitfield(cpuid_reg[eax], 13, 12);
+ info_p->cpuid_extmodel = bitfield(cpuid_reg[eax], 19, 16);
+ info_p->cpuid_extfamily = bitfield(cpuid_reg[eax], 27, 20);
+ info_p->cpuid_brand = bitfield(cpuid_reg[ebx], 7, 0);
+ info_p->cpuid_features = quad(cpuid_reg[ecx], cpuid_reg[edx]);
+
+ /* Fold extensions into family/model */
+ if (info_p->cpuid_family == 0x0f)
+ info_p->cpuid_family += info_p->cpuid_extfamily;
+ if (info_p->cpuid_family == 0x0f || info_p->cpuid_family== 0x06)
+ info_p->cpuid_model += (info_p->cpuid_extmodel << 4);
+
+ if (info_p->cpuid_features & CPUID_FEATURE_HTT)
+ info_p->cpuid_logical_per_package =
+ bitfield(cpuid_reg[ebx], 23, 16);
+ else
+ info_p->cpuid_logical_per_package = 1;
+
+ if (max_extid >= 0x80000001) {
+ do_cpuid(0x80000001, cpuid_reg);
+ info_p->cpuid_extfeatures =
+ quad(cpuid_reg[ecx], cpuid_reg[edx]);
+ }
+
+ if (info_p->cpuid_extfeatures && CPUID_FEATURE_MONITOR) {
+ /*
+ * Extract the Monitor/Mwait Leaf info:
+ */
+ do_cpuid(5, cpuid_reg);
+ info_p->cpuid_mwait_linesize_min = cpuid_reg[eax];
+ info_p->cpuid_mwait_linesize_max = cpuid_reg[ebx];
+ info_p->cpuid_mwait_extensions = cpuid_reg[ecx];
+ info_p->cpuid_mwait_sub_Cstates = cpuid_reg[edx];
+
+ /*
+ * And the thermal and Power Leaf while we're at it:
+ */
+ do_cpuid(6, cpuid_reg);
+ info_p->cpuid_thermal_sensor =
+ bitfield(cpuid_reg[eax], 0, 0);
+ info_p->cpuid_thermal_dynamic_acceleration =
+ bitfield(cpuid_reg[eax], 1, 1);
+ info_p->cpuid_thermal_thresholds =
+ bitfield(cpuid_reg[ebx], 3, 0);
+ info_p->cpuid_thermal_ACNT_MCNT =
+ bitfield(cpuid_reg[ecx], 0, 0);
+
+ /*
+ * And the Architectural Performance Monitoring Leaf:
+ */
+ do_cpuid(0xa, cpuid_reg);
+ info_p->cpuid_arch_perf_version =
+ bitfield(cpuid_reg[eax], 7, 0);
+ info_p->cpuid_arch_perf_number =
+ bitfield(cpuid_reg[eax],15, 8);
+ info_p->cpuid_arch_perf_width =
+ bitfield(cpuid_reg[eax],23,16);
+ info_p->cpuid_arch_perf_events_number =
+ bitfield(cpuid_reg[eax],31,24);
+ info_p->cpuid_arch_perf_events =
+ cpuid_reg[ebx];
+ info_p->cpuid_arch_perf_fixed_number =
+ bitfield(cpuid_reg[edx], 4, 0);
+ info_p->cpuid_arch_perf_fixed_width =
+ bitfield(cpuid_reg[edx],12, 5);
+
+ }
+
+ return;
+}
+
+void
+cpuid_set_info(void)
+{
+ bzero((void *)&cpuid_cpu_info, sizeof(cpuid_cpu_info));
+
+ cpuid_set_generic_info(&cpuid_cpu_info);
+
+ /* verify we are running on a supported CPU */
+ if ((strncmp(CPUID_VID_INTEL, cpuid_cpu_info.cpuid_vendor,
+ min(strlen(CPUID_STRING_UNKNOWN) + 1,
+ sizeof(cpuid_cpu_info.cpuid_vendor)))) ||
+ (cpuid_cpu_info.cpuid_family != 6) ||
+ (cpuid_cpu_info.cpuid_model < 13))
+ panic("Unsupported CPU");
+
+ cpuid_cpu_info.cpuid_cpu_type = CPU_TYPE_X86;
+ cpuid_cpu_info.cpuid_cpu_subtype = CPU_SUBTYPE_X86_ARCH1;
+
+ cpuid_set_cache_info(&cpuid_cpu_info);
+
+ cpuid_cpu_info.cpuid_model_string = ""; /* deprecated */
+}
+
+static struct {
+ uint64_t mask;
+ const char *name;
+} feature_map[] = {
+ {CPUID_FEATURE_FPU, "FPU",},
+ {CPUID_FEATURE_VME, "VME",},
+ {CPUID_FEATURE_DE, "DE",},
+ {CPUID_FEATURE_PSE, "PSE",},
+ {CPUID_FEATURE_TSC, "TSC",},
+ {CPUID_FEATURE_MSR, "MSR",},
+ {CPUID_FEATURE_PAE, "PAE",},
+ {CPUID_FEATURE_MCE, "MCE",},
+ {CPUID_FEATURE_CX8, "CX8",},
+ {CPUID_FEATURE_APIC, "APIC",},
+ {CPUID_FEATURE_SEP, "SEP",},
+ {CPUID_FEATURE_MTRR, "MTRR",},
+ {CPUID_FEATURE_PGE, "PGE",},
+ {CPUID_FEATURE_MCA, "MCA",},
+ {CPUID_FEATURE_CMOV, "CMOV",},
+ {CPUID_FEATURE_PAT, "PAT",},
+ {CPUID_FEATURE_PSE36, "PSE36",},
+ {CPUID_FEATURE_PSN, "PSN",},
+ {CPUID_FEATURE_CLFSH, "CLFSH",},
+ {CPUID_FEATURE_DS, "DS",},
+ {CPUID_FEATURE_ACPI, "ACPI",},
+ {CPUID_FEATURE_MMX, "MMX",},
+ {CPUID_FEATURE_FXSR, "FXSR",},
+ {CPUID_FEATURE_SSE, "SSE",},
+ {CPUID_FEATURE_SSE2, "SSE2",},
+ {CPUID_FEATURE_SS, "SS",},
+ {CPUID_FEATURE_HTT, "HTT",},
+ {CPUID_FEATURE_TM, "TM",},
+ {CPUID_FEATURE_SSE3, "SSE3"},
+ {CPUID_FEATURE_MONITOR, "MON"},
+ {CPUID_FEATURE_DSCPL, "DSCPL"},
+ {CPUID_FEATURE_VMX, "VMX"},
+ {CPUID_FEATURE_SMX, "SMX"},
+ {CPUID_FEATURE_EST, "EST"},
+ {CPUID_FEATURE_TM2, "TM2"},
+ {CPUID_FEATURE_SSSE3, "SSSE3"},
+ {CPUID_FEATURE_CID, "CID"},
+ {CPUID_FEATURE_CX16, "CX16"},
+ {CPUID_FEATURE_xTPR, "TPR"},
+ {CPUID_FEATURE_PDCM, "PDCM"},
+ {CPUID_FEATURE_SSE4_1, "SSE4.1"},
+ {CPUID_FEATURE_SSE4_2, "SSE4.2"},
+ {CPUID_FEATURE_POPCNT, "POPCNT"},
+ {0, 0}
+},
+extfeature_map[] = {
+ {CPUID_EXTFEATURE_SYSCALL, "SYSCALL"},
+ {CPUID_EXTFEATURE_XD, "XD"},
+ {CPUID_EXTFEATURE_EM64T, "EM64T"},
+ {CPUID_EXTFEATURE_LAHF, "LAHF"},
+ {0, 0}
+};
+
+i386_cpu_info_t *
+cpuid_info(void)
+{
+ /* Set-up the cpuid_indo stucture lazily */
+ if (cpuid_cpu_infop == NULL) {
+ cpuid_set_info();
+ cpuid_cpu_infop = &cpuid_cpu_info;
+ }
+ return cpuid_cpu_infop;
+}
+
+char *
+cpuid_get_feature_names(uint64_t features, char *buf, unsigned buf_len)
+{
+ int len = -1;
+ char *p = buf;
+ int i;
+
+ for (i = 0; feature_map[i].mask != 0; i++) {
+ if ((features & feature_map[i].mask) == 0)
+ continue;
+ if (len > 0)
+ *p++ = ' ';
+ len = min(strlen(feature_map[i].name), (buf_len-1) - (p-buf));
+ if (len == 0)
+ break;
+ bcopy(feature_map[i].name, p, len);
+ p += len;
+ }
+ *p = '\0';
+ return buf;
+}
+
+char *
+cpuid_get_extfeature_names(uint64_t extfeatures, char *buf, unsigned buf_len)
+{
+ int len = -1;
+ char *p = buf;
+ int i;
+
+ for (i = 0; extfeature_map[i].mask != 0; i++) {
+ if ((extfeatures & extfeature_map[i].mask) == 0)
+ continue;
+ if (len > 0)
+ *p++ = ' ';
+ len = min(strlen(extfeature_map[i].name), (buf_len-1)-(p-buf));
+ if (len == 0)
+ break;
+ bcopy(extfeature_map[i].name, p, len);
+ p += len;
+ }
+ *p = '\0';
+ return buf;
+}
+
+
+#if CONFIG_NO_KPRINTF_STRINGS
+void
+cpuid_feature_display(
+ __unused const char *header)
+{
+}
+
+void
+cpuid_extfeature_display(
+ __unused const char *header)