summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-09-28 17:01:48 +0200
committerGitHub <noreply@github.com>2025-09-28 17:01:48 +0200
commit2117a9b0f4b84f5bd6c99566bcf5849a64104467 (patch)
tree590b20056c62d04a496aa22f6bee0034a1430e4e /dev/kernel/HALKit
parent0f88e96c0cf7ffaccecae94794024164c510f735 (diff)
parentb1302067703566624390d780dffd621bb99bb439 (diff)
Merge pull request #64 from nekernel-org/dev
ver: `kernel` v0.0.6
Diffstat (limited to 'dev/kernel/HALKit')
-rw-r--r--dev/kernel/HALKit/AMD64/CxxAbi.cc15
-rw-r--r--dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc13
-rw-r--r--dev/kernel/HALKit/AMD64/HalDebugOutput.cc2
-rw-r--r--dev/kernel/HALKit/AMD64/HalKernelMain.cc39
-rw-r--r--dev/kernel/HALKit/ARM64/HalHandoverStub.s8
-rw-r--r--dev/kernel/HALKit/ARM64/HalKernelMain.cc22
6 files changed, 33 insertions, 66 deletions
diff --git a/dev/kernel/HALKit/AMD64/CxxAbi.cc b/dev/kernel/HALKit/AMD64/CxxAbi.cc
index cd135abc..84a00449 100644
--- a/dev/kernel/HALKit/AMD64/CxxAbi.cc
+++ b/dev/kernel/HALKit/AMD64/CxxAbi.cc
@@ -62,17 +62,18 @@ EXTERN_C void __cxa_finalize(void* f) {
}
namespace cxxabiv1 {
-EXTERN_C int __cxa_guard_acquire(__guard* g) {
- (void) g;
+EXTERN_C int __cxa_guard_acquire(__guard g) {
+ if ((*g & 1) || (*g & 2)) return 1;
+ *g |= 2;
return 0;
}
-EXTERN_C int __cxa_guard_release(__guard* g) {
- *(char*) g = 1;
- return 0;
+EXTERN_C void __cxa_guard_release(__guard g) {
+ *g |= 1;
+ *g &= 2;
}
-EXTERN_C void __cxa_guard_abort(__guard* g) {
- (void) g;
+EXTERN_C void __cxa_guard_abort(__guard g) {
+ *g &= ~2;
}
} // namespace cxxabiv1
diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc
index df5386e4..e3e08830 100644
--- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc
+++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc
@@ -88,7 +88,7 @@ struct LAPIC final {
/// @param target
/// @return
/***********************************************************************************/
-Void hal_send_ipi_msg(UInt32 target, UInt32 apic_id, UInt8 vector) {
+EXTERN_C Void hal_send_ipi_msg(UInt32 target, UInt32 apic_id, UInt8 vector) {
Kernel::ke_dma_write<UInt32>(target, APIC_ICR_HIGH, apic_id << 24);
Kernel::ke_dma_write<UInt32>(target, APIC_ICR_LOW, 0x00000600 | 0x00004000 | 0x00000000 | vector);
@@ -200,10 +200,7 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept {
UInt8 type = *entry_ptr;
UInt8 length = *(entry_ptr + 1);
- // Avoid infinite loop on bad APIC tables.
- if (length < 2) break;
-
- if (type == 0) {
+ if (type == 0 && length == sizeof(struct LAPIC)) {
volatile LAPIC* entry_struct = (volatile LAPIC*) entry_ptr;
if (entry_struct->Flags & 0x1) {
@@ -212,15 +209,15 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept {
++kSMPCount;
- kout << "Kind: LAPIC: ON\r";
+ kout << "AP: kind: LAPIC: ON.\r";
// 0x7c00, as recommended by the Intel SDM.
hal_send_ipi_msg(kApicBaseAddress, entry_struct->ProcessorID, 0x7c);
} else {
- kout << "Kind: LAPIC: OFF\r";
+ kout << "AP: kind: LAPIC: OFF.\r";
}
} else {
- kout << "Kind: UNKNOWN: OFF\r";
+ kout << "AP: kind: UNKNOWN: OFF.\r";
}
entry_ptr += length;
diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
index 1e9fbab3..789c1067 100644
--- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
+++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc
@@ -57,7 +57,9 @@ namespace Detail {
TerminalDevice::~TerminalDevice() = default;
+#ifdef __DEBUG__
STATIC SizeT kX = kFontSizeX, kY = kFontSizeY;
+#endif // __DEBUG__
EXTERN_C void ke_utf_io_write(DeviceInterface<const Utf8Char*>* obj, const Utf8Char* bytes) {
NE_UNUSED(bytes);
diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc
index f121fbb4..6f4d7e0a 100644
--- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc
+++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc
@@ -32,17 +32,14 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
HAL::rt_sti();
- kHandoverHeader = handover_hdr;
-
- FB::fb_clear_video();
-
fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]);
Boot::ExitBootServices(handover_hdr->f_HardwareTables.f_ImageKey,
handover_hdr->f_HardwareTables.f_ImageHandle);
- kBitMapCursor = 0UL;
- kKernelVM = kHandoverHeader->f_PageStart;
+ kHandoverHeader = handover_hdr;
+
+ kKernelVM = kHandoverHeader->f_PageStart;
if (!kKernelVM) {
MUST_PASS(kKernelVM);
@@ -55,6 +52,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
/* INITIALIZE BIT MAP. */
/************************************** */
+ kBitMapCursor = 0UL;
kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
kKernelBitMpStart =
reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(kHandoverHeader->f_BitMapStart));
@@ -120,6 +118,8 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
kGDTArray[4].fFlags = 0;
kGDTArray[4].fBaseHigh = 0;
+ FB::fb_clear_video();
+
// Load memory descriptors.
HAL::Register64 gdt_reg;
@@ -133,24 +133,14 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
return kEfiFail;
}
-EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept {
+EXTERN_C Kernel::Void hal_real_init(Kernel::Void) {
using namespace Kernel;
- 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);
- }
-
- for (SizeT index = 0UL; index < UserProcessScheduler::The().TheCurrentTeam().AsArray().Count();
- ++index) {
- UserProcessScheduler::The().TheCurrentTeam().AsArray()[index].Status =
- ProcessStatusKind::kInvalid;
- }
+ HAL::Register64 idt_reg;
+ idt_reg.Base = reinterpret_cast<UIntPtr>(kInterruptVectorTable);
- rtl_create_user_process(sched_idle_task, "MgmtSrv"); //! Mgmt command server.
- rtl_create_user_process(sched_idle_task, "LaunchSrv"); //! launchd
- rtl_create_user_process(sched_idle_task, "SecSrv"); //! Login Server
+ HAL::IDTLoader idt_loader;
+ idt_loader.Load(idt_reg);
HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
@@ -162,13 +152,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept {
NeFS::fs_init_nefs();
#endif
- HAL::Register64 idt_reg;
- idt_reg.Base = reinterpret_cast<UIntPtr>(kInterruptVectorTable);
-
- HAL::IDTLoader idt_loader;
-
- idt_loader.Load(idt_reg);
-
while (YES)
;
}
diff --git a/dev/kernel/HALKit/ARM64/HalHandoverStub.s b/dev/kernel/HALKit/ARM64/HalHandoverStub.s
index 7c70ebfd..c0e7cb2b 100644
--- a/dev/kernel/HALKit/ARM64/HalHandoverStub.s
+++ b/dev/kernel/HALKit/ARM64/HalHandoverStub.s
@@ -9,11 +9,11 @@
.section .ldr
- ;; MAGIC
+ ;; // MAGIC
.quad 0xDAB4
- ;; VERSION (1.0.0)
+ ;; // VERSION (1.0.0)
.word 100
- ;; CPU (ARM64)
+ ;; // CPU (ARM64)
.word 0
- ;; TYPE (KERNEL)
+ ;; // TYPE (KERNEL)
.word 122
diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc
index d7663f4e..b711b833 100644
--- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc
+++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc
@@ -35,10 +35,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
return;
}
- FB::fb_clear_video();
-
- kBitMapCursor = 0UL;
-
#ifdef __NE_ARM64_EFI__
fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]);
@@ -46,31 +42,19 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) {
handover_hdr->f_HardwareTables.f_ImageHandle);
#endif
+ FB::fb_clear_video();
+
/************************************** */
/* INITIALIZE BIT MAP. */
/************************************** */
+ kBitMapCursor = 0UL;
kKernelBitMpSize = kHandoverHeader->f_BitMapSize;
kKernelBitMpStart = reinterpret_cast<Kernel::VoidPtr>(
reinterpret_cast<Kernel::UIntPtr>(kHandoverHeader->f_BitMapStart));
/// @note do initialize the interrupts after it.
- for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) {
- HardwareThreadScheduler::The()[index].Leak()->Kind() = ThreadKind::kAPStandard;
- HardwareThreadScheduler::The()[index].Leak()->Busy(NO);
- }
-
- for (SizeT index = 0UL; index < UserProcessScheduler::The().TheCurrentTeam().AsArray().Count();
- ++index) {
- UserProcessScheduler::The().TheCurrentTeam().AsArray()[index].Status =
- ProcessStatusKind::kInvalid;
- }
-
- rtl_create_user_process(sched_idle_task, "MgmtSrv"); //! Mgmt command server.
- rtl_create_user_process(sched_idle_task, "LaunchSrv"); //! launchd
- rtl_create_user_process(sched_idle_task, "SecSrv"); //! Login Server
-
Kernel::mp_init_cores();
while (YES)