summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/Sources
diff options
context:
space:
mode:
Diffstat (limited to 'dev/ZKA/Sources')
-rw-r--r--dev/ZKA/Sources/CodeMgr.cxx8
-rw-r--r--dev/ZKA/Sources/ExeMain.cxx14
-rw-r--r--dev/ZKA/Sources/FS/NeFS.cxx4
-rw-r--r--dev/ZKA/Sources/HardwareThreadScheduler.cxx13
-rw-r--r--dev/ZKA/Sources/IPEFDLLObject.cxx10
-rw-r--r--dev/ZKA/Sources/ThreadLocalStorage.cxx36
-rw-r--r--dev/ZKA/Sources/UserProcessScheduler.cxx74
-rw-r--r--dev/ZKA/Sources/UserThreadScheduler.cxx49
8 files changed, 110 insertions, 98 deletions
diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx
index 1d4f4a6e..49968e73 100644
--- a/dev/ZKA/Sources/CodeMgr.cxx
+++ b/dev/ZKA/Sources/CodeMgr.cxx
@@ -14,10 +14,10 @@ namespace Kernel
/// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible.
/// @param main the start of the process.
/// @return if the process was started or not.
- bool sched_execute_thread(MainKind main, const Char* processName) noexcept
+ bool sched_execute_thread(MainKind main, const Char* process_name) noexcept
{
if (!main)
- return false;
+ return No;
UserProcess proc;
proc.SetImageStart(reinterpret_cast<VoidPtr>(main));
@@ -25,8 +25,8 @@ namespace Kernel
proc.Kind = UserProcess::kExeKind;
proc.StackSize = mib_cast(4);
- rt_copy_memory((VoidPtr)processName, proc.Name, rt_string_len(processName));
+ rt_copy_memory((VoidPtr)process_name, proc.Name, rt_string_len(process_name));
- return UserProcessScheduler::The().Add(proc) == kErrorSuccess;
+ return UserProcessScheduler::The().Add(proc) != 0;
}
} // namespace Kernel
diff --git a/dev/ZKA/Sources/ExeMain.cxx b/dev/ZKA/Sources/ExeMain.cxx
index 2aed9bf7..d8d1ea6e 100644
--- a/dev/ZKA/Sources/ExeMain.cxx
+++ b/dev/ZKA/Sources/ExeMain.cxx
@@ -65,11 +65,11 @@ namespace Kernel::Detail
CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0));
}
- const Kernel::SizeT cDirCount = 7UL;
+ const Kernel::SizeT cDirCount = 9UL;
const Kernel::Char* cDirStr[cDirCount] = {
"\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\",
- "\\Users\\", "\\Library\\", "\\Mount\\"};
+ "\\Users\\", "\\Library\\", "\\Mount\\", "\\Games\\", "\\Applications\\Java\\"};
if (fNeFS->GetParser())
{
@@ -117,11 +117,18 @@ EXTERN_C ATTRIBUTE(naked) Kernel::Void HangCPU(Kernel::Void)
}
}
+namespace Kernel
+{
+ EXTERN UserProcessScheduler* cProcessScheduler;
+}
+
/// @brief Application entrypoint.
/// @param Void
/// @return Void
EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void)
{
+ Kernel::cProcessScheduler = nullptr;
+
CG::CGDrawBackground();
cKernelWnd = nullptr;
@@ -148,8 +155,7 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void)
CG::CGDrawStringToWnd(cKernelWnd, "Starting ZKA System...", 20, 10, RGB(0, 0, 0));
- Kernel::UserProcessHelper::Init();
-
+ Kernel::UserProcessHelper::StartScheduling();
Kernel::sched_execute_thread(HangCPU, "HANG TEST");
while (Yes)
diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx
index 68078ec3..409ca663 100644
--- a/dev/ZKA/Sources/FS/NeFS.cxx
+++ b/dev/ZKA/Sources/FS/NeFS.cxx
@@ -814,8 +814,8 @@ NeFSSearchThroughCatalogList:
NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT();
rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT));
- kcout << "found catalog at: " << hex_number(startCatalogList) << endl;
- kcout << "found catalog at: " << catalog->Name << endl;
+ kcout << "Found catalog at: " << hex_number(startCatalogList) << endl;
+ kcout << "Found catalog at: " << catalog->Name << endl;
out_lba = startCatalogList;
return catalogPtr;
diff --git a/dev/ZKA/Sources/HardwareThreadScheduler.cxx b/dev/ZKA/Sources/HardwareThreadScheduler.cxx
index b130ef63..c5d04bbc 100644
--- a/dev/ZKA/Sources/HardwareThreadScheduler.cxx
+++ b/dev/ZKA/Sources/HardwareThreadScheduler.cxx
@@ -17,6 +17,8 @@
namespace Kernel
{
+ HardwareThreadScheduler* cHardwareThreadScheduler = nullptr;
+
///! A HardwareThread class takes care of it's owned hardware thread.
///! It has a stack for it's core.
@@ -107,7 +109,7 @@ namespace Kernel
{
mp_do_context_switch_pre();
mp_do_context_switch(image, stack_ptr, fStack);
-
+
return true;
}
}
@@ -124,7 +126,10 @@ namespace Kernel
///! @brief Constructor and destructors.
///! @brief Default constructor.
- HardwareThreadScheduler::HardwareThreadScheduler() = default;
+ HardwareThreadScheduler::HardwareThreadScheduler()
+ {
+ kcout << "Initializing class done!" << endl;
+ }
///! @brief Default destructor.
HardwareThreadScheduler::~HardwareThreadScheduler() = default;
@@ -132,8 +137,8 @@ namespace Kernel
/// @brief Shared singleton function
HardwareThreadScheduler& HardwareThreadScheduler::The()
{
- STATIC HardwareThreadScheduler sched;
- return sched;
+ MUST_PASS(cHardwareThreadScheduler);
+ return *cHardwareThreadScheduler;
}
/// @brief Get Stack Frame of Core
diff --git a/dev/ZKA/Sources/IPEFDLLObject.cxx b/dev/ZKA/Sources/IPEFDLLObject.cxx
index 913912a4..a8505eb3 100644
--- a/dev/ZKA/Sources/IPEFDLLObject.cxx
+++ b/dev/ZKA/Sources/IPEFDLLObject.cxx
@@ -18,11 +18,11 @@
Revision History:
- 01/02/24: Rework shared sharedObj ABI, except a rtl_init_shared_object and
- rtl_fini_shared_object (amlel) 15/02/24: Breaking changes, changed the name of the
+ 01/02/24: Rework shared sharedObj ABI, except a rtl_init_dll and
+ rtl_fini_dll (amlel) 15/02/24: Breaking changes, changed the name of the
routines. (amlel)
- 07/28/24: Replace rt_library_free with rtl_fini_shared_object
+ 07/28/24: Replace rt_library_free with rtl_fini_dll
------------------------------------------- */
@@ -37,7 +37,7 @@ using namespace Kernel;
/** @brief Library initializer. */
/***********************************************************************************/
-EXTERN_C IDLL rtl_init_shared_object(UserProcess* header)
+EXTERN_C IDLL rtl_init_dll(UserProcess* header)
{
IDLL sharedObj = tls_new_class<IPEFDLLObject>();
@@ -80,7 +80,7 @@ EXTERN_C IDLL rtl_init_shared_object(UserProcess* header)
/** @param successful Reports if successful or not. */
/***********************************************************************************/
-EXTERN_C Void rtl_fini_shared_object(UserProcess* header, IDLL lib, Bool* successful)
+EXTERN_C Void rtl_fini_dll(UserProcess* header, IDLL lib, Bool* successful)
{
MUST_PASS(successful);
diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx
index 35f2dbcd..825761de 100644
--- a/dev/ZKA/Sources/ThreadLocalStorage.cxx
+++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx
@@ -21,42 +21,6 @@
using namespace Kernel;
-namespace Kernel::Detail
-{
- /// \brief UserProcess thread information header.
- struct THREAD_HEADER_BLOCK final
- {
- STATIC constexpr SizeT cMaxLen = 256;
-
- Char fName[cMaxLen] = {"THREAD #0 (PROCESS 0)"};
- ProcessStatusKind fThreadStatus;
- Int64 fThreadID;
- UIntPtr fCode{0};
- UIntPtr fStack{0};
- UIntPtr fData{0};
-
- Void Exit() noexcept
- {
- this->fThreadStatus = ProcessStatusKind::kKilled;
- }
-
- UIntPtr GetStack() noexcept
- {
- return fStack;
- }
-
- UIntPtr GetData() noexcept
- {
- return fData;
- }
-
- UIntPtr GetPC() noexcept
- {
- return fCode;
- }
- };
-} // namespace Detail
-
/**
* @brief Checks for cookie inside the TIB.
* @param tib the TIB to check.
diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx
index 8c46b1cf..f480bccc 100644
--- a/dev/ZKA/Sources/UserProcessScheduler.cxx
+++ b/dev/ZKA/Sources/UserProcessScheduler.cxx
@@ -12,6 +12,7 @@
/// @brief User Process scheduler.
/***********************************************************************************/
+#include "HALKit/AMD64/Processor.hxx"
#include <KernelKit/UserProcessScheduler.hxx>
#include <KernelKit/IPEFDLLObject.hxx>
#include <KernelKit/HardwareThreadScheduler.hxx>
@@ -213,7 +214,7 @@ namespace Kernel
if (this->Kind == kDLLKind)
{
Bool success = false;
- rtl_fini_shared_object(this, this->DLLPtr, &success);
+ rtl_fini_dll(this, this->DLLPtr, &success);
if (success)
{
@@ -237,7 +238,7 @@ namespace Kernel
process.MemoryPD = reinterpret_cast<UIntPtr>(hal_read_cr3());
#endif // __ZKA_AMD64__
- process.StackFrame = (HAL::StackFrame*)process.New(sizeof(HAL::StackFrame));
+ process.StackFrame = new HAL::StackFrame(0);
if (!process.StackFrame)
{
@@ -248,28 +249,26 @@ namespace Kernel
// Create heap according to type of process.
if (process.Kind == UserProcess::kDLLKind)
{
- process.DLLPtr = rtl_init_shared_object(&process);
+ process.DLLPtr = rtl_init_dll(&process);
}
- if (process.Image)
+ if (!process.Image)
{
- // get preferred stack size by app.
- const auto cMaxStackSize = process.StackSize;
- process.StackReserve = (UInt8*)process.New(sizeof(UInt8) * cMaxStackSize);
-
- if (process.StackReserve)
+ if (process.Kind != UserProcess::kDLLKind)
{
process.Crash();
return -kErrorProcessFault;
}
}
- else
+
+ // get preferred stack size by app.
+ const auto cMaxStackSize = process.StackSize;
+ process.StackReserve = new UInt8[cMaxStackSize];
+
+ if (!process.StackReserve)
{
- if (process.Kind != UserProcess::kDLLKind)
- {
- process.Crash();
- return -kErrorProcessFault;
- }
+ process.Crash();
+ return -kErrorProcessFault;
}
process.Status = ProcessStatusKind::kStarting;
@@ -277,9 +276,6 @@ namespace Kernel
++mTeam.mProcessAmount;
- while (1)
- ;
-
mTeam.AsArray()[process.ProcessId] = process;
return process.ProcessId;
@@ -318,6 +314,8 @@ namespace Kernel
SizeT process_index = 0; //! we store this guy to tell the scheduler how many
//! things we have scheduled.
+ kcout << "Finding available process...\r";
+
for (; process_index < mTeam.AsArray().Capacity(); ++process_index)
{
auto& process = mTeam.AsArray()[process_index];
@@ -326,7 +324,7 @@ namespace Kernel
if (UserProcessHelper::CanBeScheduled(process))
{
// set the current process.
- mTeam.AsRef() = mTeam.AsArray()[process.ProcessId];
+ mTeam.AsRef() = process;
process.PTime = static_cast<Int32>(process.Affinity);
@@ -339,10 +337,6 @@ namespace Kernel
process.Crash();
continue;
}
-
- process.Exit();
-
- continue;
}
else
{
@@ -378,35 +372,16 @@ namespace Kernel
return cProcessScheduler->CurrentProcess().Leak().ProcessId;
}
- Void UserProcessHelper::Init()
- {
- if (mm_is_valid_heap(cProcessScheduler))
- delete cProcessScheduler;
-
- cProcessScheduler = nullptr;
- cProcessScheduler = new UserProcessScheduler();
- MUST_PASS(cProcessScheduler);
- }
-
/// @brief Check if process can be schedulded.
/// @param process the process reference.
/// @retval true can be schedulded.
/// @retval false cannot be schedulded.
- bool UserProcessHelper::CanBeScheduled(UserProcess& process)
+ bool UserProcessHelper::CanBeScheduled(const UserProcess process)
{
if (process.Status == ProcessStatusKind::kFrozen ||
process.Status == ProcessStatusKind::kDead)
return false;
- if (process.Kind == UserProcess::kDLLKind)
- {
- if (auto start = process.DLLPtr->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart), kPefCode);
- start)
- {
- process.Image = start;
- }
- }
-
return process.PTime < 1;
}
@@ -414,8 +389,21 @@ namespace Kernel
* @brief Scheduler helper class.
*/
+ EXTERN
+ HardwareThreadScheduler* cHardwareThreadScheduler;
+
SizeT UserProcessHelper::StartScheduling()
{
+ if (!cHardwareThreadScheduler)
+ {
+ cHardwareThreadScheduler = new HardwareThreadScheduler();
+ }
+
+ if (!cProcessScheduler)
+ {
+ cProcessScheduler = new UserProcessScheduler();
+ }
+
SizeT ret = cProcessScheduler->Run();
return ret;
}
diff --git a/dev/ZKA/Sources/UserThreadScheduler.cxx b/dev/ZKA/Sources/UserThreadScheduler.cxx
new file mode 100644
index 00000000..739f00ad
--- /dev/null
+++ b/dev/ZKA/Sources/UserThreadScheduler.cxx
@@ -0,0 +1,49 @@
+/*
+ * ========================================================
+ *
+ * newoskrnl
+ * Copyright ZKA Technologies., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <NewKit/String.hxx>
+#include <CFKit/Property.hxx>
+#include <KernelKit/UserProcessScheduler.hxx>
+
+namespace Kernel
+{
+ /// \brief UserProcess thread information header.
+ struct USER_THREAD_BLOCK final
+ {
+ STATIC constexpr SizeT cMaxLen = 256;
+
+ Char fName[cMaxLen] = {"THREAD #0 (PROCESS 0)"};
+ ProcessStatusKind fThreadStatus;
+ Int64 fThreadID;
+ Int64* fProcessID{nullptr};
+ VoidPtr fCode{nullptr};
+ VoidPtr fStack{nullptr};
+ VoidPtr fData{nullptr};
+
+ Void Exit() noexcept
+ {
+ this->fThreadStatus = ProcessStatusKind::kKilled;
+ }
+
+ VoidPtr GetStack() noexcept
+ {
+ return fStack;
+ }
+
+ VoidPtr GetData() noexcept
+ {
+ return fData;
+ }
+
+ VoidPtr GetPC() noexcept
+ {
+ return fCode;
+ }
+ };
+} // namespace Detail