1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

Kernel: Add Aarch64 CPU feature detection

This commit is contained in:
konrad 2023-01-08 00:01:25 +01:00 committed by Jelle Raaijmakers
parent 9f736d782c
commit 97dce5d001
4 changed files with 53 additions and 16 deletions

View file

@ -8,6 +8,12 @@
namespace Kernel { namespace Kernel {
CPUFeature::Type detect_cpu_features()
{
auto features = CPUFeature::Type(0u);
return features;
}
// https://developer.arm.com/downloads/-/exploration-tools/feature-names-for-a-profile // https://developer.arm.com/downloads/-/exploration-tools/feature-names-for-a-profile
StringView cpu_feature_to_name(CPUFeature::Type const& feature) StringView cpu_feature_to_name(CPUFeature::Type const& feature)
{ {
@ -1004,4 +1010,21 @@ StringView cpu_feature_to_description(CPUFeature::Type const& feature)
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
NonnullOwnPtr<KString> build_cpu_feature_names(CPUFeature::Type const& features)
{
StringBuilder builder;
bool first = true;
for (auto feature = CPUFeature::Type(1u); feature != CPUFeature::__End; feature <<= 1u) {
if (features.has_flag(feature)) {
if (first)
first = false;
else
MUST(builder.try_append(' '));
auto name = cpu_feature_to_name(feature);
MUST(builder.try_append(name));
}
}
return KString::must_create(builder.string_view());
}
} }

View file

@ -7,8 +7,11 @@
#pragma once #pragma once
#include <AK/ArbitrarySizedEnum.h> #include <AK/ArbitrarySizedEnum.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <AK/UFixedBigInt.h> #include <AK/UFixedBigInt.h>
#include <Kernel/Arch/aarch64/Registers.h>
#include <Kernel/KString.h>
#include <AK/Platform.h> #include <AK/Platform.h>
VALIDATE_IS_AARCH64() VALIDATE_IS_AARCH64()
@ -269,7 +272,9 @@ AK_MAKE_ARBITRARY_SIZED_ENUM(CPUFeature, u256,
__End = CPUFeature(1u) << 255u); __End = CPUFeature(1u) << 255u);
CPUFeature::Type detect_cpu_features();
StringView cpu_feature_to_name(CPUFeature::Type const&); StringView cpu_feature_to_name(CPUFeature::Type const&);
StringView cpu_feature_to_description(CPUFeature::Type const&); StringView cpu_feature_to_description(CPUFeature::Type const&);
NonnullOwnPtr<KString> build_cpu_feature_names(CPUFeature::Type const&);
} }

View file

@ -30,6 +30,7 @@ Processor* g_current_processor;
void Processor::initialize(u32 cpu) void Processor::initialize(u32 cpu)
{ {
VERIFY(g_current_processor == nullptr); VERIFY(g_current_processor == nullptr);
m_features = detect_cpu_features();
initialize_exceptions(cpu); initialize_exceptions(cpu);

View file

@ -12,6 +12,7 @@
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Arch/ProcessorSpecificDataID.h> #include <Kernel/Arch/ProcessorSpecificDataID.h>
#include <Kernel/Arch/aarch64/CPUID.h>
#include <Kernel/Arch/aarch64/Registers.h> #include <Kernel/Arch/aarch64/Registers.h>
#include <Kernel/VirtualAddress.h> #include <Kernel/VirtualAddress.h>
@ -136,6 +137,11 @@ public:
return false; return false;
} }
ALWAYS_INLINE bool has_feature(CPUFeature::Type const& feature) const
{
return m_features.has_flag(feature);
}
ALWAYS_INLINE static FlatPtr current_in_irq() ALWAYS_INLINE static FlatPtr current_in_irq()
{ {
return current().m_in_irq; return current().m_in_irq;
@ -277,6 +283,8 @@ public:
private: private:
Processor(Processor const&) = delete; Processor(Processor const&) = delete;
CPUFeature::Type m_features;
Thread* m_current_thread; Thread* m_current_thread;
Thread* m_idle_thread; Thread* m_idle_thread;
u32 m_in_critical { 0 }; u32 m_in_critical { 0 };