mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:57:44 +00:00
Kernel: Move hypervisor vendor ID string to ProcessorInfo
This will make it possible to expose it in /proc/cpuinfo. :^)
This commit is contained in:
parent
f6181cd47e
commit
8d96525b9d
3 changed files with 31 additions and 21 deletions
|
@ -21,6 +21,7 @@ public:
|
||||||
ProcessorInfo(Processor const& processor);
|
ProcessorInfo(Processor const& processor);
|
||||||
|
|
||||||
StringView vendor_id_string() const { return m_vendor_id_string->view(); }
|
StringView vendor_id_string() const { return m_vendor_id_string->view(); }
|
||||||
|
StringView hypervisor_vendor_id_string() const { return m_hypervisor_vendor_id_string->view(); }
|
||||||
StringView brand_string() const { return m_brand_string->view(); }
|
StringView brand_string() const { return m_brand_string->view(); }
|
||||||
StringView features_string() const { return m_features_string->view(); }
|
StringView features_string() const { return m_features_string->view(); }
|
||||||
u32 display_model() const { return m_display_model; }
|
u32 display_model() const { return m_display_model; }
|
||||||
|
@ -33,10 +34,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static NonnullOwnPtr<KString> build_vendor_id_string();
|
static NonnullOwnPtr<KString> build_vendor_id_string();
|
||||||
|
static NonnullOwnPtr<KString> build_hypervisor_vendor_id_string(Processor const&);
|
||||||
static NonnullOwnPtr<KString> build_brand_string();
|
static NonnullOwnPtr<KString> build_brand_string();
|
||||||
static NonnullOwnPtr<KString> build_features_string(Processor const&);
|
static NonnullOwnPtr<KString> build_features_string(Processor const&);
|
||||||
|
|
||||||
NonnullOwnPtr<KString> m_vendor_id_string;
|
NonnullOwnPtr<KString> m_vendor_id_string;
|
||||||
|
NonnullOwnPtr<KString> m_hypervisor_vendor_id_string;
|
||||||
NonnullOwnPtr<KString> m_brand_string;
|
NonnullOwnPtr<KString> m_brand_string;
|
||||||
NonnullOwnPtr<KString> m_features_string;
|
NonnullOwnPtr<KString> m_features_string;
|
||||||
u32 m_display_model { 0 };
|
u32 m_display_model { 0 };
|
||||||
|
|
|
@ -676,18 +676,10 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu)
|
||||||
UNMAP_AFTER_INIT void Processor::detect_hypervisor()
|
UNMAP_AFTER_INIT void Processor::detect_hypervisor()
|
||||||
{
|
{
|
||||||
CPUID hypervisor_leaf_range(0x40000000);
|
CPUID hypervisor_leaf_range(0x40000000);
|
||||||
|
auto hypervisor_vendor_id_string = m_info->hypervisor_vendor_id_string();
|
||||||
|
dmesgln("CPU[{}]: CPUID hypervisor signature '{}' ({:#x} {:#x} {:#x}), max leaf {:#x}", current_id(), hypervisor_vendor_id_string, hypervisor_leaf_range.ebx(), hypervisor_leaf_range.ecx(), hypervisor_leaf_range.edx(), hypervisor_leaf_range.eax());
|
||||||
|
|
||||||
// Get signature of hypervisor.
|
if (hypervisor_vendor_id_string == "Microsoft Hv"sv)
|
||||||
alignas(sizeof(u32)) char hypervisor_signature_buffer[13];
|
|
||||||
*reinterpret_cast<u32*>(hypervisor_signature_buffer) = hypervisor_leaf_range.ebx();
|
|
||||||
*reinterpret_cast<u32*>(hypervisor_signature_buffer + 4) = hypervisor_leaf_range.ecx();
|
|
||||||
*reinterpret_cast<u32*>(hypervisor_signature_buffer + 8) = hypervisor_leaf_range.edx();
|
|
||||||
hypervisor_signature_buffer[12] = '\0';
|
|
||||||
StringView hypervisor_signature(hypervisor_signature_buffer);
|
|
||||||
|
|
||||||
dmesgln("CPU[{}]: CPUID hypervisor signature '{}' ({:#x} {:#x} {:#x}), max leaf {:#x}", current_id(), hypervisor_signature, hypervisor_leaf_range.ebx(), hypervisor_leaf_range.ecx(), hypervisor_leaf_range.edx(), hypervisor_leaf_range.eax());
|
|
||||||
|
|
||||||
if (hypervisor_signature == "Microsoft Hv"sv)
|
|
||||||
detect_hypervisor_hyperv(hypervisor_leaf_range);
|
detect_hypervisor_hyperv(hypervisor_leaf_range);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Kernel {
|
||||||
|
|
||||||
ProcessorInfo::ProcessorInfo(Processor const& processor)
|
ProcessorInfo::ProcessorInfo(Processor const& processor)
|
||||||
: m_vendor_id_string(build_vendor_id_string())
|
: m_vendor_id_string(build_vendor_id_string())
|
||||||
|
, m_hypervisor_vendor_id_string(build_hypervisor_vendor_id_string(processor))
|
||||||
, m_brand_string(build_brand_string())
|
, m_brand_string(build_brand_string())
|
||||||
, m_features_string(build_features_string(processor))
|
, m_features_string(build_features_string(processor))
|
||||||
{
|
{
|
||||||
|
@ -35,21 +36,35 @@ ProcessorInfo::ProcessorInfo(Processor const& processor)
|
||||||
m_display_model = model;
|
m_display_model = model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void emit_u32(StringBuilder& builder, u32 value)
|
||||||
NonnullOwnPtr<KString> ProcessorInfo::build_vendor_id_string()
|
|
||||||
{
|
{
|
||||||
CPUID cpuid(0);
|
|
||||||
StringBuilder builder;
|
|
||||||
auto emit_u32 = [&](u32 value) {
|
|
||||||
builder.appendff("{:c}{:c}{:c}{:c}",
|
builder.appendff("{:c}{:c}{:c}{:c}",
|
||||||
value & 0xff,
|
value & 0xff,
|
||||||
(value >> 8) & 0xff,
|
(value >> 8) & 0xff,
|
||||||
(value >> 16) & 0xff,
|
(value >> 16) & 0xff,
|
||||||
(value >> 24) & 0xff);
|
(value >> 24) & 0xff);
|
||||||
};
|
};
|
||||||
emit_u32(cpuid.ebx());
|
|
||||||
emit_u32(cpuid.edx());
|
NonnullOwnPtr<KString> ProcessorInfo::build_vendor_id_string()
|
||||||
emit_u32(cpuid.ecx());
|
{
|
||||||
|
CPUID cpuid(0);
|
||||||
|
StringBuilder builder;
|
||||||
|
emit_u32(builder, cpuid.ebx());
|
||||||
|
emit_u32(builder, cpuid.edx());
|
||||||
|
emit_u32(builder, cpuid.ecx());
|
||||||
|
return KString::must_create(builder.string_view());
|
||||||
|
}
|
||||||
|
|
||||||
|
NonnullOwnPtr<KString> ProcessorInfo::build_hypervisor_vendor_id_string(Processor const& processor)
|
||||||
|
{
|
||||||
|
if (!processor.has_feature(CPUFeature::HYPERVISOR))
|
||||||
|
return KString::must_create({});
|
||||||
|
|
||||||
|
CPUID cpuid(0x40000000);
|
||||||
|
StringBuilder builder;
|
||||||
|
emit_u32(builder, cpuid.ebx());
|
||||||
|
emit_u32(builder, cpuid.ecx());
|
||||||
|
emit_u32(builder, cpuid.edx());
|
||||||
return KString::must_create(builder.string_view());
|
return KString::must_create(builder.string_view());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue