summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-03-08 11:45:31 +0000
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-03-08 11:45:31 +0000
commit842d35cdd8511adf379c4ccb52010b9b71e0757f (patch)
tree5d49b59f49d633fe10aaf416056b2a413f60f1e8
parentdb0c8756f85c4a1f1f7770b704528d135ed765b9 (diff)
HCR-14:
- Improve kernel scheduler. - Defined a ProcessTeam object. - Define an entrypoint for a PE personality as a helper macro.
-rw-r--r--Private/Drivers/HPET/.gitkeep0
-rw-r--r--Private/KernelKit/PE.hpp2
-rw-r--r--Private/KernelKit/ProcessManager.hpp14
-rw-r--r--Private/KernelKit/ProcessTeam.hpp35
-rw-r--r--Private/Source/ProcessManager.cxx27
-rw-r--r--Private/Source/ProcessTeam.cxx3
-rw-r--r--Public/Kits/HCoreKit/kernel.h27
-rw-r--r--Public/Kits/ObjC/base_api.h11
-rw-r--r--Public/Kits/ObjC/base_object.h20
9 files changed, 61 insertions, 78 deletions
diff --git a/Private/Drivers/HPET/.gitkeep b/Private/Drivers/HPET/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/Private/Drivers/HPET/.gitkeep
diff --git a/Private/KernelKit/PE.hpp b/Private/KernelKit/PE.hpp
index c9e4e19c..9ab094d9 100644
--- a/Private/KernelKit/PE.hpp
+++ b/Private/KernelKit/PE.hpp
@@ -118,4 +118,6 @@ typedef struct ExecImportDirectory {
U32 mThunkTableRva;
} ExecImportDirectory, *ExecImportDirectoryPtr;
+#define kPeStart "__hcore_subsys_start"
+
#endif /* ifndef __PE__ */
diff --git a/Private/KernelKit/ProcessManager.hpp b/Private/KernelKit/ProcessManager.hpp
index 277a2985..d7a3d39e 100644
--- a/Private/KernelKit/ProcessManager.hpp
+++ b/Private/KernelKit/ProcessManager.hpp
@@ -9,6 +9,7 @@
#include <ArchKit/ArchKit.hpp>
#include <KernelKit/FileManager.hpp>
+#include <KernelKit/ProcessTeam.hpp>
#include <KernelKit/PermissionSelector.hxx>
#include <NewKit/LockDelegate.hpp>
#include <NewKit/MutableArray.hpp>
@@ -191,11 +192,13 @@ class ProcessManager final {
HCORE_COPY_DEFAULT(ProcessManager)
- operator bool() { return m_Headers.Count() > 0; }
- bool operator!() { return m_Headers.Count() == 0; }
+ operator bool() { return mTeam.AsArray().Count() > 0; }
+ bool operator!() { return mTeam.AsArray().Count() == 0; }
- bool Add(Ref<Process> &Header);
- bool Remove(SizeT Header);
+ ProcessTeam& CurrentTeam() { return mTeam; }
+
+ SizeT Add(Ref<Process> &headerRef);
+ bool Remove(SizeT headerIndex);
Ref<Process> &GetCurrent();
SizeT Run() noexcept;
@@ -203,8 +206,7 @@ class ProcessManager final {
static Ref<ProcessManager> Shared();
private:
- MutableArray<Ref<Process>> m_Headers;
- Ref<Process> m_CurrentProcess;
+ ProcessTeam mTeam;
};
/*
diff --git a/Private/KernelKit/ProcessTeam.hpp b/Private/KernelKit/ProcessTeam.hpp
new file mode 100644
index 00000000..1fb78d1d
--- /dev/null
+++ b/Private/KernelKit/ProcessTeam.hpp
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+#include <ArchKit/ArchKit.hpp>
+#include <KernelKit/FileManager.hpp>
+#include <KernelKit/PermissionSelector.hxx>
+#include <NewKit/LockDelegate.hpp>
+#include <NewKit/MutableArray.hpp>
+#include <NewKit/UserHeap.hpp>
+
+/// kernel namespace
+namespace HCore {
+/// \brief Processs Team (contains multiple processes inside it.)
+/// Equivalent to a process batch
+class ProcessTeam final {
+public:
+ explicit ProcessTeam() = default;
+ ~ProcessTeam() = default;
+
+ HCORE_COPY_DEFAULT(ProcessTeam);
+
+ MutableArray<Ref<Process>>& AsArray() { return mProcessList; }
+ Ref<Process>& AsRef() { return mCurrentProcess; }
+
+public:
+ MutableArray<Ref<Process>> mProcessList;
+ Ref<Process> mCurrentProcess;
+
+};
+} // namespace HCore \ No newline at end of file
diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx
index 37293aa5..bb952186 100644
--- a/Private/Source/ProcessManager.cxx
+++ b/Private/Source/ProcessManager.cxx
@@ -145,15 +145,15 @@ void Process::Exit(Int32 exit_code) {
ProcessManager::Shared().Leak().Remove(this->ProcessId);
}
-bool ProcessManager::Add(Ref<Process> &process) {
- if (!process) return false;
+SizeT ProcessManager::Add(Ref<Process> &process) {
+ if (!process) return -1;
- if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) return false;
+ if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) return -1;
kcout << "ProcessManager::Add(Ref<Process>& process)\r\n";
process.Leak().HeapPtr = ke_new_heap(kPoolUser | kPoolRw);
- process.Leak().ProcessId = this->m_Headers.Count();
+ process.Leak().ProcessId = mTeam.AsArray().Count();
process.Leak().HeapCursor = process.Leak().HeapPtr;
process.Leak().StackFrame = reinterpret_cast<HAL::StackFrame *>(
@@ -165,7 +165,7 @@ bool ProcessManager::Add(Ref<Process> &process) {
process.Leak().AssignStart(imageStart);
- this->m_Headers.Add(process);
+ mTeam.AsArray().Add(process);
if (!imageStart && process.Leak().Kind == Process::ExecutableType) {
process.Leak().Crash();
@@ -178,23 +178,23 @@ bool ProcessManager::Add(Ref<Process> &process) {
ke_stop(RUNTIME_CHECK_PROCESS);
}
- return true;
+ return mTeam.AsArray().Count() - 1;
}
bool ProcessManager::Remove(SizeT process) {
- if (process > this->m_Headers.Count()) return false;
+ if (process > mTeam.AsArray().Count()) return false;
kcout << "ProcessManager::Remove(SizeT process)\r\n";
- return this->m_Headers.Remove(process);
+ return mTeam.AsArray().Remove(process);
}
SizeT ProcessManager::Run() noexcept {
SizeT processIndex = 0; //! we store this guy to tell the scheduler how many
//! things we have scheduled.
- for (; processIndex < this->m_Headers.Count(); ++processIndex) {
- auto process = this->m_Headers[processIndex];
+ for (; processIndex < mTeam.AsArray().Count(); ++processIndex) {
+ 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;
@@ -208,6 +208,7 @@ SizeT ProcessManager::Run() noexcept {
// set the current process.
m_CurrentProcess = unwrapped_process;
+ // tell helper to find a core to schedule on.
ProcessHelper::Switch(m_CurrentProcess.Leak().StackFrame,
m_CurrentProcess.Leak().ProcessId);
} else {
@@ -227,7 +228,7 @@ Ref<ProcessManager> ProcessManager::Shared() {
Ref<Process> &ProcessManager::GetCurrent() { return m_CurrentProcess; }
PID &ProcessHelper::GetCurrentPID() {
- kcout << "ProcessHelper::GetCurrentPID\r\n";
+ kcout << "ProcessHelper::GetCurrentPID: Leaking ProcessId...\r\n";
return ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId;
}
@@ -268,7 +269,7 @@ bool ProcessHelper::StartScheduling() {
SizeT ret = processRef.Run();
kcout << StringBuilder::FromInt(
- "ProcessHelper::StartScheduling() Iterated over: {%} processes.\r\n", ret);
+ "ProcessHelper::StartScheduling() Iterated over: % jobs.\r\n", ret);
return true;
}
@@ -288,7 +289,7 @@ bool ProcessHelper::Switch(HAL::StackFrame *the_stack, const PID &new_pid) {
if (SMPManager::Shared().Leak()[index].Leak().IsBusy()) continue;
if (SMPManager::Shared().Leak()[index].Leak().Kind() !=
- ThreadKind::kHartBoot ||
+ ThreadKind::kHartBoot &&
SMPManager::Shared().Leak()[index].Leak().Kind() !=
ThreadKind::kHartSystemReserved) {
SMPManager::Shared().Leak()[index].Leak().Busy(true);
diff --git a/Private/Source/ProcessTeam.cxx b/Private/Source/ProcessTeam.cxx
index 678f5fce..d7979cf3 100644
--- a/Private/Source/ProcessTeam.cxx
+++ b/Private/Source/ProcessTeam.cxx
@@ -11,5 +11,6 @@
#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/SMPManager.hpp>
+#include <KernelKit/ProcessTeam.hpp>
-// last rev 05-03-24 \ No newline at end of file
+// last rev 05-03-24
diff --git a/Public/Kits/HCoreKit/kernel.h b/Public/Kits/HCoreKit/kernel.h
deleted file mode 100644
index 15b3fad6..00000000
--- a/Public/Kits/HCoreKit/kernel.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
-* The HCore Kit
-* Copyright Mahrouss Logic
-* File: HKernel.h
-* Purpose: Base HCore header
-*/
-
-#pragma once
-
-/* process id */
-typedef long rt_kernel_port;
-
-/* @brief scheduling team */
-typedef long rt_kernel_team;
-
-/* virtual memory key */
-typedef long long int rt_virt_mem_t;
-
-/// override previous vm size if any.
-
-#ifdef kVirtualMemorySize
-// do not edit this! if you want to avoid your program crashing.
-#undef kVirtualMemorySize
-#endif /* ifdef kVirtualMemorySize */
-
-/// 4 megs of additional memory.
-#define kVirtualMemorySize 4096U
diff --git a/Public/Kits/ObjC/base_api.h b/Public/Kits/ObjC/base_api.h
deleted file mode 100644
index 861998d4..00000000
--- a/Public/Kits/ObjC/base_api.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/**
-* The HCore Kit
-* Copyright Mahrouss Logic
-* File: HBase.h
-* Purpose: Base HCore header
-*/
-
-#import <HCoreKit/kernel.h>
-
-typedef char8_t HCUtf8Raw;
-typedef HCUtf8Raw* HCUtf8RawPtr;
diff --git a/Public/Kits/ObjC/base_object.h b/Public/Kits/ObjC/base_object.h
deleted file mode 100644
index 783f5eb2..00000000
--- a/Public/Kits/ObjC/base_object.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
-* The HCore Kit
-* Copyright Mahrouss Logic
-* File: HCObject.h
-* Purpose: Base HCore object
-*/
-
-/// HCUtf8Raw, HCUtf8RawPtr, kVirtualMemorySize, rt_kernel_port, rt_kernel_team
-#import <HCoreKit/base_api.h>
-
-/// @brief Base HCore object
-/// @version 1.0
-
-@interface HCObject {
- HCUtf8RawPtr fClsName;
-}
-
--(id) init;
--(HCUtf8RawPtr) toString;
-@end // interface HCObject \ No newline at end of file