summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-06-13 19:38:29 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-06-13 19:38:29 +0200
commit7327f305efb1c6678722308cc5f9645dd39f451e (patch)
tree0e15f4ad6f275aa689f5d66641d3d9ad59d15472 /Kernel/Sources
parent349fe48baf941b2d1b571d3a5d0d796823bae312 (diff)
MHR-31: Lots of fixes and improvements regarding the kernel.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources')
-rw-r--r--Kernel/Sources/HError.cxx3
-rw-r--r--Kernel/Sources/KeMain.cxx5
-rw-r--r--Kernel/Sources/ProcessScheduler.cxx61
-rw-r--r--Kernel/Sources/SMPManager.cxx46
4 files changed, 58 insertions, 57 deletions
diff --git a/Kernel/Sources/HError.cxx b/Kernel/Sources/HError.cxx
index 937e983a..1f36d020 100644
--- a/Kernel/Sources/HError.cxx
+++ b/Kernel/Sources/HError.cxx
@@ -13,6 +13,7 @@ namespace NewOS
/// @return if error-free: true, otherwise false.
Boolean ke_bug_check(void) noexcept
{
- return true;
+ /// TODO:
+ return false;
}
} // namespace NewOS
diff --git a/Kernel/Sources/KeMain.cxx b/Kernel/Sources/KeMain.cxx
index e2f41464..60494ee3 100644
--- a/Kernel/Sources/KeMain.cxx
+++ b/Kernel/Sources/KeMain.cxx
@@ -220,9 +220,4 @@ EXTERN_C NewOS::Void KeMain(NewOS::Void)
auto cLoaderName = "SystemLauncher";
NewOS::execute_from_image(NewOS::Detail::SystemLauncher_Main, cLoaderName);
-
- while (true)
- {
- NewOS::ProcessScheduler::The().Leak().Run();
- }
}
diff --git a/Kernel/Sources/ProcessScheduler.cxx b/Kernel/Sources/ProcessScheduler.cxx
index 08a7971e..7008eafe 100644
--- a/Kernel/Sources/ProcessScheduler.cxx
+++ b/Kernel/Sources/ProcessScheduler.cxx
@@ -18,7 +18,7 @@
///! BUGS: 0
/***********************************************************************************/
-/* This file handles the process scheduling.
+/* This file handles the process scheduling. */
/***********************************************************************************/
namespace NewOS
@@ -42,7 +42,8 @@ namespace NewOS
void ProcessHeader::Crash()
{
- kcout << this->Name << ": crashed. (id = " << number(kErrorProcessFault);
+ kcout << (*this->Name == 0 ? "Unknown" : this->Name) << ": crashed. (id = ";
+ kcout.Number(kErrorProcessFault);
kcout << ")\r";
if (this->Ring != kRingUserKind)
@@ -201,9 +202,6 @@ namespace NewOS
/// @return
SizeT ProcessScheduler::Add(Ref<ProcessHeader>& process)
{
- if (!process)
- return -1;
-
if (!process.Leak().Image)
{
if (process.Leak().Kind != ProcessHeader::kShLibKind)
@@ -212,7 +210,7 @@ namespace NewOS
}
}
- if (!mTeam.AsArray().Count() > kSchedProcessLimitPerTeam)
+ if (mTeam.AsArray().Count() > kSchedProcessLimitPerTeam)
return -kErrorOutOfTeamSlot;
kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r";
@@ -262,8 +260,8 @@ namespace NewOS
{
auto process = mTeam.AsArray()[processIndex];
- MUST_PASS(process); //! no need for a MUST_PASS(process.Leak());, it is
- //! recursive because of the nature of the class;
+ if (!process)
+ continue;
//! run any process needed to be scheduled.
if (ProcessHelper::CanBeScheduled(process.Leak()))
@@ -351,22 +349,11 @@ namespace NewOS
bool ProcessHelper::StartScheduling()
{
- if (ProcessHelper::CanBeScheduled(
- ProcessScheduler::The().Leak().GetCurrent()))
- {
- --ProcessScheduler::The().Leak().GetCurrent().Leak().PTime;
- return false;
- }
-
- auto processRef = ProcessScheduler::The().Leak();
-
- if (!processRef)
- return false; // we have nothing to schedule. simply return.
+ auto& processRef = ProcessScheduler::The().Leak();
+ SizeT ret = processRef.Run();
- SizeT ret = processRef.Run();
-
- kcout << StringBuilder::FromInt(
- "ProcessHelper::StartScheduling() Iterated over {%} jobs inside team.\r", ret);
+ kcout << "newoskrnl: Iterated over: " << number(ret);
+ kcout << " processes.\r";
return true;
}
@@ -384,30 +371,42 @@ namespace NewOS
for (SizeT index = 0UL; index < SMPManager::The().Leak().Count(); ++index)
{
- if (SMPManager::The().Leak()[index].Leak().Kind() == kInvalidHart)
+ if (SMPManager::The().Leak()[index].Leak()->Kind() == kInvalidHart)
continue;
- if (SMPManager::The().Leak()[index].Leak().StackFrame() == the_stack)
+ if (SMPManager::The().Leak()[index].Leak()->StackFrame() == the_stack)
{
- SMPManager::The().Leak()[index].Leak().Busy(false);
+ SMPManager::The().Leak()[index].Leak()->Busy(false);
continue;
}
- if (SMPManager::The().Leak()[index].Leak().IsBusy())
+ if (SMPManager::The().Leak()[index].Leak()->IsBusy())
continue;
- if (SMPManager::The().Leak()[index].Leak().Kind() !=
+ if (SMPManager::The().Leak()[index].Leak()->Kind() !=
ThreadKind::kHartBoot &&
- SMPManager::The().Leak()[index].Leak().Kind() !=
+ SMPManager::The().Leak()[index].Leak()->Kind() !=
ThreadKind::kHartSystemReserved)
{
- SMPManager::The().Leak()[index].Leak().Busy(true);
+ SMPManager::The().Leak()[index].Leak()->Busy(true);
ProcessHelper::GetCurrentPID() = new_pid;
- return SMPManager::The().Leak()[index].Leak().Switch(the_stack);
+ return SMPManager::The().Leak()[index].Leak()->Switch(the_stack);
}
}
return false;
}
+
+ /// @brief this checks if any process is on the team.
+ ProcessScheduler::operator bool()
+ {
+ return mTeam.AsArray().Count() > 0;
+ }
+
+ /// @brief this checks if no process is on the team.
+ bool ProcessScheduler::operator!()
+ {
+ return mTeam.AsArray().Count() == 0;
+ }
} // namespace NewOS
diff --git a/Kernel/Sources/SMPManager.cxx b/Kernel/Sources/SMPManager.cxx
index 99a3b025..683343ff 100644
--- a/Kernel/Sources/SMPManager.cxx
+++ b/Kernel/Sources/SMPManager.cxx
@@ -117,7 +117,7 @@ namespace NewOS
}
rt_do_context_switch(fStack);
-
+
return true;
}
@@ -143,12 +143,12 @@ namespace NewOS
}
/// @brief Get Stack Frame of Core
- HAL::StackFramePtr SMPManager::GetStackFrame() noexcept
+ HAL::StackFramePtr SMPManager::Leak() noexcept
{
if (fThreadList[fCurrentThread].Leak() &&
ProcessHelper::GetCurrentPID() ==
- fThreadList[fCurrentThread].Leak().Leak().fPID)
- return fThreadList[fCurrentThread].Leak().Leak().fStack;
+ fThreadList[fCurrentThread].Leak().Leak()->fPID)
+ return fThreadList[fCurrentThread].Leak().Leak()->fStack;
return nullptr;
}
@@ -163,35 +163,35 @@ namespace NewOS
{
// stack != nullptr -> if core is used, then continue.
if (!fThreadList[idx].Leak() ||
- !fThreadList[idx].Leak().Leak().IsWakeup() ||
- fThreadList[idx].Leak().Leak().IsBusy())
+ !fThreadList[idx].Leak().Leak()->IsWakeup() ||
+ fThreadList[idx].Leak().Leak()->IsBusy())
continue;
// to avoid any null deref.
- if (!fThreadList[idx].Leak().Leak().fStack)
+ if (!fThreadList[idx].Leak().Leak()->fStack)
continue;
- if (fThreadList[idx].Leak().Leak().fStack->Rsp == 0)
+ if (fThreadList[idx].Leak().Leak()->fStack->Rsp == 0)
continue;
- if (fThreadList[idx].Leak().Leak().fStack->Rbp == 0)
+ if (fThreadList[idx].Leak().Leak()->fStack->Rbp == 0)
continue;
- fThreadList[idx].Leak().Leak().Busy(true);
+ fThreadList[idx].Leak().Leak()->Busy(true);
- fThreadList[idx].Leak().Leak().fID = idx;
+ fThreadList[idx].Leak().Leak()->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].Leak().Leak()->fStack,
sizeof(HAL::StackFrame));
- fThreadList[idx].Leak().Leak().Switch(fThreadList[idx].Leak().Leak().fStack);
+ fThreadList[idx].Leak().Leak()->Switch(fThreadList[idx].Leak().Leak()->fStack);
- fThreadList[idx].Leak().Leak().fPID = ProcessHelper::GetCurrentPID();
+ fThreadList[idx].Leak().Leak()->fPID = ProcessHelper::GetCurrentPID();
- fThreadList[idx].Leak().Leak().Busy(false);
+ fThreadList[idx].Leak().Leak()->Busy(false);
return true;
}
@@ -204,19 +204,25 @@ namespace NewOS
* @param idx the index
* @return the reference to the hardware thread.
*/
- Ref<HardwareThread> SMPManager::operator[](const SizeT& idx)
+ Ref<HardwareThread*> SMPManager::operator[](const SizeT& idx)
{
if (idx == 0)
{
- if (fThreadList[idx].Leak().Leak().Kind() != kHartSystemReserved)
+ if (fThreadList[idx].Leak().Leak()->Kind() != kHartSystemReserved)
{
- fThreadList[idx].Leak().Leak().fKind = kHartBoot;
+ fThreadList[idx].Leak().Leak()->fKind = kHartBoot;
}
}
else if (idx >= kMaxHarts)
{
- HardwareThread fakeThread;
- fakeThread.fKind = kInvalidHart;
+ static HardwareThread* fakeThread = new HardwareThread();
+
+ if (!fakeThread)
+ {
+ fakeThread = new HardwareThread();
+ }
+
+ fakeThread->fKind = kInvalidHart;
return {fakeThread};
}