summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/Sources
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-30 18:46:00 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-30 19:56:02 +0200
commita9d87cbd143b05cc3de711d84401f8ef514f3aa3 (patch)
treecfc703f1dc02f6894b4d6d173d18d84be5757c5f /dev/ZKA/Sources
parent5229ca8ae190c0cb3db8d381a44be4113e81d5dc (diff)
[IMP] Updated the ARM64 release of ZKA.
[IMP] Shall use the timer on AMD64 by default, a SMP driver will be written if needed. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/Sources')
-rw-r--r--dev/ZKA/Sources/DLLMain.cxx12
-rw-r--r--dev/ZKA/Sources/KernelCheck.cxx8
-rw-r--r--dev/ZKA/Sources/MP.cxx46
-rw-r--r--dev/ZKA/Sources/ProcessScheduler.cxx79
-rw-r--r--dev/ZKA/Sources/ProcessTeam.cxx2
5 files changed, 63 insertions, 84 deletions
diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx
index 8562ba09..0cecc820 100644
--- a/dev/ZKA/Sources/DLLMain.cxx
+++ b/dev/ZKA/Sources/DLLMain.cxx
@@ -23,6 +23,7 @@
#include <NewKit/String.hxx>
#include <NewKit/Utils.hxx>
#include <KernelKit/PEFCodeManager.hxx>
+#include <KernelKit/CodeManager.hxx>
#include <CFKit/Property.hxx>
#include <Modules/CoreCG/WindowRenderer.hxx>
#include <KernelKit/Timer.hxx>
@@ -213,8 +214,11 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void)
CG::CGDrawStringToWnd(cKernelWnd, "newoskrnl.dll: Starting ZKA...", 30, 10, RGB(0, 0, 0));
- while (Yes)
- {
- Kernel::ProcessHelper::StartScheduling();
- }
+ Kernel::ProcessHelper::StartScheduling();
+
+ Kernel::execute_from_image([]() -> void {
+ },
+ "ZKA Logger");
+
+ Kernel::ProcessHelper::StartScheduling();
}
diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx
index 3057fe65..85cfe215 100644
--- a/dev/ZKA/Sources/KernelCheck.cxx
+++ b/dev/ZKA/Sources/KernelCheck.cxx
@@ -114,8 +114,8 @@ namespace Kernel
}
};
- while (Yes)
- ;
+ PowerFactoryInterface power(nullptr);
+ power.Reboot();
}
Void RecoveryFactory::Recover() noexcept
@@ -125,8 +125,10 @@ namespace Kernel
HardwareTimer timer(cMaxSeconds);
timer.Wait();
+ kcout << "newoskrnl: Shutting down...\r";
+
PowerFactoryInterface power(nullptr);
- power.Reboot();
+ power.Shutdown();
}
void ke_runtime_check(bool expr, const Char* file, const Char* line)
diff --git a/dev/ZKA/Sources/MP.cxx b/dev/ZKA/Sources/MP.cxx
index da92a8c6..89b5f01d 100644
--- a/dev/ZKA/Sources/MP.cxx
+++ b/dev/ZKA/Sources/MP.cxx
@@ -76,7 +76,10 @@ namespace Kernel
mp_wakeup_thread(fStack);
}
- EXTERN Bool rt_check_stack(HAL::StackFramePtr stackPtr);
+ /// @note Those symbols are needed in order to switch and validate the stack.
+
+ EXTERN Bool hal_check_stack(HAL::StackFramePtr stackPtr);
+ EXTERN_C Void hal_switch_context(HAL::StackFramePtr stackPtr);
/// @brief Switch to hardware thread.
/// @param stack the new hardware thread.
@@ -93,7 +96,7 @@ namespace Kernel
return true;
}
- if (!rt_check_stack(stack))
+ if (!hal_check_stack(stack))
{
return false;
}
@@ -106,7 +109,7 @@ namespace Kernel
fStack = stack;
- rt_do_context_switch(fStack);
+ hal_switch_context(fStack);
return true;
}
@@ -144,12 +147,7 @@ namespace Kernel
/// @brief Get Stack Frame of Core
HAL::StackFramePtr HardwareThreadScheduler::Leak() noexcept
{
- if (fThreadList[fCurrentThread].Leak() &&
- ProcessHelper::TheCurrentPID() ==
- fThreadList[fCurrentThread].Leak().Leak()->fSourcePID)
- return fThreadList[fCurrentThread].Leak().Leak()->fStack;
-
- return nullptr;
+ return fThreadList[fCurrentThread].fStack;
}
/// @brief Finds and switch to a free core.
@@ -161,36 +159,36 @@ namespace Kernel
for (SizeT idx = 0; idx < cMaxHWThreads; ++idx)
{
// stack != nullptr -> if core is used, then continue.
- if (!fThreadList[idx].Leak() ||
- !fThreadList[idx].Leak().Leak()->IsWakeup() ||
- fThreadList[idx].Leak().Leak()->IsBusy())
+ if (!fThreadList[idx] ||
+ !fThreadList[idx].IsWakeup() ||
+ fThreadList[idx].IsBusy())
continue;
// to avoid any null deref.
- if (!fThreadList[idx].Leak().Leak()->fStack)
+ if (!fThreadList[idx].fStack)
continue;
- if (fThreadList[idx].Leak().Leak()->fStack->SP == 0)
+ if (fThreadList[idx].fStack->SP == 0)
continue;
- if (fThreadList[idx].Leak().Leak()->fStack->BP == 0)
+ if (fThreadList[idx].fStack->BP == 0)
continue;
- fThreadList[idx].Leak().Leak()->Busy(true);
+ fThreadList[idx].Busy(true);
- fThreadList[idx].Leak().Leak()->fID = idx;
+ fThreadList[idx].fID = idx;
/// I figured out this:
/// Allocate stack
/// Set APIC base to stack
/// Do stuff and relocate stack based on this code.
/// - Amlel
- rt_copy_memory(stack, fThreadList[idx].Leak().Leak()->fStack,
+ rt_copy_memory(stack, fThreadList[idx].fStack,
sizeof(HAL::StackFrame));
- fThreadList[idx].Leak().Leak()->Switch(fThreadList[idx].Leak().Leak()->fStack);
+ fThreadList[idx].Switch(fThreadList[idx].fStack);
- fThreadList[idx].Leak().Leak()->fSourcePID = ProcessHelper::TheCurrentPID();
+ fThreadList[idx].fSourcePID = ProcessHelper::TheCurrentPID();
- fThreadList[idx].Leak().Leak()->Busy(false);
+ fThreadList[idx].Busy(false);
return true;
}
@@ -207,9 +205,9 @@ namespace Kernel
{
if (idx == 0)
{
- if (fThreadList[idx].Leak().Leak()->Kind() != kHartSystemReserved)
+ if (fThreadList[idx].Kind() != kHartSystemReserved)
{
- fThreadList[idx].Leak().Leak()->fKind = kHartBoot;
+ fThreadList[idx].fKind = kHartBoot;
}
}
else if (idx >= cMaxHWThreads)
@@ -226,7 +224,7 @@ namespace Kernel
return {fakeThread};
}
- return fThreadList[idx].Leak();
+ return &fThreadList[idx];
}
/**
diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx
index 2198cd42..bf2cdbd3 100644
--- a/dev/ZKA/Sources/ProcessScheduler.cxx
+++ b/dev/ZKA/Sources/ProcessScheduler.cxx
@@ -211,7 +211,7 @@ namespace Kernel
/// @brief Add process to list.
/// @param process the process *Ref* class.
/// @return the process index inside the team.
- SizeT ProcessScheduler::Add(Ref<PROCESS_HEADER_BLOCK>& process)
+ SizeT ProcessScheduler::Add(Ref<PROCESS_HEADER_BLOCK> process)
{
if (!process.Leak().Image)
{
@@ -224,24 +224,17 @@ namespace Kernel
if (mTeam.AsArray().Count() > kSchedProcessLimitPerTeam)
return -kErrorOutOfTeamSlot;
- kcout << "ProcessScheduler:: adding process to team...\r";
-
- if (process.Leak().GetOwner() == nullptr)
- {
- // Something went wrong, do not continue, process may be incorrect.
- process.Leak().Crash();
- return -kErrorProcessFault;
- }
+ kcout << "ProcessScheduler: Adding process to team...\r";
// Create heap according to type of process.
if (process.Leak().Kind == PROCESS_HEADER_BLOCK::kAppKind)
{
- process.Leak().HeapPtr = sched_new_heap(kProcessHeapUser | kProcessHeapRw, process.Leak().SizeMemory);
+ process.Leak().HeapPtr = mm_new_ke_heap(process.Leak().SizeMemory, true, true);
}
else if (process.Leak().Kind == PROCESS_HEADER_BLOCK::kSharedObjectKind)
{
- process.Leak().DLLPtr = rtl_init_shared_object(&process.Leak());
- process.Leak().HeapPtr = sched_new_heap(kProcessHeapUser | kProcessHeapRw | kProcessHeapShared, process.Leak().SizeMemory);
+ process.Leak().DLLPtr = rtl_init_shared_object(&process.Leak());
+ process.Leak().HeapPtr = mm_new_ke_heap(process.Leak().SizeMemory, true, true);
}
else
{
@@ -276,7 +269,9 @@ namespace Kernel
process.Leak().ProcessId = (mTeam.AsArray().Count() - 1);
process.Leak().HeapCursor = process.Leak().HeapPtr;
- MUST_PASS(mTeam.AsArray().Add(process));
+ mTeam.AsArray()[process.Leak().ProcessId] = process.Leak();
+
+ kcout << "ProcessScheduler: Adding process to team [ OK ]...\r";
return (mTeam.AsArray().Count() - 1);
}
@@ -302,12 +297,13 @@ namespace Kernel
return false;
// also check if the process isn't a dummy one.
- if (mTeam.AsArray()[processSlot].Leak().Leak().Image == nullptr)
+ if (mTeam.AsArray()[processSlot].Image == nullptr)
return false;
- kcout << "ProcessScheduler: removing process\r";
+ kcout << "ProcessScheduler: Removing process...\r";
- return mTeam.AsArray().Remove(processSlot);
+ mTeam.AsArray()[processSlot].Status = ProcessStatus::kDead;
+ return true;
}
/// @brief Run scheduler.
@@ -322,26 +318,18 @@ namespace Kernel
auto process = mTeam.AsArray()[process_index];
//! check if process needs to be scheduled.
- if (ProcessHelper::CanBeScheduled(process.Leak()))
+ if (ProcessHelper::CanBeScheduled(process))
{
- auto unwrapped_process = *process.Leak();
-
- if (unwrapped_process.Parent->Status == ProcessStatus::kKilled)
- {
- unwrapped_process.Exit();
- continue;
- }
-
// set the current process.
- mTeam.AsRef() = unwrapped_process;
+ mTeam.AsRef() = process;
- // tell helper to find a core to schedule on.
- ProcessHelper::Switch(unwrapped_process.StackFrame,
- unwrapped_process.ProcessId);
+ process.PTime = static_cast<Int32>(process.Affinity);
- unwrapped_process.PTime = static_cast<Int32>(unwrapped_process.Affinity);
+ kcout << process.Name << ": will be runned.\r";
- kcout << unwrapped_process.Name << ": has been switched to a CPU core.\r";
+ // tell helper to find a core to schedule on.
+ ProcessHelper::Switch(process.StackFrame,
+ process.ProcessId);
}
else
{
@@ -381,36 +369,23 @@ namespace Kernel
/// @param process the process reference.
/// @retval true can be schedulded.
/// @retval false cannot be schedulded.
- bool ProcessHelper::CanBeScheduled(Ref<PROCESS_HEADER_BLOCK>& process)
+ bool ProcessHelper::CanBeScheduled(PROCESS_HEADER_BLOCK& process)
{
- if (process.Leak().Status == ProcessStatus::kFrozen ||
- process.Leak().Status == ProcessStatus::kDead)
+ if (process.Status == ProcessStatus::kFrozen ||
+ process.Status == ProcessStatus::kDead)
return false;
- if (process.Leak().Kind == PROCESS_HEADER_BLOCK::kSharedObjectKind)
+ if (process.Kind == PROCESS_HEADER_BLOCK::kSharedObjectKind)
{
- if (auto start = process.Leak().DLLPtr->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart), kPefCode);
+ if (auto start = process.DLLPtr->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart), kPefCode);
start)
{
- process.Leak().Image = start;
- process.Leak().StackFrame->BP = reinterpret_cast<HAL::Reg>(start);
+ process.Image = start;
+ process.StackFrame->BP = reinterpret_cast<HAL::Reg>(start);
}
}
- if (process.Leak().GetStatus() == ProcessStatus::kStarting)
- {
- if (process.Leak().PTime <= 0)
- {
- process.Leak().Status = ProcessStatus::kRunning;
- process.Leak().Affinity = AffinityKind::kStandard;
-
- return true;
- }
-
- ++process.Leak().PTime;
- }
-
- return process.Leak().PTime > 0;
+ return process.PTime > 0;
}
/**
diff --git a/dev/ZKA/Sources/ProcessTeam.cxx b/dev/ZKA/Sources/ProcessTeam.cxx
index 81307d97..c6a26275 100644
--- a/dev/ZKA/Sources/ProcessTeam.cxx
+++ b/dev/ZKA/Sources/ProcessTeam.cxx
@@ -15,7 +15,7 @@ namespace Kernel
{
/// @brief Process list array getter.
/// @return The list of process to schedule.
- MutableArray<Ref<PROCESS_HEADER_BLOCK>>& ProcessTeam::AsArray()
+ Array<PROCESS_HEADER_BLOCK, kSchedProcessLimitPerTeam>& ProcessTeam::AsArray()
{
return mProcessList;
}