summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/Sources
diff options
context:
space:
mode:
authorAmlal <amlal@el-mahrouss-logic.com>2024-09-14 20:11:35 +0200
committerAmlal <amlal@el-mahrouss-logic.com>2024-09-14 20:11:35 +0200
commite05aa2145b8d0000110b93fb371ba858cb2a02bc (patch)
tree39d68355c6afe6f1e21f87d214a5b546b4a814d9 /dev/ZKA/Sources
parent6c51d0d2fde9b9a0201721cc625e73b585fdc479 (diff)
IMP: Fixes and improvements on PEF Loader, User scheduler and BMP manager.
- This covers the Memory Manager, User Scheduler Manager and Loader Manager. - These are mostly fixes and added features. - Such as a new symbol to get heap reserve. META: Run format command. Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/ZKA/Sources')
-rw-r--r--dev/ZKA/Sources/DriveMgr.cxx5
-rw-r--r--dev/ZKA/Sources/FS/NeFS.cxx34
-rw-r--r--dev/ZKA/Sources/FileMgr.cxx14
-rw-r--r--dev/ZKA/Sources/NeFS+IO.cxx2
-rw-r--r--dev/ZKA/Sources/PEFCodeMgr.cxx18
-rw-r--r--dev/ZKA/Sources/ThreadLocalStorage.cxx4
-rw-r--r--dev/ZKA/Sources/UserProcessScheduler.cxx36
-rw-r--r--dev/ZKA/Sources/UserThreadScheduler.cxx14
8 files changed, 68 insertions, 59 deletions
diff --git a/dev/ZKA/Sources/DriveMgr.cxx b/dev/ZKA/Sources/DriveMgr.cxx
index 82291ada..f6436f75 100644
--- a/dev/ZKA/Sources/DriveMgr.cxx
+++ b/dev/ZKA/Sources/DriveMgr.cxx
@@ -8,7 +8,6 @@
#include <KernelKit/DriveMgr.hxx>
#include <NewKit/Utils.hxx>
-
#include <Modules/ATA/ATA.hxx>
#include <Modules/AHCI/AHCI.hxx>
#include <Modules/NVME/Defines.hxx>
@@ -124,7 +123,7 @@ namespace Kernel
trait.fInput = io_drv_unimplemented;
trait.fOutput = io_drv_unimplemented;
trait.fVerify = io_drv_unimplemented;
- trait.fInit = io_drv_unimplemented;
+ trait.fInit = io_drv_unimplemented;
trait.fDriveKind = ke_drv_kind;
return trait;
@@ -142,7 +141,7 @@ namespace Kernel
trait.fInput = ke_drv_input;
trait.fOutput = ke_drv_output;
trait.fVerify = io_drv_unimplemented;
- trait.fInit = ke_drv_init;
+ trait.fInit = ke_drv_init;
trait.fDriveKind = ke_drv_kind;
kcout << "Construct drive with success.\r";
diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx
index 8bd467c6..69b0c401 100644
--- a/dev/ZKA/Sources/FS/NeFS.cxx
+++ b/dev/ZKA/Sources/FS/NeFS.cxx
@@ -60,7 +60,7 @@ STATIC MountpointInterface sMountpointInterface;
/// @return the fork
/***********************************************************************************/
_Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input NFS_FORK_STRUCT& the_fork)
+ _Input NFS_FORK_STRUCT& the_fork)
{
if (catalog && the_fork.ForkName[0] != 0 &&
the_fork.DataSize <= kNeFSForkDataSz)
@@ -142,10 +142,10 @@ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catal
constexpr auto cForkPadding =
4; /// this value gives us space for the data offset.
- the_fork.Flags |= kNeFSFlagCreated;
- the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT);
+ the_fork.Flags |= kNeFSFlagCreated;
+ the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT);
the_fork.PreviousSibling = lbaOfPreviousFork;
- the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize - sizeof(NFS_FORK_STRUCT);
+ the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize - sizeof(NFS_FORK_STRUCT);
drv.fPacket.fLba = lba;
drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT);
@@ -172,10 +172,10 @@ _Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catal
/// @return the fork.
/***********************************************************************************/
_Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog,
- _Input const Char* name,
- Boolean isDataFork)
+ _Input const Char* name,
+ Boolean isDataFork)
{
- auto drv = sMountpointInterface.A();
+ auto drv = sMountpointInterface.A();
NFS_FORK_STRUCT* the_fork = nullptr;
Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork;
@@ -238,9 +238,9 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name)
/// @param kind the catalog kind.
/// @return catalog pointer.
/***********************************************************************************/
-_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name,
- _Input const Int32& flags,
- _Input const Int32& kind)
+_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name,
+ _Input const Int32& flags,
+ _Input const Int32& kind)
{
kcout << "CreateCatalog(...)\r";
@@ -650,7 +650,7 @@ bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool i
rt_string_len("fs/newfs-packet"));
auto startFork = (!is_rsrc_fork) ? catalog->DataFork
- : catalog->ResourceFork;
+ : catalog->ResourceFork;
NFS_FORK_STRUCT* fork_data_input = new NFS_FORK_STRUCT();
NFS_FORK_STRUCT prevFork{};
@@ -684,7 +684,7 @@ bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool i
// Store the blob now.
// ===================================================== //
- fork_data_input->Flags |= kNeFSFlagCreated;
+ fork_data_input->Flags |= kNeFSFlagCreated;
drive.fPacket.fPacketContent = buf;
drive.fPacket.fPacketSize = kNeFSForkDataSz;
@@ -722,7 +722,7 @@ bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool i
/// @param catalogName the catalog name.
/// @return the newly found catalog.
_Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogName,
- Lba& out_lba)
+ Lba& out_lba)
{
kcout << "Start finding catalog...\r";
@@ -792,7 +792,7 @@ _Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogNa
}
else
{
- return nullptr;
+ return nullptr;
}
}
@@ -936,9 +936,9 @@ Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName)
/***********************************************************************************/
VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog,
- _Input Bool is_rsrc_fork,
- _Input SizeT dataSz,
- _Input const Char* forkName)
+ _Input Bool is_rsrc_fork,
+ _Input SizeT dataSz,
+ _Input const Char* forkName)
{
if (!catalog)
{
diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx
index 88e8c433..a7be26b8 100644
--- a/dev/ZKA/Sources/FileMgr.cxx
+++ b/dev/ZKA/Sources/FileMgr.cxx
@@ -101,10 +101,10 @@ namespace Kernel
}
Void NeFileSystemMgr::Write(_Input const Char* name,
- _Input NodePtr node,
- _Input VoidPtr data,
- _Input Int32 flags,
- _Input SizeT size)
+ _Input NodePtr node,
+ _Input VoidPtr data,
+ _Input Int32 flags,
+ _Input SizeT size)
{
if (!size ||
size > kNeFSForkSize)
@@ -121,9 +121,9 @@ namespace Kernel
}
_Output VoidPtr NeFileSystemMgr::Read(_Input const Char* name,
- _Input NodePtr node,
- _Input Int32 flags,
- _Input SizeT sz)
+ _Input NodePtr node,
+ _Input Int32 flags,
+ _Input SizeT sz)
{
if (sz > kNeFSForkSize)
return nullptr;
diff --git a/dev/ZKA/Sources/NeFS+IO.cxx b/dev/ZKA/Sources/NeFS+IO.cxx
index a86e9c29..6c3aa6e1 100644
--- a/dev/ZKA/Sources/NeFS+IO.cxx
+++ b/dev/ZKA/Sources/NeFS+IO.cxx
@@ -24,7 +24,7 @@
/// Useful macros.
#define NEFS_WRITE(DRV, TRAITS, MP) (MP->DRV()).fOutput(&TRAITS)
-#define NEFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS)
+#define NEFS_READ(DRV, TRAITS, MP) (MP->DRV()).fInput(&TRAITS)
using namespace Kernel;
diff --git a/dev/ZKA/Sources/PEFCodeMgr.cxx b/dev/ZKA/Sources/PEFCodeMgr.cxx
index c635dd69..fa9b0d93 100644
--- a/dev/ZKA/Sources/PEFCodeMgr.cxx
+++ b/dev/ZKA/Sources/PEFCodeMgr.cxx
@@ -15,6 +15,7 @@
/// @brief PEF stack size symbol.
#define cPefStackSizeSymbol "SizeOfReserveStack"
+#define cPefHeapSizeSymbol "SizeOfReserveHeap"
#define cPefNameSymbol "ProgramName"
namespace Kernel
@@ -206,8 +207,9 @@ namespace Kernel
UserProcess proc;
proc.SetImageStart(errOrStart.Leak().Leak());
- proc.Kind = procKind;
- proc.StackSize = *(UIntPtr*)exec.FindSymbol(cPefStackSizeSymbol, kPefData);
+ proc.Kind = procKind;
+ proc.StackSize = *(UIntPtr*)exec.FindSymbol(cPefStackSizeSymbol, kPefData);
+ proc.MemoryLimit = *(UIntPtr*)exec.FindSymbol(cPefHeapSizeSymbol, kPefData);
rt_set_memory(proc.Name, 0, kProcessLen);
@@ -235,15 +237,17 @@ namespace Kernel
const Char* PEFLoader::AsString()
{
#ifdef __32x0__
- return "32x0 PEF format.";
+ return "32x0 PEF executable.";
#elif defined(__64x0__)
- return "64x0 PEF format.";
+ return "64x0 PEF executable.";
#elif defined(__x86_64__)
- return "x86_64 PEF format.";
+ return "x86_64 PEF executable.";
+#elif defined(__aarch64__)
+ return "aarch64 PEF executable.";
#elif defined(__powerpc64__)
- return "POWER PEF format.";
+ return "POWER64 PEF executable.";
#else
- return "Unknown PEF format.";
+ return "???? PEF executable.";
#endif // __32x0__ || __64x0__ || __x86_64__ || __powerpc64__
}
diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx
index ed723c06..587edafd 100644
--- a/dev/ZKA/Sources/ThreadLocalStorage.cxx
+++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx
@@ -33,8 +33,8 @@ Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib)
!the_tib->f_ThreadRecord)
return false;
- IEncoderObject encoder;
- const char* tibAsBytes = encoder.AsBytes(the_tib);
+ IEncoderObject encoder;
+ const char* tibAsBytes = encoder.AsBytes(the_tib);
kcout << "checking for a valid cookie inside the TIB...\r";
diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx
index 2d4c3836..487a2f38 100644
--- a/dev/ZKA/Sources/UserProcessScheduler.cxx
+++ b/dev/ZKA/Sources/UserProcessScheduler.cxx
@@ -53,10 +53,8 @@ namespace Kernel
Void UserProcess::Crash()
{
- if (*this->Name == 0)
- return;
-
- kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl;
+ if (*this->Name != 0)
+ kcout << this->Name << ": crashed, error id: " << number(kErrorProcessFault) << endl;
this->Exit(kErrorProcessFault);
}
@@ -112,12 +110,13 @@ namespace Kernel
}
else
{
- auto entry = this->MemoryEntryList;
+ auto entry = this->MemoryEntryList;
+ PROCESS_MEMORY_ENTRY* prev_entry = nullptr;
- while (entry->MemoryNext)
+ while (!entry)
{
- if (entry->MemoryNext)
- entry = entry->MemoryNext;
+ prev_entry = entry;
+ entry = entry->MemoryNext;
}
entry->MemoryNext = new UserProcess::PROCESS_MEMORY_ENTRY();
@@ -137,7 +136,7 @@ namespace Kernel
{
auto entry = this->MemoryEntryList;
- while (entry->MemoryNext)
+ while (entry)
{
if (entry->MemoryEntry == ptr)
{
@@ -145,7 +144,7 @@ namespace Kernel
auto pd = hal_read_cr3();
hal_write_cr3(reinterpret_cast<VoidPtr>(this->MemoryPD));
- bool ret = mm_delete_ke_heap(ptr);
+ Bool ret = mm_delete_ke_heap(ptr);
hal_write_cr3(reinterpret_cast<VoidPtr>(pd));
return ret;
@@ -155,8 +154,7 @@ namespace Kernel
#endif
}
- if (entry->MemoryNext)
- entry = entry->MemoryNext;
+ entry = entry->MemoryNext;
}
return false;
@@ -305,6 +303,9 @@ namespace Kernel
/// @param process_id process slot inside team.
/// @retval true process was removed.
/// @retval false process doesn't exist in team.
+
+ /***********************************************************************************/
+
Bool UserProcessScheduler::Remove(ProcessID process_id)
{
// check if process is within range.
@@ -317,8 +318,13 @@ namespace Kernel
return true;
}
- /// @brief Run scheduler.
- /// @return
+ /***********************************************************************************/
+
+ /// @brief Run User scheduler object.
+ /// @return Process executed within team.
+
+ /***********************************************************************************/
+
SizeT UserProcessScheduler::Run() noexcept
{
SizeT process_index = 0; //! we store this guy to tell the scheduler how many
@@ -326,7 +332,7 @@ namespace Kernel
for (; process_index < mTeam.AsArray().Capacity(); ++process_index)
{
- kcout << "Grabbing available process...\r";
+ kcout << "Grabbing available process in team...\r";
auto& process = mTeam.AsArray()[process_index];
diff --git a/dev/ZKA/Sources/UserThreadScheduler.cxx b/dev/ZKA/Sources/UserThreadScheduler.cxx
index 739f00ad..21514972 100644
--- a/dev/ZKA/Sources/UserThreadScheduler.cxx
+++ b/dev/ZKA/Sources/UserThreadScheduler.cxx
@@ -18,13 +18,13 @@ namespace Kernel
{
STATIC constexpr SizeT cMaxLen = 256;
- Char fName[cMaxLen] = {"THREAD #0 (PROCESS 0)"};
+ Char fName[cMaxLen] = {"THREAD #0 (PROCESS 0)"};
ProcessStatusKind fThreadStatus;
- Int64 fThreadID;
- Int64* fProcessID{nullptr};
- VoidPtr fCode{nullptr};
- VoidPtr fStack{nullptr};
- VoidPtr fData{nullptr};
+ Int64 fThreadID;
+ Int64* fProcessID{nullptr};
+ VoidPtr fCode{nullptr};
+ VoidPtr fStack{nullptr};
+ VoidPtr fData{nullptr};
Void Exit() noexcept
{
@@ -46,4 +46,4 @@ namespace Kernel
return fCode;
}
};
-} // namespace Detail
+} // namespace Kernel