1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

Kernel: Add a class to wrap aarch64 MIDR_EL1

We'll need part_num() to determine the MMIO address base. It's
0x3F000000 on rpi3 but 0xFE000000 on rpi4.
This commit is contained in:
Nico Weber 2021-09-12 09:42:27 -04:00 committed by Brian Gianforcaro
parent 2dc02607ed
commit 3c6ad4c7db
4 changed files with 59 additions and 0 deletions

View file

@ -0,0 +1,19 @@
/*
* Copyright (c) 2021, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/Prekernel/Arch/aarch64/MainIdRegister.h>
namespace Prekernel {
MainIdRegister::MainIdRegister()
{
unsigned int mrs;
asm volatile("mrs %x0, MIDR_EL1"
: "=r"(mrs));
m_value = mrs;
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2021, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
namespace Prekernel {
class MainIdRegister {
public:
MainIdRegister();
enum Implementer {
ArmLimited = 0x41,
};
unsigned implementer() const { return (m_value >> 24) & 0xFF; }
unsigned variant() const { return (m_value >> 20) & 0xF; }
unsigned architecture() const { return (m_value >> 16) & 0xF; }
enum PartNum {
RaspberryPi1 = 0xB76,
RaspberryPi2 = 0xC07,
RaspberryPi3 = 0xD03,
RaspberryPi4 = 0xD08,
};
unsigned part_num() const { return (m_value >> 4) & 0xFFF; }
unsigned revision() const { return m_value & 0xF; }
private:
unsigned int m_value;
};
}

View file

@ -5,10 +5,13 @@
*/ */
#include <AK/Types.h> #include <AK/Types.h>
#include <Kernel/Prekernel/Arch/aarch64/MainIdRegister.h>
extern "C" [[noreturn]] void init(); extern "C" [[noreturn]] void init();
extern "C" [[noreturn]] void init() extern "C" [[noreturn]] void init()
{ {
Prekernel::MainIdRegister id;
[[maybe_unused]] unsigned part_num = id.part_num();
for (;;) { } for (;;) { }
} }

View file

@ -12,6 +12,7 @@ if ("${SERENITY_ARCH}" STREQUAL "aarch64")
Arch/aarch64/boot.S Arch/aarch64/boot.S
${SOURCES} ${SOURCES}
Arch/aarch64/MainIdRegister.cpp
Arch/aarch64/init.cpp Arch/aarch64/init.cpp
) )
else() else()