summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/Sources/UserProcessScheduler.cxx
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-09-03 15:34:28 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-09-03 15:34:28 +0200
commit441c1460b29f5003a5478032f17a6c5f486dd1fd (patch)
treec74f48a17b83b62dbd9badde686e09e1bdf49f1f /dev/ZKA/Sources/UserProcessScheduler.cxx
parent7fdb28714eb98d58c55324db51cc7caf97c631bf (diff)
[ FIX ] Almost fixed the ring-3 switch code, which currently gives an UD
error. [ REFACTOR ] Kernel is now a EXE, instead of being a DLL. [ FIX ] Fixed some parts of the user scheduler and kernel, cleaned it up also. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/Sources/UserProcessScheduler.cxx')
-rw-r--r--dev/ZKA/Sources/UserProcessScheduler.cxx39
1 files changed, 19 insertions, 20 deletions
diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx
index c20c6054..cd8ec150 100644
--- a/dev/ZKA/Sources/UserProcessScheduler.cxx
+++ b/dev/ZKA/Sources/UserProcessScheduler.cxx
@@ -48,18 +48,16 @@ namespace Kernel
/// @brief crash current process.
/***********************************************************************************/
- void UserProcess::Crash()
+ Void UserProcess::Crash()
{
- constexpr auto cUnknownProcess = "?";
+ if (this->Name == 0)
+ return;
- kcout << (*this->Name == 0 ? cUnknownProcess : this->Name) << ": crashed. (id = " << number(kErrorProcessFault);
- kcout << ")\r";
-
- this->Status = ProcessStatus::kDead;
+ kcout << this->Name << ": crashed. (id = " << number(kErrorProcessFault) << endl;
this->Exit(kErrorProcessFault);
- ProcessHelper::StartScheduling();
+ UserProcessHelper::StartScheduling();
}
/// @brief Gets the local last exit code.
@@ -186,6 +184,8 @@ namespace Kernel
*/
void UserProcess::Exit(const Int32& exit_code)
{
+ this->Status = ProcessStatus::kDead;
+
fLastExitCode = exit_code;
cLastExitCode = exit_code;
@@ -260,7 +260,7 @@ namespace Kernel
if (!process.StackReserve)
{
process.StackReserve = (UInt8*)mm_new_ke_heap(kSchedMaxStackSz, Yes, Yes);
- kcout << "newoskrnl.dll: Use fallback reserve.\r";
+ kcout << "newoskrnl.exe: Use fallback reserve.\r";
}
}
else
@@ -331,7 +331,7 @@ namespace Kernel
auto& process = mTeam.AsArray()[process_index];
//! check if process needs to be scheduled.
- if (ProcessHelper::CanBeScheduled(process))
+ if (UserProcessHelper::CanBeScheduled(process))
{
// set the current process.
mTeam.AsRef() = process;
@@ -341,7 +341,7 @@ namespace Kernel
kcout << process.Name << ": will be runned.\r";
// tell helper to find a core to schedule on.
- if (!ProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize - 1], process.StackFrame,
+ if (!UserProcessHelper::Switch(process.Image, &process.StackReserve[process.StackSize - 1], process.StackFrame,
process.ProcessId))
{
process.Crash();
@@ -379,9 +379,9 @@ namespace Kernel
/// @brief Current proccess id getter.
/// @return UserProcess ID integer.
- PID& ProcessHelper::TheCurrentPID()
+ PID& UserProcessHelper::TheCurrentPID()
{
- kcout << "ProcessHelper::TheCurrentPID: Leaking ProcessId...\r";
+ kcout << "UserProcessHelper::TheCurrentPID: Leaking ProcessId...\r";
return cProcessScheduler->CurrentProcess().Leak().ProcessId;
}
@@ -389,7 +389,7 @@ namespace Kernel
/// @param process the process reference.
/// @retval true can be schedulded.
/// @retval false cannot be schedulded.
- bool ProcessHelper::CanBeScheduled(UserProcess& process)
+ bool UserProcessHelper::CanBeScheduled(UserProcess& process)
{
if (process.Status == ProcessStatus::kFrozen ||
process.Status == ProcessStatus::kDead)
@@ -401,7 +401,6 @@ namespace Kernel
start)
{
process.Image = start;
- process.StackFrame->BP = reinterpret_cast<HAL::Reg>(start);
}
}
@@ -412,14 +411,14 @@ namespace Kernel
* @brief Scheduler helper class.
*/
- SizeT ProcessHelper::StartScheduling()
+ SizeT UserProcessHelper::StartScheduling()
{
if (!cProcessScheduler)
{
cProcessScheduler = new UserProcessScheduler();
MUST_PASS(cProcessScheduler);
- kcout << "newoskrnl.dll: Team capacity: " << number(cProcessScheduler->CurrentTeam().AsArray().Capacity()) << endl;
+ kcout << "newoskrnl.exe: Team capacity: " << number(cProcessScheduler->CurrentTeam().AsArray().Capacity()) << endl;
}
SizeT ret = cProcessScheduler->Run();
@@ -432,12 +431,12 @@ namespace Kernel
* \param new_pid the process's PID.
*/
- bool ProcessHelper::Switch(VoidPtr image_ptr, UInt8* stack, HAL::StackFramePtr frame_ptr, const PID& new_pid)
+ bool UserProcessHelper::Switch(VoidPtr image_ptr, UInt8* stack, HAL::StackFramePtr frame_ptr, const PID& new_pid)
{
if (!stack || !frame_ptr || !image_ptr || new_pid < 0)
return false;
- kcout << "newoskrnl.dll: Finding hardware thread...\r";
+ kcout << "newoskrnl.exe: Finding hardware thread...\r";
for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Count(); ++index)
{
@@ -454,9 +453,9 @@ namespace Kernel
{
HardwareThreadScheduler::The()[index].Leak()->Busy(true);
- ProcessHelper::TheCurrentPID() = new_pid;
+ UserProcessHelper::TheCurrentPID() = new_pid;
- kcout << "newoskrnl.dll: Found hardware thread...\r";
+ kcout << "newoskrnl.exe: Found hardware thread...\r";
bool ret = HardwareThreadScheduler::The()[index].Leak()->Switch(image_ptr, stack, frame_ptr);