summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/HALKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-31 15:08:15 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-08-31 15:08:15 +0200
commite2a90fce95fde6eaef50e6d99e32b902ec14cc0d (patch)
treea7cc8f17478f9e77019beab9e524d39fe311f775 /dev/ZKA/HALKit
parent2c4b02249ec4355a73b826909ab1889e45871faf (diff)
Source bump.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/HALKit')
-rw-r--r--dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx19
-rw-r--r--dev/ZKA/HALKit/AMD64/HalHart.cxx33
-rw-r--r--dev/ZKA/HALKit/AMD64/HalKernelMain.cxx2
-rw-r--r--dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm37
-rw-r--r--dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx15
-rw-r--r--dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx36
-rw-r--r--dev/ZKA/HALKit/AMD64/Processor.hxx21
-rw-r--r--dev/ZKA/HALKit/ARM64/HalCoreMPScheduler.cxx29
-rw-r--r--dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx17
-rw-r--r--dev/ZKA/HALKit/ARM64/Processor.hxx14
-rw-r--r--dev/ZKA/HALKit/POWER/Processor.hxx14
11 files changed, 137 insertions, 100 deletions
diff --git a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx
index 1f233e08..f022b5e5 100644
--- a/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalCoreMPScheduler.cxx
@@ -5,6 +5,7 @@
------------------------------------------- */
#include <Modules/ACPI/ACPIFactoryInterface.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
#include <HALKit/AMD64/Processor.hxx>
#include <NewKit/KernelCheck.hxx>
#include <ArchKit/ArchKit.hxx>
@@ -133,13 +134,13 @@ namespace Kernel::HAL
Kernel::ke_dma_write(targetAddress, kAPIC_ICR_Low, kAPIC_EIPI_Vector | vector);
}
- EXTERN_C Void hal_switch_context(HAL::StackFramePtr stack_frame);
+ EXTERN_C Bool mp_register_process(HAL::StackFramePtr stack_frame);
/// @brief Called when the AP is ready.
/// @internal
EXTERN_C Void hal_on_ap_startup(HAL::StackFramePtr stack_frame)
{
- hal_switch_context(stack_frame);
+ mp_register_process(stack_frame);
ke_stop(RUNTIME_CHECK_FAILED);
}
@@ -147,20 +148,24 @@ namespace Kernel::HAL
{
UserProcessPtr f_Process;
HAL::StackFramePtr f_Frame;
- } fBlocks[cMaxHWThreads] = {0};
+ } fBlocks[kSchedProcessLimitPerTeam] = {0};
EXTERN_C HAL::StackFramePtr _hal_leak_current_context(Void)
{
- return fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % cMaxHWThreads].f_Frame;
+ return fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame;
}
- EXTERN_C Void hal_switch_context(HAL::StackFramePtr stack_frame)
+ EXTERN_C Bool mp_register_process(HAL::StackFramePtr stack_frame)
{
if (kSMPAware)
{
- fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % cMaxHWThreads].f_Process = &UserProcessScheduler::The().CurrentProcess().Leak();
- fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % cMaxHWThreads].f_Frame = stack_frame;
+ fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Process = &UserProcessScheduler::The().CurrentProcess().Leak();
+ fBlocks[UserProcessScheduler::The().CurrentProcess().Leak().ProcessId % kSchedProcessLimitPerTeam].f_Frame = stack_frame;
+
+ return true;
}
+
+ return false;
}
/***********************************************************************************/
diff --git a/dev/ZKA/HALKit/AMD64/HalHart.cxx b/dev/ZKA/HALKit/AMD64/HalHart.cxx
deleted file mode 100644
index b438f303..00000000
--- a/dev/ZKA/HALKit/AMD64/HalHart.cxx
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Technologies.
-
-------------------------------------------- */
-
-#include <ArchKit/ArchKit.hxx>
-
-// bugs = 0
-
-namespace Kernel
-{
- /// @brief wakes up thread.
- /// wakes up thread from hang.
- void mp_wakeup_thread(HAL::StackFrame* stack)
- {
- HAL::rt_cli();
-
- mp_do_context_switch(stack);
-
- HAL::rt_sti();
- }
-
- /// @brief makes the thread sleep on a loop.
- /// hooks and hangs thread to prevent code from executing.
- void mp_hang_thread(HAL::StackFrame* stack)
- {
- while (true)
- {
- /* nohing, code is spinning */
- }
- }
-} // namespace Kernel
diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
index e2331ba6..31a47f00 100644
--- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
@@ -52,7 +52,7 @@ namespace Kernel::HAL
{
/// @brief Gets the system cores using the MADT.
/// @param rsdPtr The 'RSD PTR' data structure.
- EXTERN void mp_get_cores(Kernel::voidPtr rsdPtr);
+ EXTERN void mp_get_cores(Kernel::voidPtr rsdPtr) noexcept;
} // namespace Kernel::HAL
/* GDT. */
diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
index 6b3ed33a..98dbfa02 100644
--- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
+++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
@@ -11,24 +11,43 @@
[global mp_get_current_context]
[global mp_do_context_switch]
-[global _hal_spin_core]
[extern _hal_switch_context]
[extern _hal_leak_current_context]
section .text
-;; writes to rdx the stackframe inside rcx.
-;; rcx: Stack Pointer
-;; rdx: SMP core address.
+;; Does a user mode switch, and then loads the task to be run.
+;; rcx: code ptr.
+;; rdx: stack ptr.
mp_do_context_switch:
- jmp $
+ mov r11, rdx
+ mov r12, rcx
+
+ ; Enable SCE that enables sysret and syscall
+ mov rcx, 0xc0000082
+ wrmsr
+ mov rcx, 0xc0000080
+ rdmsr
+ or eax, 1
+ wrmsr
+ mov rcx, 0xc0000081
+ rdmsr
+ mov edx, 0x00180008
+ wrmsr
+
+ mov rcx, r11
+ mov rdx, r12
+ mov r11, 0x202
+
+ ;; rcx and rdx already set.
+ o64 sysret
ret
+mp_do_context_switch_fail:
+ jmp $
+
+
;; @brief Gets the current stack frame.
mp_get_current_context:
call _hal_leak_current_context
ret
-
-_hal_spin_core:
- jmp $
- ret
diff --git a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx
index cad215b2..4e1b500c 100644
--- a/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalPageAlloc.cxx
@@ -97,7 +97,20 @@ namespace Kernel
kAllocationInProgress = false;
- return reinterpret_cast<VoidPtr>(vmh_header + sizeof(Detail::VIRTUAL_MEMORY_HEADER));
+ auto result = reinterpret_cast<VoidPtr>(vmh_header + sizeof(Detail::VIRTUAL_MEMORY_HEADER));
+
+ VoidPtr cr3_value;
+
+ asm volatile(
+ "mov %%cr3, %0" // Move CR3 into the variable
+ : "=r"(cr3_value) // Output operand, cr3 page directory.
+ : // No input operands
+ : "memory"
+ );
+
+ mm_update_page(cr3_value, 0, (UIntPtr)result, eFlagsPresent | (rw ? eFlagsRw : 0) | (user ? eFlagsUser : 0));
+
+ return result;
}
/// @brief Allocate a new page to be used by the OS.
diff --git a/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx b/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx
index cb849150..a63328ab 100644
--- a/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalSchedulerCore.cxx
@@ -4,17 +4,28 @@
------------------------------------------- */
+#include <HALKit/AMD64/Processor.hxx>
#include <KernelKit/UserProcessScheduler.hxx>
using namespace Kernel;
-Void UserProcess::SetEntrypoint(UIntPtr& imageStart) noexcept
+Void UserProcess::SetEntrypoint(VoidPtr imageStart) noexcept
{
- if (imageStart == 0)
+ if (imageStart == nullptr)
this->Crash();
- this->StackFrame->BP = imageStart;
- this->StackFrame->SP = this->StackFrame->BP;
+
+ VoidPtr cr3_pd;
+
+ asm volatile(
+ "mov %%cr3, %0" // Move CR3 into the variable
+ : "=r"(cr3_pd) // Output operand, cr3 page directory.
+ : // No input operands
+ : "memory");
+
+ HAL::mm_update_page(cr3_pd, 0, (UIntPtr)imageStart, HAL::eFlagsPresent | HAL::eFlagsRw | HAL::eFlagsUser);
+
+ this->Image = imageStart;
}
namespace Kernel
@@ -29,4 +40,21 @@ namespace Kernel
return true;
}
+
+ /// @brief Wakes up thread.
+ /// Wakes up thread from the hang state.
+ Void mp_wakeup_thread(HAL::StackFrame* stack)
+ {
+ mp_do_context_switch((VoidPtr)stack->BP, (UInt8*)stack->SP, 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)
+ {
+ while (Yes)
+ {
+ /* Nothing to do, code is spinning */
+ }
+ }
} // namespace Kernel
diff --git a/dev/ZKA/HALKit/AMD64/Processor.hxx b/dev/ZKA/HALKit/AMD64/Processor.hxx
index b307e0f2..94490e4e 100644
--- a/dev/ZKA/HALKit/AMD64/Processor.hxx
+++ b/dev/ZKA/HALKit/AMD64/Processor.hxx
@@ -128,18 +128,23 @@ namespace Kernel::HAL
};
using RawRegister = UInt64;
-
- using InterruptId = UInt16; /* For each element in the IVT */
-
- typedef UIntPtr Reg;
+ using Reg = RawRegister;
+ using InterruptId = UInt16; /* For each element in the IVT */
+
/// @brief Stack frame (as retrieved from assembly.)
struct PACKED StackFrame final
{
- Reg IntNum, Exception;
- Reg A0, A2, BP, SP, A3, A4, A5, A6;
- Reg R8, R9, R10, R11, R12, R13, R14, R15;
- Reg Gs, Fs;
+ UIntPtr R8{0};
+ UIntPtr R9{0};
+ UIntPtr R10{0};
+ UIntPtr R11{0};
+ UIntPtr R12{0};
+ UIntPtr R13{0};
+ UIntPtr R14{0};
+ UIntPtr R15{0};
+ UIntPtr BP{0};
+ UIntPtr SP{0};
};
typedef StackFrame* StackFramePtr;
diff --git a/dev/ZKA/HALKit/ARM64/HalCoreMPScheduler.cxx b/dev/ZKA/HALKit/ARM64/HalCoreMPScheduler.cxx
deleted file mode 100644
index 20c39684..00000000
--- a/dev/ZKA/HALKit/ARM64/HalCoreMPScheduler.cxx
+++ /dev/null
@@ -1,29 +0,0 @@
-/* -------------------------------------------
-
- Copyright ZKA Technologies.
-
-------------------------------------------- */
-
-#include <ArchKit/ArchKit.hxx>
-
-// bugs = 0
-
-namespace Kernel
-{
- /// @brief Wakes up thread.
- /// Wakes up thread from the hang state.
- Void mp_wakeup_thread(HAL::StackFrame* stack)
- {
- mp_do_context_switch(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)
- {
- while (Yes)
- {
- /* Nothing to do, code is spinning */
- }
- }
-} // namespace Kernel
diff --git a/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx b/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx
index 00eaed27..74e37d91 100644
--- a/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx
+++ b/dev/ZKA/HALKit/ARM64/HalSchedulerCore.cxx
@@ -28,4 +28,21 @@ namespace Kernel
return true;
}
+
+ /// @brief Wakes up thread.
+ /// Wakes up thread from the hang state.
+ Void mp_wakeup_thread(HAL::StackFrame* stack)
+ {
+ mp_do_context_switch(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)
+ {
+ while (Yes)
+ {
+ /* Nothing to do, code is spinning */
+ }
+ }
} // namespace Kernel
diff --git a/dev/ZKA/HALKit/ARM64/Processor.hxx b/dev/ZKA/HALKit/ARM64/Processor.hxx
index 985dfe64..7660dd5b 100644
--- a/dev/ZKA/HALKit/ARM64/Processor.hxx
+++ b/dev/ZKA/HALKit/ARM64/Processor.hxx
@@ -33,10 +33,16 @@ namespace Kernel::HAL
/// @note let's keep the same name as AMD64 HAL.
struct PACKED StackFrame final
{
- Reg IntNum, Exception;
- Reg A0, A2, BP, SP, A3, A4, A5, A6;
- Reg R8, R9, R10, R11, R12, R13, R14, R15;
- Reg Gs, Fs;
+ 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 BP{0};
+ Reg SP{0};
};
typedef StackFrame* StackFramePtr;
diff --git a/dev/ZKA/HALKit/POWER/Processor.hxx b/dev/ZKA/HALKit/POWER/Processor.hxx
index 4b03af4b..ca11bf08 100644
--- a/dev/ZKA/HALKit/POWER/Processor.hxx
+++ b/dev/ZKA/HALKit/POWER/Processor.hxx
@@ -21,10 +21,16 @@ namespace Kernel::HAL
/// @brief Stack frame (as retrieved from assembly.)
struct PACKED StackFrame final
{
- Reg IntNum, Exception;
- Reg A0, A2, BP, SP, A3, A4, A5, A6;
- Reg R8, R9, R10, R11, R12, R13, R14, R15;
- Reg Gs, Fs;
+ 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 BP{0};
+ Reg SP{0};
};
typedef StackFrame* StackFramePtr;