From 7327f305efb1c6678722308cc5f9645dd39f451e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 13 Jun 2024 19:38:29 +0200 Subject: MHR-31: Lots of fixes and improvements regarding the kernel. Signed-off-by: Amlal El Mahrouss --- Kernel/HALKit/AMD64/HalHart.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Kernel/HALKit/AMD64/HalHart.cpp (limited to 'Kernel/HALKit/AMD64/HalHart.cpp') diff --git a/Kernel/HALKit/AMD64/HalHart.cpp b/Kernel/HALKit/AMD64/HalHart.cpp new file mode 100644 index 00000000..92e075aa --- /dev/null +++ b/Kernel/HALKit/AMD64/HalHart.cpp @@ -0,0 +1,30 @@ +/* ------------------------------------------- + + Copyright Zeta Electronics Corporation + +------------------------------------------- */ + +#include + +// bugs = 0 + +namespace NewOS +{ + /// @brief wakes up thread. + /// wakes up thread from hang. + void rt_wakeup_thread(HAL::StackFrame* stack) + { + HAL::rt_cli(); + + HAL::rt_sti(); + } + + /// @brief makes thread sleep. + /// hooks and hangs thread to prevent code from executing. + void rt_hang_thread(HAL::StackFrame* stack) + { + HAL::rt_cli(); + + HAL::rt_sti(); + } +} // namespace NewOS -- cgit v1.2.3 From 1efed3cbec879134d55aee8e13c6bbc6da9b6ef6 Mon Sep 17 00:00:00 2001 From: Amlal EL Mahrouss Date: Sat, 15 Jun 2024 09:38:25 +0200 Subject: MHR-31: Changes related to ARM64/AMD64: This is the last commit regarding AMD64 support, focusing on ARM64 now. Signed-off-by: Amlal EL Mahrouss --- Boot/Sources/ovmf.ps1 | 4 -- Boot/download-ovmf.ps1 | 4 ++ .../HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp | 7 +--- Kernel/HALKit/AMD64/HalHart.cpp | 12 ++++-- Kernel/HALKit/AMD64/HalKernelMouse.cxx | 2 +- Kernel/HALKit/AMD64/HalSMPCoreManager.asm | 48 ++++++---------------- Kernel/KernelRsrc.rsrc | 2 +- ReadMe.md | 2 +- 8 files changed, 30 insertions(+), 51 deletions(-) delete mode 100644 Boot/Sources/ovmf.ps1 create mode 100644 Boot/download-ovmf.ps1 (limited to 'Kernel/HALKit/AMD64/HalHart.cpp') diff --git a/Boot/Sources/ovmf.ps1 b/Boot/Sources/ovmf.ps1 deleted file mode 100644 index 5a2c5f0e..00000000 --- a/Boot/Sources/ovmf.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -$client = new-object System.Net.WebClient -$output = "$PSScriptRoot\OVMF.fd" - -$client.DownloadFile("https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd", $output) diff --git a/Boot/download-ovmf.ps1 b/Boot/download-ovmf.ps1 new file mode 100644 index 00000000..5a2c5f0e --- /dev/null +++ b/Boot/download-ovmf.ps1 @@ -0,0 +1,4 @@ +$client = new-object System.Net.WebClient +$output = "$PSScriptRoot\OVMF.fd" + +$client.DownloadFile("https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd", $output) diff --git a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp index 37a681ab..26773640 100644 --- a/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp +++ b/Kernel/HALKit/AMD64/HalCoreMultiProcessingAMD64.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #define kAPIC_ICR_Low 0x300 #define kAPIC_ICR_High 0x310 @@ -184,11 +185,7 @@ namespace NewOS::HAL { Semaphore sem; - while (sem.IsLocked()) - { - } - - sem.Lock(&ProcessScheduler::The().Leak().GetCurrent().Leak()); + sem.LockOrWait(&ProcessScheduler::The().Leak().GetCurrent().Leak(), Seconds(5)); cFramePtr = stackFrame; diff --git a/Kernel/HALKit/AMD64/HalHart.cpp b/Kernel/HALKit/AMD64/HalHart.cpp index 92e075aa..069f3767 100644 --- a/Kernel/HALKit/AMD64/HalHart.cpp +++ b/Kernel/HALKit/AMD64/HalHart.cpp @@ -16,15 +16,19 @@ namespace NewOS { HAL::rt_cli(); + rt_do_context_switch(stack); + HAL::rt_sti(); } - /// @brief makes thread sleep. + /// @brief makes the thread sleep on a loop. /// hooks and hangs thread to prevent code from executing. void rt_hang_thread(HAL::StackFrame* stack) { - HAL::rt_cli(); - - HAL::rt_sti(); + while (true) + { + /* nohing, code is spinning */ + } + } } // namespace NewOS diff --git a/Kernel/HALKit/AMD64/HalKernelMouse.cxx b/Kernel/HALKit/AMD64/HalKernelMouse.cxx index 8dbd328a..5d50e4f2 100644 --- a/Kernel/HALKit/AMD64/HalKernelMouse.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMouse.cxx @@ -10,7 +10,7 @@ #include #include -// forward decl. +/// @note forward decl. EXTERN_C NewOS::Boolean _hal_draw_mouse(); EXTERN_C NewOS::Void _hal_init_mouse(); diff --git a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm index c4042b50..320120a4 100644 --- a/Kernel/HALKit/AMD64/HalSMPCoreManager.asm +++ b/Kernel/HALKit/AMD64/HalSMPCoreManager.asm @@ -22,59 +22,37 @@ section .text ;; rcx: Stack Pointer ;; rdx: SMP core address. rt_do_context_switch: - push rax push rcx - push rdx - push rbx - push rbp - push rsi - push rdi - push r8 - push r9 - push r10 - push r11 - push r12 - push r13 - push r14 - push r15 + push rax - jmp _hal_switch_context + call _hal_switch_context - pop r15 - pop r14 - pop r13 - pop r12 - pop r11 - pop r10 - pop r9 - pop r8 - pop rdi - pop rsi - pop rbp - pop rbx - pop rdx pop rcx pop rax - - mov eax, 0 - retfq ;; gets the current stack frame. rt_get_current_context: - push rdx + push rax + jmp _hal_leak_current_context - mov rdx, rax - pop rdx + + mov rax, r9 + pop rax + + mov r9, rax + retfq ;; @brief enables a smp core to run. _hal_enable_smp: -; Read the APIC base MSR + ; Read the APIC base MSR mov ecx, 0x1B ; IA32_APIC_BASE MSR rdmsr + ; Enable the APIC by setting bit 11 (APIC Global Enable) or rdx, 0x800 + ; Set the base address (0xFEE00000) mov eax, 0xFEE shl rax, 12 diff --git a/Kernel/KernelRsrc.rsrc b/Kernel/KernelRsrc.rsrc index 5c166c13..39b3070a 100644 --- a/Kernel/KernelRsrc.rsrc +++ b/Kernel/KernelRsrc.rsrc @@ -11,7 +11,7 @@ BEGIN BLOCK "080904E4" BEGIN VALUE "CompanyName", "Zeta Electronics Corporation" - VALUE "FileDescription", "NuX/OS kernel." + VALUE "FileDescription", "Zeta OS kernel." VALUE "FileVersion", KERNEL_VERSION VALUE "InternalName", "NeXUS" VALUE "LegalCopyright", "Zeta Electronics Corporation" diff --git a/ReadMe.md b/ReadMe.md index df4685a9..1164bfb0 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,4 +1,4 @@ - +
-- cgit v1.2.3