mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +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
Notes:
sideshowbarker
2024-07-17 14:30:40 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/8d96525b9d Pull-request: https://github.com/SerenityOS/serenity/pull/13482 Reviewed-by: https://github.com/bgianfo ✅
|
@ -21,6 +21,7 @@ public:
|
|||
ProcessorInfo(Processor const& processor);
|
||||
|
||||
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 features_string() const { return m_features_string->view(); }
|
||||
u32 display_model() const { return m_display_model; }
|
||||
|
@ -33,10 +34,12 @@ public:
|
|||
|
||||
private:
|
||||
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_features_string(Processor const&);
|
||||
|
||||
NonnullOwnPtr<KString> m_vendor_id_string;
|
||||
NonnullOwnPtr<KString> m_hypervisor_vendor_id_string;
|
||||
NonnullOwnPtr<KString> m_brand_string;
|
||||
NonnullOwnPtr<KString> m_features_string;
|
||||
u32 m_display_model { 0 };
|
||||
|
|
|
@ -676,18 +676,10 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu)
|
|||
UNMAP_AFTER_INIT void Processor::detect_hypervisor()
|
||||
{
|
||||
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.
|
||||
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)
|
||||
if (hypervisor_vendor_id_string == "Microsoft Hv"sv)
|
||||
detect_hypervisor_hyperv(hypervisor_leaf_range);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Kernel {
|
|||
|
||||
ProcessorInfo::ProcessorInfo(Processor const& processor)
|
||||
: 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_features_string(build_features_string(processor))
|
||||
{
|
||||
|
@ -35,21 +36,35 @@ ProcessorInfo::ProcessorInfo(Processor const& processor)
|
|||
m_display_model = model;
|
||||
}
|
||||
}
|
||||
static void emit_u32(StringBuilder& builder, u32 value)
|
||||
{
|
||||
builder.appendff("{:c}{:c}{:c}{:c}",
|
||||
value & 0xff,
|
||||
(value >> 8) & 0xff,
|
||||
(value >> 16) & 0xff,
|
||||
(value >> 24) & 0xff);
|
||||
};
|
||||
|
||||
NonnullOwnPtr<KString> ProcessorInfo::build_vendor_id_string()
|
||||
{
|
||||
CPUID cpuid(0);
|
||||
StringBuilder builder;
|
||||
auto emit_u32 = [&](u32 value) {
|
||||
builder.appendff("{:c}{:c}{:c}{:c}",
|
||||
value & 0xff,
|
||||
(value >> 8) & 0xff,
|
||||
(value >> 16) & 0xff,
|
||||
(value >> 24) & 0xff);
|
||||
};
|
||||
emit_u32(cpuid.ebx());
|
||||
emit_u32(cpuid.edx());
|
||||
emit_u32(cpuid.ecx());
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue