[kernel] Add in_hv cpu "feature" flag

Reformat the cpu_features.inc file and add the `in_hv` feature that is
supposedly set by hypervisors when running in emulation. QEMU does not
set it.

Tags: cpuid
This commit is contained in:
Justin C. Miller
2020-06-01 23:33:30 -07:00
parent ea2a3e6f16
commit a5f72edf82
2 changed files with 28 additions and 20 deletions

View File

@@ -90,13 +90,13 @@ cpu_id::validate()
if (leaf != feat_leaf || sub != feat_sub) { \ if (leaf != feat_leaf || sub != feat_sub) { \
leaf = feat_leaf; sub = feat_sub; r = get(leaf, sub); \ leaf = feat_leaf; sub = feat_sub; r = get(leaf, sub); \
} \ } \
if (r.regname & (1 << bit)) \ if (r.regname & (1ull << bit)) \
m_features |= (1 << static_cast<uint64_t>(cpu_feature::name)); \ m_features |= (1ull << static_cast<uint64_t>(cpu_feature::name)); \
log::debug(logs::boot, " Supports %9s: %s", #name, (r.regname & (1<<bit)) ? "yes" : "no"); log::debug(logs::boot, " Supports %9s: %s", #name, (r.regname & (1ull << bit)) ? "yes" : "no");
#define CPU_FEATURE_REQ(name, feat_leaf, feat_sub, regname, bit) \ #define CPU_FEATURE_REQ(name, feat_leaf, feat_sub, regname, bit) \
CPU_FEATURE_OPT(name, feat_leaf, feat_sub, regname, bit); \ CPU_FEATURE_OPT(name, feat_leaf, feat_sub, regname, bit); \
if ((r.regname & (1 << bit)) == 0) { \ if ((r.regname & (1ull << bit)) == 0) { \
log::error(logs::boot, "CPU missing required feature " #name); \ log::error(logs::boot, "CPU missing required feature " #name); \
fail = true; \ fail = true; \
} }

View File

@@ -1,16 +1,24 @@
CPU_FEATURE_OPT(pcid, 0x00000001, 0, ecx, 17) CPU_FEATURE_OPT(pcid, 0x00000001, 0, ecx, 17)
CPU_FEATURE_OPT(x2apic, 0x00000001, 0, ecx, 21) CPU_FEATURE_OPT(x2apic, 0x00000001, 0, ecx, 21)
CPU_FEATURE_REQ(fpu, 0x00000001, 0, edx, 0) CPU_FEATURE_OPT(in_hv, 0x00000001, 0, ecx, 31)
CPU_FEATURE_REQ(pse, 0x00000001, 0, edx, 3)
CPU_FEATURE_OPT(tsc, 0x00000001, 0, edx, 4) CPU_FEATURE_REQ(fpu, 0x00000001, 0, edx, 0)
CPU_FEATURE_REQ(msr, 0x00000001, 0, edx, 5) CPU_FEATURE_REQ(pse, 0x00000001, 0, edx, 3)
CPU_FEATURE_REQ(apic, 0x00000001, 0, edx, 9) CPU_FEATURE_OPT(tsc, 0x00000001, 0, edx, 4)
CPU_FEATURE_REQ(pge, 0x00000001, 0, edx, 13) CPU_FEATURE_REQ(msr, 0x00000001, 0, edx, 5)
CPU_FEATURE_OPT(pat, 0x00000001, 0, edx, 16) CPU_FEATURE_REQ(apic, 0x00000001, 0, edx, 9)
CPU_FEATURE_REQ(fxsr, 0x00000001, 0, edx, 24) CPU_FEATURE_REQ(pge, 0x00000001, 0, edx, 13)
CPU_FEATURE_OPT(fsgsbase, 0x00000007, 0, ebx, 0) CPU_FEATURE_OPT(pat, 0x00000001, 0, edx, 16)
CPU_FEATURE_OPT(invpcid, 0x00000007, 0, ebx, 10) CPU_FEATURE_REQ(fxsr, 0x00000001, 0, edx, 24)
CPU_FEATURE_OPT(pku, 0x00000007, 0, ecx, 3)
CPU_FEATURE_REQ(syscall, 0x80000001, 0, edx, 11) CPU_FEATURE_OPT(fsgsbase, 0x00000007, 0, ebx, 0)
CPU_FEATURE_REQ(pdpe1gb, 0x80000001, 0, edx, 26) CPU_FEATURE_OPT(invpcid, 0x00000007, 0, ebx, 10)
CPU_FEATURE_OPT(extapic, 0x80000001, 0, ecx, 3)
CPU_FEATURE_OPT(pku, 0x00000007, 0, ecx, 3)
CPU_FEATURE_OPT(extapic, 0x80000001, 0, ecx, 3)
CPU_FEATURE_REQ(syscall, 0x80000001, 0, edx, 11)
CPU_FEATURE_REQ(pdpe1gb, 0x80000001, 0, edx, 26)
// vim: et