summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit/ARM64
diff options
context:
space:
mode:
Diffstat (limited to 'dev/kernel/HALKit/ARM64')
-rw-r--r--dev/kernel/HALKit/ARM64/APM/APM+IO.cc40
-rw-r--r--dev/kernel/HALKit/ARM64/ApplicationProcessor.h9
-rw-r--r--dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc36
-rw-r--r--dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc191
-rw-r--r--dev/kernel/HALKit/ARM64/HalDebugOutput.cc118
-rw-r--r--dev/kernel/HALKit/ARM64/HalKernelMain.cc84
-rw-r--r--dev/kernel/HALKit/ARM64/HalKernelPanic.cc98
-rw-r--r--dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc143
-rw-r--r--dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc29
-rw-r--r--dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc49
-rw-r--r--dev/kernel/HALKit/ARM64/HalTimerARM64.cc10
-rw-r--r--dev/kernel/HALKit/ARM64/Paging.h151
-rw-r--r--dev/kernel/HALKit/ARM64/Processor.h141
-rw-r--r--dev/kernel/HALKit/ARM64/Storage/SCSI+Generic.cc6
-rw-r--r--dev/kernel/HALKit/ARM64/Storage/UFS+Generic.cc2
15 files changed, 509 insertions, 598 deletions
diff --git a/dev/kernel/HALKit/ARM64/APM/APM+IO.cc b/dev/kernel/HALKit/ARM64/APM/APM+IO.cc
index fc53e4e0..3df8a407 100644
--- a/dev/kernel/HALKit/ARM64/APM/APM+IO.cc
+++ b/dev/kernel/HALKit/ARM64/APM/APM+IO.cc
@@ -1,11 +1,11 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
-#include <modules/APM/APM.h>
#include <KernelKit/KPC.h>
+#include <modules/APM/APM.h>
using namespace Kernel;
@@ -13,25 +13,23 @@ using namespace Kernel;
/// @param base_dma the IO base port.
/// @param cmd the command.
/// @return status code.
-EXTERN_C Int32 apm_send_io_command(UInt16 cmd, APMPowerCmd value)
-{
- switch (cmd)
- {
- case kAPMPowerCommandReboot: {
- asm volatile(
- "ldr x0, =0x84000004\n"
- "svc #0\n");
+EXTERN_C Int32 apm_send_io_command(UInt16 cmd, APMPowerCmd value) {
+ switch (cmd) {
+ case kAPMPowerCommandReboot: {
+ asm volatile(
+ "ldr x0, =0x84000004\n"
+ "svc #0\n");
- return kErrorSuccess;
- }
- case kAPMPowerCommandShutdown: {
- asm volatile(
- "ldr x0, =0x84000008\n"
- "svc #0\n");
+ return kErrorSuccess;
+ }
+ case kAPMPowerCommandShutdown: {
+ asm volatile(
+ "ldr x0, =0x84000008\n"
+ "svc #0\n");
- return kErrorSuccess;
- }
- default:
- return kErrorInvalidData;
- }
+ return kErrorSuccess;
+ }
+ default:
+ return kErrorInvalidData;
+ }
}
diff --git a/dev/kernel/HALKit/ARM64/ApplicationProcessor.h b/dev/kernel/HALKit/ARM64/ApplicationProcessor.h
index 6068d503..f48c1483 100644
--- a/dev/kernel/HALKit/ARM64/ApplicationProcessor.h
+++ b/dev/kernel/HALKit/ARM64/ApplicationProcessor.h
@@ -1,19 +1,18 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#pragma once
-#include <NewKit/Defines.h>
#include <HALKit/ARM64/Processor.h>
+#include <NewKit/Defines.h>
/************************************************** */
/* INITIALIZE THE GIC ON CPU. */
/************************************************** */
-namespace Kernel
-{
- BOOL mp_initialize_gic(Kernel::Void);
+namespace Kernel {
+BOOL mp_initialize_gic(Kernel::Void);
} \ No newline at end of file
diff --git a/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc
index 27ea0977..31f5a4f2 100644
--- a/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc
+++ b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc
@@ -1,32 +1,26 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
-#include <modules/ACPI/ACPIFactoryInterface.h>
-#include <NewKit/KString.h>
#include <ArchKit/ArchKit.h>
#include <KernelKit/MemoryMgr.h>
+#include <NewKit/KString.h>
+#include <modules/ACPI/ACPIFactoryInterface.h>
#include <modules/APM/APM.h>
-namespace Kernel
-{
- ACPIFactoryInterface::ACPIFactoryInterface(VoidPtr rsp_ptr)
- : fRsdp(rsp_ptr), fEntries(0)
- {
- }
+namespace Kernel {
+ACPIFactoryInterface::ACPIFactoryInterface(VoidPtr rsp_ptr) : fRsdp(rsp_ptr), fEntries(0) {}
- BOOL ACPIFactoryInterface::Shutdown()
- {
- apm_send_io_command(kAPMPowerCommandShutdown, 0);
- return NO;
- }
+BOOL ACPIFactoryInterface::Shutdown() {
+ apm_send_io_command(kAPMPowerCommandShutdown, 0);
+ return NO;
+}
- /// @brief Reboot machine in either ACPI or by triple faulting.
- /// @return nothing it's a reboot.
- Void ACPIFactoryInterface::Reboot()
- {
- apm_send_io_command(kAPMPowerCommandReboot, 0);
- }
-} // namespace Kernel
+/// @brief Reboot machine in either ACPI or by triple faulting.
+/// @return nothing it's a reboot.
+Void ACPIFactoryInterface::Reboot() {
+ apm_send_io_command(kAPMPowerCommandReboot, 0);
+}
+} // namespace Kernel
diff --git a/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc b/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc
index 7d985a44..14af1a16 100644
--- a/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc
+++ b/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc
@@ -1,145 +1,132 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
+#include <HALKit/ARM64/ApplicationProcessor.h>
#include <HALKit/ARM64/Processor.h>
#include <KernelKit/DebugOutput.h>
-#include <HALKit/ARM64/ApplicationProcessor.h>
#include <KernelKit/ProcessScheduler.h>
-#define GICD_BASE 0x08000000 // Distributor base address
-#define GICC_BASE 0x08010000 // CPU interface base address
+#define GICD_BASE 0x08000000 // Distributor base address
+#define GICC_BASE 0x08010000 // CPU interface base address
-#define GICD_CTLR 0x000 // Distributor Control Register
-#define GICD_ISENABLER 0x100 // Interrupt Set-Enable Registers
-#define GICD_ICENABLER 0x180 // Interrupt Clear-Enable Registers
-#define GICD_ISPENDR 0x200 // Interrupt Set-Pending Registers
-#define GICD_ICPENDR 0x280 // Interrupt Clear-Pending Registers
-#define GICD_IPRIORITYR 0x400 // Interrupt Priority Registers
-#define GICD_ITARGETSR 0x800 // Interrupt Processor Targets Registers
-#define GICD_ICFGR 0xC00 // Interrupt Configuration Registers
+#define GICD_CTLR 0x000 // Distributor Control Register
+#define GICD_ISENABLER 0x100 // Interrupt Set-Enable Registers
+#define GICD_ICENABLER 0x180 // Interrupt Clear-Enable Registers
+#define GICD_ISPENDR 0x200 // Interrupt Set-Pending Registers
+#define GICD_ICPENDR 0x280 // Interrupt Clear-Pending Registers
+#define GICD_IPRIORITYR 0x400 // Interrupt Priority Registers
+#define GICD_ITARGETSR 0x800 // Interrupt Processor Targets Registers
+#define GICD_ICFGR 0xC00 // Interrupt Configuration Registers
-#define GICC_CTLR 0x000 // CPU Interface Control Register
-#define GICC_PMR 0x004 // Interrupt Priority Mask Register
-#define GICC_IAR 0x00C // Interrupt Acknowledge Register
-#define GICC_EOIR 0x010 // End of Interrupt Register
+#define GICC_CTLR 0x000 // CPU Interface Control Register
+#define GICC_PMR 0x004 // Interrupt Priority Mask Register
+#define GICC_IAR 0x00C // Interrupt Acknowledge Register
+#define GICC_EOIR 0x010 // End of Interrupt Register
// ================================================================= //
-namespace Kernel
-{
- struct PROCESS_CONTROL_BLOCK final
- {
- HAL::StackFramePtr mFrame;
- };
+namespace Kernel {
+struct PROCESS_CONTROL_BLOCK final {
+ HAL::StackFramePtr mFrame;
+};
- STATIC PROCESS_CONTROL_BLOCK kProcessBlocks[kSchedProcessLimitPerTeam] = {0};
+STATIC PROCESS_CONTROL_BLOCK kProcessBlocks[kSchedProcessLimitPerTeam] = {0};
- namespace Detail
- {
- STATIC BOOL kGICEnabled = NO;
+namespace Detail {
+ STATIC BOOL kGICEnabled = NO;
- STATIC void mp_hang_fn(void)
- {
- while (YES)
- ;
+ STATIC void mp_hang_fn(void) {
+ while (YES);
- dbg_break_point();
- }
+ dbg_break_point();
+ }
- Void mp_setup_gic_el0(Void)
- {
- // enable distributor.
- ke_dma_write<UInt32>(GICD_BASE, GICD_CTLR, YES);
+ Void mp_setup_gic_el0(Void) {
+ // enable distributor.
+ ke_dma_write<UInt32>(GICD_BASE, GICD_CTLR, YES);
- UInt32 gicc_ctlr = ke_dma_read<UInt32>(GICC_BASE, GICC_CTLR);
+ UInt32 gicc_ctlr = ke_dma_read<UInt32>(GICC_BASE, GICC_CTLR);
- const auto kEnableSignalInt = YES;
+ const auto kEnableSignalInt = YES;
- gicc_ctlr |= kEnableSignalInt; // Enable signaling of interrupts
- gicc_ctlr |= (kEnableSignalInt << 1); // Allow Group 1 interrupts in EL0
+ gicc_ctlr |= kEnableSignalInt; // Enable signaling of interrupts
+ gicc_ctlr |= (kEnableSignalInt << 1); // Allow Group 1 interrupts in EL0
- ke_dma_write<UInt32>(GICC_BASE, GICC_CTLR, gicc_ctlr);
+ ke_dma_write<UInt32>(GICC_BASE, GICC_CTLR, gicc_ctlr);
- // Set priority mask (accept all priorities)
- ke_dma_write<UInt32>(GICC_BASE, GICC_PMR, 0xFF);
+ // Set priority mask (accept all priorities)
+ ke_dma_write<UInt32>(GICC_BASE, GICC_PMR, 0xFF);
- UInt32 icfgr = ke_dma_read<UInt32>(GICD_BASE, GICD_ICFGR + (0x20 / 0x10) * 4);
+ UInt32 icfgr = ke_dma_read<UInt32>(GICD_BASE, GICD_ICFGR + (0x20 / 0x10) * 4);
- icfgr |= (0x2 << ((32 % 16) * 2)); // Edge-triggered
- ke_dma_write<UInt32>(GICD_BASE, GICD_ICFGR + (0x20 / 0x10) * 4, icfgr);
+ icfgr |= (0x2 << ((32 % 16) * 2)); // Edge-triggered
+ ke_dma_write<UInt32>(GICD_BASE, GICD_ICFGR + (0x20 / 0x10) * 4, icfgr);
- // Target interrupt 32 to CPU 1
- ke_dma_write<UInt32>(GICD_BASE, GICD_ITARGETSR + (0x20 / 0x04) * 4, 0x2 << ((32 % 4) * 8));
+ // Target interrupt 32 to CPU 1
+ ke_dma_write<UInt32>(GICD_BASE, GICD_ITARGETSR + (0x20 / 0x04) * 4, 0x2 << ((32 % 4) * 8));
- // Set interrupt 32 priority to lowest (0xFF)
- ke_dma_write<UInt32>(GICD_BASE, GICD_IPRIORITYR + (0x20 / 0x04) * 4, 0xFF << ((32 % 4) * 8));
+ // Set interrupt 32 priority to lowest (0xFF)
+ ke_dma_write<UInt32>(GICD_BASE, GICD_IPRIORITYR + (0x20 / 0x04) * 4, 0xFF << ((32 % 4) * 8));
- // Enable interrupt 32 for AP.
- ke_dma_write<UInt32>(GICD_BASE, GICD_ISENABLER + 4, 0x01);
- }
+ // Enable interrupt 32 for AP.
+ ke_dma_write<UInt32>(GICD_BASE, GICD_ISENABLER + 4, 0x01);
+ }
- BOOL mp_handle_gic_interrupt_el0(Void)
- {
- // Read the interrupt ID
- UInt32 interrupt_id = ke_dma_read<UInt32>(GICC_BASE, GICC_IAR);
+ BOOL mp_handle_gic_interrupt_el0(Void) {
+ // Read the interrupt ID
+ UInt32 interrupt_id = ke_dma_read<UInt32>(GICC_BASE, GICC_IAR);
- // Check if it's a valid interrupt (not spurious)
- if ((interrupt_id & 0x3FF) < 1020)
- {
- auto interrupt = interrupt_id & 0x3FF;
+ // Check if it's a valid interrupt (not spurious)
+ if ((interrupt_id & 0x3FF) < 1020) {
+ auto interrupt = interrupt_id & 0x3FF;
- const UInt16 kInterruptScheduler = 0x20;
+ const UInt16 kInterruptScheduler = 0x20;
- (Void)(kout << "Handling interrupt for AP: " << interrupt << kendl);
+ (Void)(kout << "Handling interrupt for AP: " << interrupt << kendl);
- switch (interrupt)
- {
- case kInterruptScheduler: {
- ke_dma_write<UInt32>(GICC_BASE, GICC_EOIR, interrupt_id);
- UserProcessHelper::StartScheduling();
- break;
- }
- default: {
- ke_dma_write<UInt32>(GICC_BASE, GICC_EOIR, interrupt_id);
- break;
- }
- }
+ switch (interrupt) {
+ case kInterruptScheduler: {
+ ke_dma_write<UInt32>(GICC_BASE, GICC_EOIR, interrupt_id);
+ UserProcessHelper::StartScheduling();
+ break;
+ }
+ default: {
+ ke_dma_write<UInt32>(GICC_BASE, GICC_EOIR, interrupt_id);
+ break;
+ }
+ }
- return YES;
- }
+ return YES;
+ }
- // spurious interrupt
- return NO;
- }
- } // namespace Detail
+ // spurious interrupt
+ return NO;
+ }
+} // namespace Detail
- EXTERN_C HAL::StackFramePtr mp_get_current_context(ProcessID pid)
- {
- return kProcessBlocks[pid % kSchedProcessLimitPerTeam].mFrame;
- }
+EXTERN_C HAL::StackFramePtr mp_get_current_context(ProcessID pid) {
+ return kProcessBlocks[pid % kSchedProcessLimitPerTeam].mFrame;
+}
- EXTERN_C Bool mp_register_process(HAL::StackFramePtr stack_frame, ProcessID pid)
- {
- MUST_PASS(stack_frame);
+EXTERN_C Bool mp_register_process(HAL::StackFramePtr stack_frame, ProcessID pid) {
+ MUST_PASS(stack_frame);
- const auto process_index = pid % kSchedProcessLimitPerTeam;
+ const auto process_index = pid % kSchedProcessLimitPerTeam;
- kProcessBlocks[process_index].mFrame = stack_frame;
+ kProcessBlocks[process_index].mFrame = stack_frame;
- return YES;
- }
+ return YES;
+}
- BOOL mp_initialize_gic(Void)
- {
- if (!Detail::kGICEnabled)
- {
- Detail::kGICEnabled = YES;
- Detail::mp_setup_gic_el0();
- }
+BOOL mp_initialize_gic(Void) {
+ if (!Detail::kGICEnabled) {
+ Detail::kGICEnabled = YES;
+ Detail::mp_setup_gic_el0();
+ }
- return Detail::kGICEnabled;
- }
-} // namespace Kernel \ No newline at end of file
+ return Detail::kGICEnabled;
+}
+} // namespace Kernel \ No newline at end of file
diff --git a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc
index 7f9c73be..7ec90c6e 100644
--- a/dev/kernel/HALKit/ARM64/HalDebugOutput.cc
+++ b/dev/kernel/HALKit/ARM64/HalDebugOutput.cc
@@ -1,83 +1,71 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#include <ArchKit/ArchKit.h>
#include <KernelKit/DebugOutput.h>
-#include <NewKit/Utils.h>
#include <NewKit/New.h>
+#include <NewKit/Utils.h>
-namespace Kernel
-{
- EXTERN_C void ke_io_write(IDeviceObject<const Char*>* self, const Char* bytes)
- {
+namespace Kernel {
+EXTERN_C void ke_io_write(IDeviceObject<const Char*>* self, const Char* bytes) {
#ifdef __DEBUG__
- if (*bytes == 0)
- return;
+ if (*bytes == 0) return;
- SizeT index = 0;
- SizeT len = 0;
+ SizeT index = 0;
+ SizeT len = 0;
- index = 0;
- len = rt_string_len(bytes, 256U);
+ index = 0;
+ len = rt_string_len(bytes, 256U);
- volatile UInt8* uart_ptr = (UInt8*)0x09000000;
+ volatile UInt8* uart_ptr = (UInt8*) 0x09000000;
- while (index < len)
- {
- if (bytes[index] == '\r')
- *uart_ptr = '\r';
+ while (index < len) {
+ if (bytes[index] == '\r') *uart_ptr = '\r';
- *uart_ptr = bytes[index] == '\r' ? '\n' : bytes[index];
- ++index;
- }
-#endif // __DEBUG__
- }
+ *uart_ptr = bytes[index] == '\r' ? '\n' : bytes[index];
+ ++index;
+ }
+#endif // __DEBUG__
+}
- TerminalDevice::~TerminalDevice() = default;
+TerminalDevice::~TerminalDevice() = default;
- EXTERN_C void ke_io_read(IDeviceObject<const Char*>* self, const Char* bytes)
- {
+EXTERN_C void ke_io_read(IDeviceObject<const Char*>* self, const Char* bytes) {
#ifdef __DEBUG__
- SizeT index = 0;
-
- volatile UInt8* uart_ptr = (UInt8*)0x09000000;
-
- ///! TODO: Look on how to wait for the UART to complete.
- while (Yes)
- {
- auto in = *uart_ptr;
-
- ///! If enter pressed then break.
- if (in == 0xD)
- {
- break;
- }
-
- if (in < '0' || in < 'A' || in < 'a')
- {
- if (in != '@' || in != '!' || in != '?' || in != '.' || in != '/' ||
- in != ':')
- {
- continue;
- }
- }
-
- ((char*)bytes)[index] = in;
-
- ++index;
- }
-
- ((char*)bytes)[index] = 0;
-#endif // __DEBUG__
- }
-
- TerminalDevice TerminalDevice::The() noexcept
- {
- TerminalDevice out(Kernel::ke_io_write, Kernel::ke_io_read);
- return out;
- }
-
-} // namespace Kernel
+ SizeT index = 0;
+
+ volatile UInt8* uart_ptr = (UInt8*) 0x09000000;
+
+ ///! TODO: Look on how to wait for the UART to complete.
+ while (Yes) {
+ auto in = *uart_ptr;
+
+ ///! If enter pressed then break.
+ if (in == 0xD) {
+ break;
+ }
+
+ if (in < '0' || in < 'A' || in < 'a') {
+ if (in != '@' || in != '!' || in != '?' || in != '.' || in != '/' || in != ':') {
+ continue;
+ }
+ }
+
+ ((char*) bytes)[index] = in;
+
+ ++index;
+ }
+
+ ((char*) bytes)[index] = 0;
+#endif // __DEBUG__
+}
+
+TerminalDevice TerminalDevice::The() noexcept {
+ TerminalDevice out(Kernel::ke_io_write, Kernel::ke_io_read);
+ return out;
+}
+
+} // namespace Kernel
diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc
index 3498d477..3e6701ea 100644
--- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc
+++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc
@@ -1,77 +1,71 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#include <ArchKit/ArchKit.h>
-#include <modules/CoreGfx/CoreGfx.h>
+#include <CFKit/Property.h>
#include <FirmwareKit/Handover.h>
+#include <HALKit/ARM64/Processor.h>
+#include <KernelKit/CodeMgr.h>
#include <KernelKit/FileMgr.h>
#include <KernelKit/MemoryMgr.h>
#include <KernelKit/PEFCodeMgr.h>
#include <KernelKit/ProcessScheduler.h>
+#include <NetworkKit/IPC.h>
#include <NewKit/Json.h>
-#include <KernelKit/CodeMgr.h>
#include <modules/ACPI/ACPIFactoryInterface.h>
-#include <NetworkKit/IPC.h>
-#include <HALKit/ARM64/Processor.h>
-#include <CFKit/Property.h>
+#include <modules/CoreGfx/CoreGfx.h>
#include <HALKit/ARM64/ApplicationProcessor.h>
-EXTERN_C void hal_init_platform(
- Kernel::HEL::BootInfoHeader* handover_hdr)
-{
-
- /************************************************** */
- /* INITIALIZE AND VALIDATE HEADER. */
- /************************************************** */
+EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
+ /************************************************** */
+ /* INITIALIZE AND VALIDATE HEADER. */
+ /************************************************** */
- kHandoverHeader = handover_hdr;
+ kHandoverHeader = handover_hdr;
- if (kHandoverHeader->f_Magic != kHandoverMagic &&
- kHandoverHeader->f_Version != kHandoverVersion)
- {
- return;
- }
+ if (kHandoverHeader->f_Magic != kHandoverMagic &&
+ kHandoverHeader->f_Version != kHandoverVersion) {
+ return;
+ }
- /************************************** */
- /* INITIALIZE BIT MAP. */
- /************************************** */
+ /************************************** */
+ /* INITIALIZE BIT MAP. */
+ /************************************** */
- kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
- kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
- reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
+ kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
+ kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
+ reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
- /// @note do initialize the interrupts after it.
+ /// @note do initialize the interrupts after it.
- Kernel::mp_initialize_gic();
+ Kernel::mp_initialize_gic();
- /// after the scheduler runs, we must look over teams, every 5000s in order to schedule every process according to their affinity fairly.
+ /// after the scheduler runs, we must look over teams, every 5000s in order to schedule every
+ /// process according to their affinity fairly.
- auto constexpr kSchedTeamSwitchMS = 5U; /// @brief Team switch time in milliseconds.
+ auto constexpr kSchedTeamSwitchMS = 5U; /// @brief Team switch time in milliseconds.
- Kernel::HardwareTimer timer(rtl_milliseconds(kSchedTeamSwitchMS));
+ Kernel::HardwareTimer timer(rtl_milliseconds(kSchedTeamSwitchMS));
- STATIC Kernel::Array<UserProcessTeam, kSchedTeamCount> kTeams;
+ STATIC Kernel::Array<UserProcessTeam, kSchedTeamCount> kTeams;
- SizeT team_index = 0U;
+ SizeT team_index = 0U;
- /// @brief This just loops over the teams and switches between them.
- /// @details Not even round-robin, just a simple loop in this boot core we're at.
- while (YES)
- {
- if (team_index > (kSchedTeamCount - 1))
- {
- team_index = 0U;
- }
+ /// @brief This just loops over the teams and switches between them.
+ /// @details Not even round-robin, just a simple loop in this boot core we're at.
+ while (YES) {
+ if (team_index > (kSchedTeamCount - 1)) {
+ team_index = 0U;
+ }
- while (!UserProcessScheduler::The().SwitchTeam(kTeams[team_index]))
- ;
+ while (!UserProcessScheduler::The().SwitchTeam(kTeams[team_index]));
- timer.Wait();
+ timer.Wait();
- ++team_index;
- }
+ ++team_index;
+ }
}
diff --git a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc
index ad966991..5680041c 100644
--- a/dev/kernel/HALKit/ARM64/HalKernelPanic.cc
+++ b/dev/kernel/HALKit/ARM64/HalKernelPanic.cc
@@ -1,80 +1,74 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
-#include <NewKit/KernelPanic.h>
#include <ArchKit/ArchKit.h>
-#include <KernelKit/Timer.h>
-#include <KernelKit/DebugOutput.h>
-#include <NewKit/KString.h>
#include <FirmwareKit/Handover.h>
+#include <KernelKit/DebugOutput.h>
#include <KernelKit/FileMgr.h>
+#include <KernelKit/Timer.h>
+#include <NewKit/KString.h>
+#include <NewKit/KernelPanic.h>
+#include <NewKit/Utils.h>
#include <modules/CoreGfx/CoreGfx.h>
#include <modules/CoreGfx/TextGfx.h>
-#include <NewKit/Utils.h>
/* Each error code is attributed with an ID, which will prompt a string onto the
* screen. Wait for debugger... */
-namespace Kernel
-{
- /// @brief Dumping factory class.
- class RecoveryFactory final
- {
- public:
- STATIC Void Recover() noexcept;
- };
+namespace Kernel {
+/// @brief Dumping factory class.
+class RecoveryFactory final {
+ public:
+ STATIC Void Recover() noexcept;
+};
- /***********************************************************************************/
- /// @brief Stops execution of the kernel.
- /// @param id kernel stop ID.
- /***********************************************************************************/
- Void ke_panic(const Kernel::Int32& id, const Char* message)
- {
- fb_init();
+/***********************************************************************************/
+/// @brief Stops execution of the kernel.
+/// @param id kernel stop ID.
+/***********************************************************************************/
+Void ke_panic(const Kernel::Int32& id, const Char* message) {
+ fb_init();
- auto panic_text = RGB(0xff, 0xff, 0xff);
+ auto panic_text = RGB(0xff, 0xff, 0xff);
- auto y = 10;
- auto x = 10;
+ auto y = 10;
+ auto x = 10;
- Char* message_apicid = new Char[128];
- rt_set_memory(message_apicid, 0, 128);
+ Char* message_apicid = new Char[128];
+ rt_set_memory(message_apicid, 0, 128);
- rt_copy_memory((VoidPtr) "panic id: ", message_apicid, rt_string_len("panic id: "));
- rt_to_string(message_apicid + rt_string_len("panic id: "), (UIntPtr)id, 10);
+ rt_copy_memory((VoidPtr) "panic id: ", message_apicid, rt_string_len("panic id: "));
+ rt_to_string(message_apicid + rt_string_len("panic id: "), (UIntPtr) id, 10);
- fb_render_string(message_apicid, y, x, panic_text);
+ fb_render_string(message_apicid, y, x, panic_text);
- y += 10;
+ y += 10;
- fb_render_string((message ? message : "message: panic raised, going nowhere after this!"), y, x, panic_text);
+ fb_render_string((message ? message : "message: panic raised, going nowhere after this!"), y, x,
+ panic_text);
- y += 10;
+ y += 10;
- fb_clear();
+ fb_clear();
- RecoveryFactory::Recover();
- }
+ RecoveryFactory::Recover();
+}
- Void RecoveryFactory::Recover() noexcept
- {
- while (YES)
- {
- HAL::rt_halt();
- }
- }
+Void RecoveryFactory::Recover() noexcept {
+ while (YES) {
+ HAL::rt_halt();
+ }
+}
- void ke_runtime_check(bool expr, const Char* file, const Char* line)
- {
- if (!expr)
- {
- (Void)(kout << "FAILED: FILE: " << file << kendl);
- (Void)(kout << "FAILED: LINE: " << line << kendl);
+void ke_runtime_check(bool expr, const Char* file, const Char* line) {
+ if (!expr) {
+ (Void)(kout << "FAILED: FILE: " << file << kendl);
+ (Void)(kout << "FAILED: LINE: " << line << kendl);
- ke_panic(RUNTIME_CHECK_FAILED, file); // Runtime Check failed
- }
- }
-} // namespace Kernel
+ ke_panic(RUNTIME_CHECK_FAILED, file); // Runtime Check failed
+ }
+}
+} // namespace Kernel
diff --git a/dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc b/dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc
index 08dd6180..e8c6875d 100644
--- a/dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc
+++ b/dev/kernel/HALKit/ARM64/HalPagingMgrARM64.cc
@@ -1,86 +1,75 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
- File: HalPagingMgr.cc
- Purpose: Platform Paging Manager.
+ File: HalPagingMgr.cc
+ Purpose: Platform Paging Manager.
------------------------------------------- */
#include <HALKit/ARM64/Paging.h>
#include <HALKit/ARM64/Processor.h>
-namespace Kernel::HAL
-{
- typedef UInt32 PageTableIndex;
-
- /// \brief Page store type.
- struct NE_PAGE_STORE final
- {
- struct
- {
- PDE* fPde{nullptr};
- PTE* fPte{nullptr};
- VoidPtr fVAddr{nullptr};
- } fInternalStore;
-
- Bool fStoreOp{No}; // Store operation in progress.
-
- static NE_PAGE_STORE& The()
- {
- static NE_PAGE_STORE the;
- return the;
- }
- };
-
- /// \brief Retrieve the page status of a PTE.
- STATIC Void mmi_page_status(PTE* pte)
- {
- }
-
- STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, PTE* pt_entry);
-
- /// @brief Maps or allocates a page from virtual_address.
- /// @param virtual_address a valid virtual address.
- /// @param phys_addr point to physical address.
- /// @param flags the flags to put on the page.
- /// @return Status code of page manipulation process.
- EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags)
- {
- if (!virtual_address ||
- !flags)
- return 0;
-
- NE_PAGE_STORE& page_store = NE_PAGE_STORE::The();
-
- while (page_store.fStoreOp)
- ;
-
- page_store.fStoreOp = Yes;
-
- if (page_store.fInternalStore.fVAddr == virtual_address)
- {
- page_store.fStoreOp = No;
- return mmi_map_page_table_entry(page_store.fInternalStore.fVAddr, flags, page_store.fInternalStore.fPte);
- }
-
- return 1;
- }
-
- /// @brief Maps flags for a specific pte.
- /// @internal Internal function.
- STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, PTE* pt_entry)
- {
- NE_PAGE_STORE& page_store = NE_PAGE_STORE::The();
-
- // Update internal store.
-
- page_store.fInternalStore.fPde = nullptr;
- page_store.fInternalStore.fPte = pt_entry;
- page_store.fInternalStore.fVAddr = virtual_address;
-
- page_store.fStoreOp = No;
-
- return 0;
- }
-} // namespace Kernel::HAL
+namespace Kernel::HAL {
+typedef UInt32 PageTableIndex;
+
+/// \brief Page store type.
+struct NE_PAGE_STORE final {
+ struct {
+ PDE* fPde{nullptr};
+ PTE* fPte{nullptr};
+ VoidPtr fVAddr{nullptr};
+ } fInternalStore;
+
+ Bool fStoreOp{No}; // Store operation in progress.
+
+ static NE_PAGE_STORE& The() {
+ static NE_PAGE_STORE the;
+ return the;
+ }
+};
+
+/// \brief Retrieve the page status of a PTE.
+STATIC Void mmi_page_status(PTE* pte) {}
+
+STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, PTE* pt_entry);
+
+/// @brief Maps or allocates a page from virtual_address.
+/// @param virtual_address a valid virtual address.
+/// @param phys_addr point to physical address.
+/// @param flags the flags to put on the page.
+/// @return Status code of page manipulation process.
+EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags) {
+ if (!virtual_address || !flags) return 0;
+
+ NE_PAGE_STORE& page_store = NE_PAGE_STORE::The();
+
+ while (page_store.fStoreOp);
+
+ page_store.fStoreOp = Yes;
+
+ if (page_store.fInternalStore.fVAddr == virtual_address) {
+ page_store.fStoreOp = No;
+ return mmi_map_page_table_entry(page_store.fInternalStore.fVAddr, flags,
+ page_store.fInternalStore.fPte);
+ }
+
+ return 1;
+}
+
+/// @brief Maps flags for a specific pte.
+/// @internal Internal function.
+STATIC Int32 mmi_map_page_table_entry(VoidPtr virtual_address, UInt32 flags, PTE* pt_entry) {
+ NE_PAGE_STORE& page_store = NE_PAGE_STORE::The();
+
+ // Update internal store.
+
+ page_store.fInternalStore.fPde = nullptr;
+ page_store.fInternalStore.fPte = pt_entry;
+ page_store.fInternalStore.fVAddr = virtual_address;
+
+ page_store.fStoreOp = No;
+
+ return 0;
+}
+} // namespace Kernel::HAL
diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc
index 538124a6..b3f1b62a 100644
--- a/dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc
+++ b/dev/kernel/HALKit/ARM64/HalSchedulerCoreARM64.cc
@@ -1,24 +1,21 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#include <KernelKit/ProcessScheduler.h>
-namespace Kernel
-{
- /// @brief Wakes up thread.
- /// Wakes up thread from the hang state.
- Void mp_wakeup_thread(HAL::StackFrame* stack)
- {
- NE_UNUSED(stack);
- }
+namespace Kernel {
+/// @brief Wakes up thread.
+/// Wakes up thread from the hang state.
+Void mp_wakeup_thread(HAL::StackFrame* stack) {
+ NE_UNUSED(stack);
+}
- /// @brief makes the thread sleep on a loop.
- /// hooks and hangs thread to prevent code from executing.
- Void mp_hang_thread(HAL::StackFrame* stack)
- {
- NE_UNUSED(stack);
- }
-} // namespace Kernel
+/// @brief makes the thread sleep on a loop.
+/// hooks and hangs thread to prevent code from executing.
+Void mp_hang_thread(HAL::StackFrame* stack) {
+ NE_UNUSED(stack);
+}
+} // namespace Kernel
diff --git a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc
index 84aae986..a8f0b1e1 100644
--- a/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc
+++ b/dev/kernel/HALKit/ARM64/HalSchedulerCorePrimitivesARM64.cc
@@ -1,35 +1,30 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#include <HALKit/ARM64/Processor.h>
#include <KernelKit/ProcessScheduler.h>
-namespace Kernel
-{
- /***********************************************************************************/
- /// @brief Unimplemented function (crashes by default)
- /// @param void
- /***********************************************************************************/
-
- EXTERN_C Void __zka_pure_call(USER_PROCESS* process)
- {
- if (process)
- process->Crash();
- }
-
- /***********************************************************************************/
- /// @brief Validate user stack.
- /// @param stack_ptr the frame pointer.
- /***********************************************************************************/
-
- EXTERN_C Bool hal_check_stack(HAL::StackFramePtr stack_ptr)
- {
- if (!stack_ptr)
- return No;
-
- return stack_ptr->SP != 0 && stack_ptr->BP != 0;
- }
-} // namespace Kernel
+namespace Kernel {
+/***********************************************************************************/
+/// @brief Unimplemented function (crashes by default)
+/// @param void
+/***********************************************************************************/
+
+EXTERN_C Void __zka_pure_call(USER_PROCESS* process) {
+ if (process) process->Crash();
+}
+
+/***********************************************************************************/
+/// @brief Validate user stack.
+/// @param stack_ptr the frame pointer.
+/***********************************************************************************/
+
+EXTERN_C Bool hal_check_stack(HAL::StackFramePtr stack_ptr) {
+ if (!stack_ptr) return No;
+
+ return stack_ptr->SP != 0 && stack_ptr->BP != 0;
+}
+} // namespace Kernel
diff --git a/dev/kernel/HALKit/ARM64/HalTimerARM64.cc b/dev/kernel/HALKit/ARM64/HalTimerARM64.cc
index c9fb1617..32f64aec 100644
--- a/dev/kernel/HALKit/ARM64/HalTimerARM64.cc
+++ b/dev/kernel/HALKit/ARM64/HalTimerARM64.cc
@@ -1,13 +1,13 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
- File: HalTimer.cc
- Purpose: HAL timer
+ File: HalTimer.cc
+ Purpose: HAL timer
- Revision History:
+ Revision History:
- 07/07/24: Added file (amlel)
+ 07/07/24: Added file (amlel)
------------------------------------------- */
diff --git a/dev/kernel/HALKit/ARM64/Paging.h b/dev/kernel/HALKit/ARM64/Paging.h
index 26c277db..e23c0538 100644
--- a/dev/kernel/HALKit/ARM64/Paging.h
+++ b/dev/kernel/HALKit/ARM64/Paging.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -8,7 +8,7 @@
/** ---------------------------------------------------
- * THIS FILE CONTAINS CODE FOR ARMV8 PAGING.
+ * THIS FILE CONTAINS CODE FOR ARMV8 PAGING.
------------------------------------------------------- */
@@ -16,105 +16,90 @@
#ifndef kPageMax
#define kPageMax (0x200)
-#endif //! kPageMax
+#endif //! kPageMax
#ifndef kPageAlign
#define kPageAlign (0x1000)
-#endif //! kPageAlign
+#endif //! kPageAlign
#ifndef kPageSize
#define kPageSize (0x1000)
-#endif // !kPageSize
+#endif // !kPageSize
//! short format address range
#define c16KBPage 0b000
-#define c8KBPage 0b001
-#define c4KBPage 0b010
-#define c2KBPage 0b011
-#define c1KBPage 0b100
+#define c8KBPage 0b001
+#define c4KBPage 0b010
+#define c2KBPage 0b011
+#define c1KBPage 0b100
#define c512BPage 0b101
#define c256BPage 0b110
#define c128BPage 0b111
/// Long format address range
-#define cPageMAll \
- { \
- 0b000, 0b000 \
- }
+#define cPageMAll \
+ { 0b000, 0b000 }
#define cPageMToMax(M) \
- { \
- M, 0b000 \
- }
+ { M, 0b000 }
#define cPageMaxToM(M) \
- { \
- 0b000, M \
- }
+ { 0b000, M }
#define cPageMToN(M, N) \
- { \
- M, N \
- }
-
-namespace Kernel::HAL
-{
- struct PACKED PTE_4KB final
- {
- UInt64 Valid : 1;
- UInt64 Table : 1;
- UInt64 AttrIndex : 3;
- UInt64 NS : 1;
- UInt64 AP : 2;
- UInt64 SH : 2;
- UInt64 AF : 1;
- UInt64 NG : 1;
- UInt64 Reserved1 : 1;
- UInt64 Contiguous : 1;
- UInt64 Dirty : 1;
- UInt64 Reserved : 2;
- UInt64 PhysicalAddress : 36;
- UInt64 Reserved3 : 4;
- UInt64 PXN : 1;
- UInt64 XN : 1;
- UInt64 Reserved4 : 9;
- };
-
- namespace Detail
- {
- enum class ControlRegisterBits
- {
- ProtectedModeEnable = 0,
- MonitorCoProcessor = 1,
- Emulation = 2,
- TaskSwitched = 3,
- ExtensionType = 4,
- NumericError = 5,
- WriteProtect = 16,
- AlignementMask = 18,
- NotWriteThrough = 29,
- CacheDisable = 30,
- PageEnable = 31,
- };
-
- inline UInt8 control_register_cast(ControlRegisterBits reg)
- {
- return static_cast<UInt8>(reg);
- }
- } // namespace Detail
-
- struct PDE_4KB final
- {
- PTE_4KB ALIGN(kPageAlign) fEntries[kPageMax];
- };
-
- auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page) -> VoidPtr;
- auto mm_free_bitmap(VoidPtr page_ptr) -> Bool;
-} // namespace Kernel::HAL
-
-namespace Kernel
-{
- typedef HAL::PTE_4KB PTE;
- typedef HAL::PDE_4KB PDE;
-} // namespace Kernel
+ { M, N }
+
+namespace Kernel::HAL {
+struct PACKED PTE_4KB final {
+ UInt64 Valid : 1;
+ UInt64 Table : 1;
+ UInt64 AttrIndex : 3;
+ UInt64 NS : 1;
+ UInt64 AP : 2;
+ UInt64 SH : 2;
+ UInt64 AF : 1;
+ UInt64 NG : 1;
+ UInt64 Reserved1 : 1;
+ UInt64 Contiguous : 1;
+ UInt64 Dirty : 1;
+ UInt64 Reserved : 2;
+ UInt64 PhysicalAddress : 36;
+ UInt64 Reserved3 : 4;
+ UInt64 PXN : 1;
+ UInt64 XN : 1;
+ UInt64 Reserved4 : 9;
+};
+
+namespace Detail {
+ enum class ControlRegisterBits {
+ ProtectedModeEnable = 0,
+ MonitorCoProcessor = 1,
+ Emulation = 2,
+ TaskSwitched = 3,
+ ExtensionType = 4,
+ NumericError = 5,
+ WriteProtect = 16,
+ AlignementMask = 18,
+ NotWriteThrough = 29,
+ CacheDisable = 30,
+ PageEnable = 31,
+ };
+
+ inline UInt8 control_register_cast(ControlRegisterBits reg) {
+ return static_cast<UInt8>(reg);
+ }
+} // namespace Detail
+
+struct PDE_4KB final {
+ PTE_4KB ALIGN(kPageAlign) fEntries[kPageMax];
+};
+
+auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page) -> VoidPtr;
+auto mm_free_bitmap(VoidPtr page_ptr) -> Bool;
+} // namespace Kernel::HAL
+
+namespace Kernel {
+typedef HAL::PTE_4KB PTE;
+typedef HAL::PDE_4KB PDE;
+} // namespace Kernel
EXTERN_C void hal_flush_tlb();
diff --git a/dev/kernel/HALKit/ARM64/Processor.h b/dev/kernel/HALKit/ARM64/Processor.h
index 3a04bed1..38902627 100644
--- a/dev/kernel/HALKit/ARM64/Processor.h
+++ b/dev/kernel/HALKit/ARM64/Processor.h
@@ -1,93 +1,84 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
#pragma once
+#include <FirmwareKit/Handover.h>
#include <NewKit/Array.h>
#include <NewKit/Defines.h>
#include <NewKit/Utils.h>
-#include <FirmwareKit/Handover.h>
#define kCPUBackendName "ARMv8"
-namespace Kernel::HAL
-{
- struct PACKED Register64 final
- {
- UShort Limit;
- UIntPtr Base;
- };
-
- /// @brief Memory Manager mapping flags.
- enum
- {
- kMMFlagsPresent = 1 << 0,
- kMMFlagsWr = 1 << 1,
- kMMFlagsUser = 1 << 2,
- kMMFlagsNX = 1 << 3,
- kMMFlagsPCD = 1 << 4,
- kMMFlagsCount = 4,
- };
-
- /// @brief Set a PTE from pd_base.
- /// @param virt_addr a valid virtual address.
- /// @param phys_addr point to physical address.
- /// @param flags the flags to put on the page.
- /// @return Status code of page manip.
- EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags);
-
- EXTERN_C UIntPtr hal_get_phys_address(VoidPtr virtual_address);
-
- typedef UIntPtr Reg;
- typedef Register64 Register;
-
- /// @note let's keep the same name as AMD64 HAL.
- struct PACKED StackFrame final
- {
- Reg R8{0};
- Reg R9{0};
- Reg R10{0};
- Reg R11{0};
- Reg R12{0};
- Reg R13{0};
- Reg R14{0};
- Reg R15{0};
- Reg SP{0};
- Reg BP{0};
- };
-
- typedef StackFrame* StackFramePtr;
-
- inline Void rt_halt() noexcept
- {
- while (Yes)
- {
- }
- }
-
- template <typename DataKind>
- inline void hal_dma_write(UIntPtr address, DataKind value)
- {
- *reinterpret_cast<volatile DataKind*>(address) = value;
- }
-
- template <typename DataKind>
- inline DataKind hal_dma_read(UIntPtr address)
- {
- return *reinterpret_cast<volatile DataKind*>(address);
- }
-
- inline Void hal_wfi(Void)
- {
- asm volatile("wfi");
- }
-} // namespace Kernel::HAL
+namespace Kernel::HAL {
+struct PACKED Register64 final {
+ UShort Limit;
+ UIntPtr Base;
+};
+
+/// @brief Memory Manager mapping flags.
+enum {
+ kMMFlagsPresent = 1 << 0,
+ kMMFlagsWr = 1 << 1,
+ kMMFlagsUser = 1 << 2,
+ kMMFlagsNX = 1 << 3,
+ kMMFlagsPCD = 1 << 4,
+ kMMFlagsCount = 4,
+};
+
+/// @brief Set a PTE from pd_base.
+/// @param virt_addr a valid virtual address.
+/// @param phys_addr point to physical address.
+/// @param flags the flags to put on the page.
+/// @return Status code of page manip.
+EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UInt32 flags);
+
+EXTERN_C UIntPtr hal_get_phys_address(VoidPtr virtual_address);
+
+typedef UIntPtr Reg;
+typedef Register64 Register;
+
+/// @note let's keep the same name as AMD64 HAL.
+struct PACKED StackFrame final {
+ Reg R8{0};
+ Reg R9{0};
+ Reg R10{0};
+ Reg R11{0};
+ Reg R12{0};
+ Reg R13{0};
+ Reg R14{0};
+ Reg R15{0};
+ Reg SP{0};
+ Reg BP{0};
+};
+
+typedef StackFrame* StackFramePtr;
+
+inline Void rt_halt() noexcept {
+ while (Yes) {
+ }
+}
+
+template <typename DataKind>
+inline void hal_dma_write(UIntPtr address, DataKind value) {
+ *reinterpret_cast<volatile DataKind*>(address) = value;
+}
+
+template <typename DataKind>
+inline DataKind hal_dma_read(UIntPtr address) {
+ return *reinterpret_cast<volatile DataKind*>(address);
+}
+
+inline Void hal_wfi(Void) {
+ asm volatile("wfi");
+}
+} // namespace Kernel::HAL
inline Kernel::VoidPtr kKernelBitMpStart = nullptr;
-inline Kernel::UIntPtr kKernelBitMpSize = 0UL;
+inline Kernel::UIntPtr kKernelBitMpSize = 0UL;
inline Kernel::VoidPtr kKernelPhysicalStart = nullptr;
diff --git a/dev/kernel/HALKit/ARM64/Storage/SCSI+Generic.cc b/dev/kernel/HALKit/ARM64/Storage/SCSI+Generic.cc
index cb387e73..1cc97cba 100644
--- a/dev/kernel/HALKit/ARM64/Storage/SCSI+Generic.cc
+++ b/dev/kernel/HALKit/ARM64/Storage/SCSI+Generic.cc
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -9,5 +9,5 @@
using namespace Kernel;
///! @brief ATAPI SCSI packet.
-const ATTRIBUTE(unused) scsi_packet_type_12 kCDRomPacketTemplate = {0x43, 0, 1, 0, 0, 0,
- 0, 12, 0x40, 0, 0};
+const ATTRIBUTE(unused) scsi_packet_type_12 kCDRomPacketTemplate = {0x43, 0, 1, 0, 0, 0,
+ 0, 12, 0x40, 0, 0};
diff --git a/dev/kernel/HALKit/ARM64/Storage/UFS+Generic.cc b/dev/kernel/HALKit/ARM64/Storage/UFS+Generic.cc
index 1529e158..e5ef7b91 100644
--- a/dev/kernel/HALKit/ARM64/Storage/UFS+Generic.cc
+++ b/dev/kernel/HALKit/ARM64/Storage/UFS+Generic.cc
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */