summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-05-23 11:12:31 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-05-23 11:13:38 +0200
commit54a0f4c49d9bfb955174c87dae2f442d7f5a8b25 (patch)
treead59d31c9444fcfc6d5f0da7b17c8843710e6014 /dev/kernel/HALKit
parentfc67c4af554189c941c811486a0b2b21aa3f54ea (diff)
feat!(Kernel): Improvements on the BitMapMgr, HTS, and UPS.
other: - Add ZXD header file. - Reworking AMD64 interrupts. - Improved HTS's design implementation. - Improved UPS's balancing implementation. breaking changes: - Rename MemoryMgr to HeapMgr. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/HALKit')
-rw-r--r--dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc2
-rw-r--r--dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc2
-rw-r--r--dev/kernel/HALKit/AMD64/HalApplicationProcessorStartup.s (renamed from dev/kernel/HALKit/AMD64/HalAPStartup.s)4
-rw-r--r--dev/kernel/HALKit/AMD64/HalCommonAPI.asm3
-rw-r--r--dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc66
-rw-r--r--dev/kernel/HALKit/AMD64/HalKernelMain.cc1
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc26
-rw-r--r--dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc2
-rw-r--r--dev/kernel/HALKit/ARM64/HalApplicationProcessorStartup.s12
-rw-r--r--dev/kernel/HALKit/ARM64/HalKernelMain.cc2
10 files changed, 43 insertions, 77 deletions
diff --git a/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc b/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc
index e2b89765..1d289db8 100644
--- a/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc
+++ b/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc
@@ -6,7 +6,7 @@
#include <ArchKit/ArchKit.h>
#include <HALKit/AMD64/Processor.h>
-#include <KernelKit/MemoryMgr.h>
+#include <KernelKit/HeapMgr.h>
#include <NeKit/KString.h>
#include <modules/ACPI/ACPIFactoryInterface.h>
diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc
index 17d4690f..7926289f 100644
--- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc
+++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc
@@ -121,8 +121,6 @@ EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ProcessID thrdid)
HardwareThreadScheduler::The()[thrdid].Leak()->Busy(NO);
- sched_jump_to_task(stack_frame);
-
return YES;
}
diff --git a/dev/kernel/HALKit/AMD64/HalAPStartup.s b/dev/kernel/HALKit/AMD64/HalApplicationProcessorStartup.s
index ec17bf7b..903038ea 100644
--- a/dev/kernel/HALKit/AMD64/HalAPStartup.s
+++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessorStartup.s
@@ -1,4 +1,4 @@
-.data
+.text
.global hal_ap_blob_start
.global hal_ap_blob_length
@@ -8,5 +8,7 @@ hal_ap_blob_start:
hlt
jmp hal_ap_blob_start
+.data
+
hal_ap_blob_length:
.long 4
diff --git a/dev/kernel/HALKit/AMD64/HalCommonAPI.asm b/dev/kernel/HALKit/AMD64/HalCommonAPI.asm
index d0ce2418..be150dde 100644
--- a/dev/kernel/HALKit/AMD64/HalCommonAPI.asm
+++ b/dev/kernel/HALKit/AMD64/HalCommonAPI.asm
@@ -116,9 +116,6 @@ sched_jump_to_task:
global sched_idle_task
sched_idle_task:
- mov ax, cs
- and ax, 3
-
jmp $
ret
diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
index 9da31800..23ca8d0e 100644
--- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
+++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc
@@ -33,30 +33,23 @@ STATIC void hal_idt_send_eoi(UInt8 vector) {
/// @brief Handle GPF fault.
/// @param rsp
EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp) {
- hal_idt_send_eoi(13);
-
auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess();
+ process.Leak().Crash();
- Kernel::kout << "Kernel: General Access Fault.\r";
+ hal_idt_send_eoi(13);
process.Leak().Signal.SignalArg = rsp;
process.Leak().Signal.SignalID = SIGKILL;
process.Leak().Signal.Status = process.Leak().Status;
-
- Kernel::kout << "Kernel: SIGKILL status.\r";
-
- process.Leak().Crash();
}
/// @brief Handle page fault.
/// @param rsp
EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) {
- hal_idt_send_eoi(14);
-
auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess();
+ process.Leak().Crash();
- Kernel::kout << "Kernel: Page Fault.\r";
- Kernel::kout << "Kernel: SIGKILL\r";
+ hal_idt_send_eoi(14);
process.Leak().Signal.SignalArg = rsp;
process.Leak().Signal.SignalID = SIGKILL;
@@ -87,26 +80,22 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) {
auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess();
- Kernel::kout << "Kernel: Math error (division by zero?).\r";
-
process.Leak().Signal.SignalArg = rsp;
process.Leak().Signal.SignalID = SIGKILL;
process.Leak().Signal.Status = process.Leak().Status;
- Kernel::kout << "Kernel: SIGKILL status.\r";
-
process.Leak().Crash();
}
/// @brief Handle any generic fault.
/// @param rsp
EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) {
- hal_idt_send_eoi(30);
-
auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess();
+ process.Leak().Crash();
+
+ hal_idt_send_eoi(30);
- (Void)(Kernel::kout << "Kernel: Process RSP: " << Kernel::hex_number(rsp) << Kernel::kendl);
- Kernel::kout << "Kernel: Access Process Fault.\r";
+ Kernel::kout << "Kernel: Generic Process Fault.\r";
process.Leak().Signal.SignalArg = rsp;
process.Leak().Signal.SignalID = SIGKILL;
@@ -118,46 +107,31 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) {
}
EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip) {
- hal_idt_send_eoi(3);
-
auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess();
+ process.Leak().Crash();
- (Void)(Kernel::kout << "Kernel: Process RIP: " << Kernel::hex_number(rip) << Kernel::kendl);
-
- Kernel::kout << "Kernel: SIGTRAP\r";
+ hal_idt_send_eoi(3);
process.Leak().Signal.SignalArg = rip;
process.Leak().Signal.SignalID = SIGTRAP;
process.Leak().Signal.Status = process.Leak().Status;
- Kernel::kout << "Kernel: SIGTRAP status.\r";
-
process.Leak().Status = Kernel::ProcessStatusKind::kFrozen;
}
/// @brief Handle #UD fault.
/// @param rsp
EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) {
- hal_idt_send_eoi(6);
-
- NE_UNUSED(rsp);
-
auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess();
+ process.Leak().Crash();
- if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT ||
- process.Leak().Signal.SignalID == SIGTRAP) {
- dbg_break_point();
- }
-
- Kernel::kout << "Kernel: Undefined Opcode.\r";
+ hal_idt_send_eoi(6);
process.Leak().Signal.SignalArg = rsp;
process.Leak().Signal.SignalID = SIGKILL;
process.Leak().Signal.Status = process.Leak().Status;
- Kernel::kout << "Kernel: SIGKILL status.\r";
-
process.Leak().Crash();
}
@@ -169,19 +143,11 @@ EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx_syscall_index,
hal_idt_send_eoi(50);
if (rcx_syscall_index < kSysCalls.Count()) {
- Kernel::kout << "syscall: Enter Syscall.\r";
-
if (kSysCalls[rcx_syscall_index].fHooked) {
if (kSysCalls[rcx_syscall_index].fProc) {
(kSysCalls[rcx_syscall_index].fProc)((Kernel::VoidPtr) rdx_syscall_struct);
- } else {
- Kernel::kout << "syscall: syscall isn't valid at all! (is nullptr)\r";
}
- } else {
- Kernel::kout << "syscall: syscall isn't hooked at all! (is set to false)\r";
}
-
- Kernel::kout << "syscall: Exit Syscall.\r";
}
}
@@ -193,18 +159,10 @@ EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index,
hal_idt_send_eoi(51);
if (rcx_kerncall_index < kKernCalls.Count()) {
- Kernel::kout << "kerncall: Enter Kernel Call List.\r";
-
if (kKernCalls[rcx_kerncall_index].fHooked) {
if (kKernCalls[rcx_kerncall_index].fProc) {
(kKernCalls[rcx_kerncall_index].fProc)((Kernel::VoidPtr) rdx_kerncall_struct);
- } else {
- Kernel::kout << "kerncall: Kernel call isn't valid at all! (is nullptr)\r";
}
- } else {
- Kernel::kout << "kerncall: Kernel call isn't hooked at all! (is set to false)\r";
}
-
- Kernel::kout << "kerncall: Exit Kernel Call List.\r";
}
}
diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc
index 5394645a..65b522a6 100644
--- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc
+++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc
@@ -129,6 +129,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept {
for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) {
HardwareThreadScheduler::The()[index].Leak()->Kind() = ThreadKind::kAPStandard;
+ HardwareThreadScheduler::The()[index].Leak()->ID() = index;
HardwareThreadScheduler::The()[index].Leak()->Busy(NO);
}
diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
index dd6b9aea..99e1c619 100644
--- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
+++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc
@@ -15,8 +15,6 @@
*
*/
-#if 0
-
#include <ArchKit/ArchKit.h>
#include <KernelKit/DriveMgr.h>
#include <StorageKit/ATA.h>
@@ -85,8 +83,8 @@ ATAInit_Retry:
rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY);
- while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
-
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ))
+ ;
/// fetch serial info
/// model, speed, number of sectors...
@@ -119,21 +117,22 @@ Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sect
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
- while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ))
+ ;
for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) {
drv_pio_std_wait_io(IO);
auto in = rt_in16(IO + ATA_REG_DATA);
- Buf[IndexOff] = in & 0xFF;
+ Buf[IndexOff] = in & 0xFF;
Buf[IndexOff + 1] = (in >> 8) & 0xFF;
}
}
@@ -150,22 +149,23 @@ Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sec
rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
- rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
+ rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF);
rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8);
rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16);
rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24);
rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
- while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ));
+ while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ))
+ ;
for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) {
drv_pio_std_wait_io(IO);
- UInt8 low = (UInt8)Buf[IndexOff];
- UInt8 high = (IndexOff + 1 < Size) ? (UInt8)Buf[IndexOff + 1] : 0;
+ UInt8 low = (UInt8) Buf[IndexOff];
+ UInt8 high = (IndexOff + 1 < Size) ? (UInt8) Buf[IndexOff + 1] : 0;
UInt16 packed = (high << 8) | low;
-
+
rt_out16(IO + ATA_REG_DATA, packed);
}
}
@@ -275,6 +275,4 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster)
return drv_pio_std_init(Bus, Drive, OutBus, OutMaster);
}
-#endif
-
#endif \ No newline at end of file
diff --git a/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc
index 660110b2..dc883239 100644
--- a/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc
+++ b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc
@@ -5,7 +5,7 @@
------------------------------------------- */
#include <ArchKit/ArchKit.h>
-#include <KernelKit/MemoryMgr.h>
+#include <KernelKit/HeapMgr.h>
#include <NeKit/KString.h>
#include <modules/ACPI/ACPIFactoryInterface.h>
#include <modules/APM/APM.h>
diff --git a/dev/kernel/HALKit/ARM64/HalApplicationProcessorStartup.s b/dev/kernel/HALKit/ARM64/HalApplicationProcessorStartup.s
new file mode 100644
index 00000000..dca52571
--- /dev/null
+++ b/dev/kernel/HALKit/ARM64/HalApplicationProcessorStartup.s
@@ -0,0 +1,12 @@
+.text
+
+.global hal_ap_blob_start
+.global hal_ap_blob_length
+
+hal_ap_blob_start:
+ ret
+
+.data
+
+hal_ap_blob_length:
+ .long 4
diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc
index 6f3f3d12..20bd3d8a 100644
--- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc
+++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc
@@ -12,7 +12,7 @@
#include <KernelKit/CodeMgr.h>
#include <KernelKit/FileMgr.h>
#include <KernelKit/HardwareThreadScheduler.h>
-#include <KernelKit/MemoryMgr.h>
+#include <KernelKit/HeapMgr.h>
#include <KernelKit/PEFCodeMgr.h>
#include <KernelKit/ProcessScheduler.h>
#include <NeKit/Json.h>