1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:48:11 +00:00

Kernel: Move feature string building to ProcessorInfo

Other than a dmesgln(), ProcessorInfo is the only user of this function
and is already responsible for building other CPUID-related strings.
This commit is contained in:
Linus Groh 2022-04-03 16:47:38 +01:00 committed by Andreas Kling
parent 53a95a5347
commit afce63fffc
4 changed files with 21 additions and 22 deletions

View file

@ -15,7 +15,7 @@ namespace Kernel {
ProcessorInfo::ProcessorInfo(Processor const& processor)
: m_vendor_id_string(build_vendor_id_string())
, m_brand_string(build_brand_string())
, m_features_string(processor.features_string())
, m_features_string(build_features_string(processor))
{
CPUID cpuid(1);
m_stepping = cpuid.eax() & 0xf;
@ -75,4 +75,20 @@ NonnullOwnPtr<KString> ProcessorInfo::build_brand_string()
return KString::must_create(buffer);
}
NonnullOwnPtr<KString> ProcessorInfo::build_features_string(Processor const& processor)
{
StringBuilder builder;
bool first = true;
for (auto feature = CPUFeature::Type(1u); feature != CPUFeature::__End; feature <<= 1u) {
if (processor.has_feature(feature)) {
if (first)
first = false;
else
MUST(builder.try_append(' '));
MUST(builder.try_append(cpu_feature_to_string_view(feature)));
}
}
return KString::must_create(builder.string_view());
}
}