summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal <amlal@el-mahrouss-logic.com>2024-09-06 12:52:02 +0200
committerAmlal <amlal@el-mahrouss-logic.com>2024-09-06 12:52:02 +0200
commit39d95f7fb429c5c6b71cd7c1e985cadaf4ab7b83 (patch)
tree33e5832930b82adadfec61ad2e509e79995b7cf1 /dev
parent1404bdfdbf767a7c8e445766af4c27fe17f7c205 (diff)
[ IMP ] Fixed Scheduler and Team object, also fixed other things.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev')
-rw-r--r--dev/ZBA/BootKit/BootKit.hxx10
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootATA.cxx2
-rw-r--r--dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx10
-rw-r--r--dev/ZBA/Sources/Thread.cxx38
-rw-r--r--dev/ZKA/Docs/TODO-LIST.md2
-rw-r--r--dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx21
-rw-r--r--dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm5
-rw-r--r--dev/ZKA/NewKit/Array.hxx2
-rw-r--r--dev/ZKA/Sources/CodeMgr.cxx4
-rw-r--r--dev/ZKA/Sources/FS/NeFS.cxx2
-rw-r--r--dev/ZKA/Sources/PEFCodeMgr.cxx2
-rw-r--r--dev/ZKA/Sources/UserProcessScheduler.cxx22
12 files changed, 65 insertions, 55 deletions
diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx
index 3f7b0a96..ee2aea1f 100644
--- a/dev/ZBA/BootKit/BootKit.hxx
+++ b/dev/ZBA/BootKit/BootKit.hxx
@@ -236,7 +236,7 @@ public:
return false;
}
- writer.Write(L"newosldr: Disk is ").Write(GIB(this->fDiskDev.GetDiskSize())).Write(L" GB.\r");
+ writer.Write(L"NEWOSLDR: Disk is ").Write(GIB(this->fDiskDev.GetDiskSize())).Write(L" GB.\r");
if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() ||
blockPart->DiskSize < 1 ||
@@ -251,7 +251,7 @@ public:
return false;
}
- writer.Write(L"newosldr: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r");
+ writer.Write(L"NEWOSLDR: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r");
return true;
}
@@ -288,7 +288,7 @@ private:
fDiskDev.Write((Char*)&catalogKind, sizeof(NFS_CATALOG_STRUCT));
- writer.Write(L"newosldr: Wrote directory: ").Write(blob->fFileName).Write(L"\r");
+ writer.Write(L"NEWOSLDR: Wrote directory: ").Write(blob->fFileName).Write(L"\r");
return true;
}
@@ -325,7 +325,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* partName,
EFI::ThrowError(L"Disk-Too-Tiny", L"Can't format a New Filesystem partition here.");
return false;
}
-
+
NFS_ROOT_PARTITION_BLOCK partBlock{0};
CopyMem(partBlock.Ident, kNeFSIdent, kNeFSIdentLen - 1);
@@ -371,7 +371,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* partName,
if (this->WriteRootCatalog(fileBlobs, blobCount, partBlock))
{
BTextWriter writer;
- writer.Write(L"newosldr: Disk formatted.\r");
+ writer.Write(L"NEWOSLDR: Disk formatted.\r");
return true;
}
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx b/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx
index 6cc7f9b7..2f802cc0 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx
+++ b/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx
@@ -81,7 +81,7 @@ ATAInit_Retry:
if (statRdy & ATA_SR_ERR)
{
writer.Write(
- L"newosldr: ATA: Select error, not an IDE based hard-drive.\r");
+ L"NEWOSLDR: ATA: Select error, not an IDE based hard-drive.\r");
return false;
}
diff --git a/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx b/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx
index c2dff978..7c9fd042 100644
--- a/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx
+++ b/dev/ZBA/Sources/HEL/AMD64/BootFileReader.cxx
@@ -56,13 +56,13 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path,
if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk)
{
- mWriter.Write(L"newosldr: Handle-Protocol: No-Such-Protocol").Write(L"\r");
+ mWriter.Write(L"NEWOSLDR: Handle-Protocol: No-Such-Protocol").Write(L"\r");
this->mErrorCode = kNotSupported;
}
if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk)
{
- mWriter.Write(L"newosldr: Handle-Protocol: No-Such-Protocol").Write(L"\r");
+ mWriter.Write(L"NEWOSLDR: Handle-Protocol: No-Such-Protocol").Write(L"\r");
this->mErrorCode = kNotSupported;
return;
}
@@ -71,7 +71,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path,
if (efp->OpenVolume(efp, &mRootFs) != kEfiOk)
{
- mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Volume").Write(L"\r");
+ mWriter.Write(L"NEWOSLDR: Fetch-Protocol: No-Such-Volume").Write(L"\r");
this->mErrorCode = kNotSupported;
return;
}
@@ -81,7 +81,7 @@ BFileReader::BFileReader(const CharacterTypeUTF16* path,
if (mRootFs->Open(mRootFs, &KernelFile, mPath, kEFIFileRead, kEFIReadOnly) !=
kEfiOk)
{
- mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Path: ")
+ mWriter.Write(L"NEWOSLDR: Fetch-Protocol: No-Such-Path: ")
.Write(mPath)
.Write(L"\r");
this->mErrorCode = kNotSupported;
@@ -142,7 +142,7 @@ Void BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr outAddress
else if (readUntil < 1)
readUntil = newPtrInfo.FileSize;
- mWriter.Write(L"newosldr: Physical size: ").Write(readUntil).Write("\r");
+ mWriter.Write(L"NEWOSLDR: Physical size: ").Write(readUntil).Write("\r");
}
if (!outAddress)
diff --git a/dev/ZBA/Sources/Thread.cxx b/dev/ZBA/Sources/Thread.cxx
index 13b02b92..ee9b73c1 100644
--- a/dev/ZBA/Sources/Thread.cxx
+++ b/dev/ZBA/Sources/Thread.cxx
@@ -55,32 +55,32 @@ namespace Boot
if (hdrPtr->mMachine != kPeMachineAMD64 ||
hdrPtr->mSignature != kPeMagic)
{
- writer.Write("newosldr: Not a PE32+ executable.\r");
+ writer.Write("NEWOSLDR: Not a PE32+ executable.\r");
return;
}
if (optHdr->mSubsystem != kZKASubsystem)
{
- writer.Write("newosldr: Not a ZKA Subsystem executable.\r");
+ writer.Write("NEWOSLDR: Not a ZKA Subsystem executable.\r");
return;
}
- writer.Write("newosldr: PE32+ executable detected (ZKA Subsystem).\r");
+ writer.Write("NEWOSLDR: PE32+ executable detected (ZKA Subsystem).\r");
auto numSecs = hdrPtr->mNumberOfSections;
- writer.Write("newosldr: Major Linker Ver: ").Write(optHdr->mMajorLinkerVersion).Write("\r");
- writer.Write("newosldr: Minor Linker Ver: ").Write(optHdr->mMinorLinkerVersion).Write("\r");
- writer.Write("newosldr: Major Subsystem Ver: ").Write(optHdr->mMajorSubsystemVersion).Write("\r");
- writer.Write("newosldr: Minor Subsystem Ver: ").Write(optHdr->mMinorSubsystemVersion).Write("\r");
- writer.Write("newosldr: Magic: ").Write(hdrPtr->mSignature).Write("\r");
+ writer.Write("NEWOSLDR: Major Linker Ver: ").Write(optHdr->mMajorLinkerVersion).Write("\r");
+ writer.Write("NEWOSLDR: Minor Linker Ver: ").Write(optHdr->mMinorLinkerVersion).Write("\r");
+ writer.Write("NEWOSLDR: Major Subsystem Ver: ").Write(optHdr->mMajorSubsystemVersion).Write("\r");
+ writer.Write("NEWOSLDR: Minor Subsystem Ver: ").Write(optHdr->mMinorSubsystemVersion).Write("\r");
+ writer.Write("NEWOSLDR: Magic: ").Write(hdrPtr->mSignature).Write("\r");
constexpr auto cPageSize = 512;
EfiPhysicalAddress loadStartAddress = optHdr->mImageBase;
loadStartAddress += optHdr->mBaseOfData;
- writer.Write("newosldr: ImageBase: ").Write(loadStartAddress).Write("\r");
+ writer.Write("NEWOSLDR: ImageBase: ").Write(loadStartAddress).Write("\r");
auto numPages = optHdr->mSizeOfImage / cPageSize;
BS->AllocatePages(AllocateAddress, EfiLoaderData, numPages, &loadStartAddress);
@@ -95,14 +95,12 @@ namespace Boot
{
LDR_SECTION_HEADER_PTR sect = &sectPtr[sectIndex];
+ SetMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), 0, sect->mSizeOfRawData);
+
if (StrCmp(sectionForCode, sect->mName) == 0)
{
fStartAddress = (VoidPtr)((UIntPtr)loadStartAddress + optHdr->mAddressOfEntryPoint);
- writer.Write("newosldr: Entrypoint of DLL: ").Write((UIntPtr)fStartAddress).Write("\r");
- }
- else if (StrCmp(sectionForBSS, sect->mName) == 0)
- {
- SetMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), 0, sect->mSizeOfRawData);
+ writer.Write("NEWOSLDR: Entrypoint of DLL: ").Write((UIntPtr)fStartAddress).Write("\r");
}
else if (StrCmp(sectionForNewLdr, sect->mName) == 0)
{
@@ -115,12 +113,12 @@ namespace Boot
if (structHandover->HandoverMagic != kHandoverMagic &&
structHandover->HandoverType != HEL::kTypeKernel)
{
- writer.Write("newosldr: Entrypoint of EXE: ").Write((UIntPtr)fStartAddress).Write("\r");
+ writer.Write("NEWOSLDR: Entrypoint of EXE: ").Write((UIntPtr)fStartAddress).Write("\r");
CGDrawString("NEWOSLDR: NOT AN HANDOVER IMAGE...", 40, 10, RGB(0xFF, 0xFF, 0xFF));
}
}
- writer.Write("newosldr: offset ").Write(sect->mPointerToRawData).Write(" of ").Write(sect->mName).Write("\r");
+ writer.Write("NEWOSLDR: offset ").Write(sect->mPointerToRawData).Write(" of ").Write(sect->mName).Write("\r");
CopyMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), (VoidPtr)((UIntPtr)fBlob + sect->mPointerToRawData), sect->mSizeOfRawData);
}
@@ -135,12 +133,12 @@ namespace Boot
// ========================================= //
fStartAddress = nullptr;
- writer.Write("newosldr: PEF executable detected, won't load it.\r");
- writer.Write("newosldr: note: PEF executables aren't loadable by default.\r");
+ writer.Write("NEWOSLDR: PEF executable detected, won't load it.\r");
+ writer.Write("NEWOSLDR: note: PEF executables aren't loadable by default.\r");
}
else
{
- writer.Write("newosldr: Invalid executable. (note: SIGG executables aren't loadable by default).\r");
+ writer.Write("NEWOSLDR: Invalid executable. (note: SIGG executables aren't loadable by default).\r");
}
}
@@ -151,7 +149,7 @@ namespace Boot
if (!handover)
{
- writer.Write("newosldr: Exec format error.\r");
+ writer.Write("NEWOSLDR: Exec format error.\r");
return;
}
diff --git a/dev/ZKA/Docs/TODO-LIST.md b/dev/ZKA/Docs/TODO-LIST.md
index ec50c89d..2b4ea96c 100644
--- a/dev/ZKA/Docs/TODO-LIST.md
+++ b/dev/ZKA/Docs/TODO-LIST.md
@@ -18,7 +18,7 @@
Status:
-newosldr: Need to boot from EPM partition. [ X ]
+NEWOSLDR: Need to boot from EPM partition. [ X ]
<br>
newoskrnl: New Filesystem is done. [ X ]
diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
index 800d8b3d..7a6e726a 100644
--- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
@@ -46,15 +46,12 @@ namespace Kernel
kcout << "BMPMgr: Allocated pointer!\r";
kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl;
- kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl;
+ kcout << "Size of pointer (KIB): " << number(KIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (MIB): " << number(MIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (GIB): " << number(GIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl;
kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl;
- if (rw)
- mm_update_pte(base_ptr, eFlagsRw);
-
- if (user)
- mm_update_pte(base_ptr, eFlagsUser);
-
return (VoidPtr)ptr_bit_set;
}
}
@@ -68,7 +65,10 @@ namespace Kernel
kcout << "BMPMgr: Allocated pointer!\r";
kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl;
- kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl;
+ kcout << "Size of pointer (KIB): " << number(KIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (MIB): " << number(MIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (GIB): " << number(GIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl;
kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl;
if (rw)
@@ -123,7 +123,10 @@ namespace Kernel
kcout << "BMPMgr: Freed pointer!\r";
kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl;
- kcout << "Size of pointer: " << hex_number(ptr_bit_set[1]) << endl;
+ kcout << "Size of pointer (KIB): " << number(KIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (MIB): " << number(MIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (GIB): " << number(GIB(ptr_bit_set[1])) << endl;
+ kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl;
kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl;
ptr_bit_set[0] = cBitMpMagic;
diff --git a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
index c26a346f..6b00715d 100644
--- a/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
+++ b/dev/ZKA/HALKit/AMD64/HalMPContextSwitch.asm
@@ -34,12 +34,13 @@ mp_do_context_switch:
mov r11, gs
mov r12, fs
- mov r11, 0x202
-
mov fs, [r8 + (8 * 4)]
mov gs, [r8 + (8 * 9)]
mov r8, [r8]
+ mov r11, 0x202
+ mov rsp, rdx
+
o64 sysret
;; @brief Gets the current stack frame.
diff --git a/dev/ZKA/NewKit/Array.hxx b/dev/ZKA/NewKit/Array.hxx
index 9fa545ef..9d1dc74a 100644
--- a/dev/ZKA/NewKit/Array.hxx
+++ b/dev/ZKA/NewKit/Array.hxx
@@ -23,7 +23,7 @@ namespace Kernel
T& operator[](const SizeT& At)
{
- return (fArray[At]);
+ return fArray[At];
}
Boolean Empty() const
diff --git a/dev/ZKA/Sources/CodeMgr.cxx b/dev/ZKA/Sources/CodeMgr.cxx
index 49968e73..ae4cb00b 100644
--- a/dev/ZKA/Sources/CodeMgr.cxx
+++ b/dev/ZKA/Sources/CodeMgr.cxx
@@ -14,7 +14,7 @@ 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* process_name) noexcept
+ Bool sched_execute_thread(MainKind main, const Char* process_name) noexcept
{
if (!main)
return No;
@@ -27,6 +27,6 @@ namespace Kernel
rt_copy_memory((VoidPtr)process_name, proc.Name, rt_string_len(process_name));
- return UserProcessScheduler::The().Add(proc) != 0;
+ return UserProcessScheduler::The().Add(proc) > 0;
}
} // namespace Kernel
diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx
index 549a0217..1a9b89f7 100644
--- a/dev/ZKA/Sources/FS/NeFS.cxx
+++ b/dev/ZKA/Sources/FS/NeFS.cxx
@@ -724,7 +724,7 @@ bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool i
_Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogName,
Lba& out_lba)
{
- kcout << "start finding catalog...\r";
+ kcout << "Start finding catalog...\r";
NFS_ROOT_PARTITION_BLOCK fs_buf{0};
auto drive = sMountpointInterface.A();
diff --git a/dev/ZKA/Sources/PEFCodeMgr.cxx b/dev/ZKA/Sources/PEFCodeMgr.cxx
index feafc35c..23dfae31 100644
--- a/dev/ZKA/Sources/PEFCodeMgr.cxx
+++ b/dev/ZKA/Sources/PEFCodeMgr.cxx
@@ -221,7 +221,7 @@ namespace Kernel
proc.StackSize = mib_cast(cDefaultStackSizeMib);
}
- return UserProcessScheduler::The().Add(proc);
+ return UserProcessScheduler::The().Add(proc) > 0;
}
} // namespace Utils
diff --git a/dev/ZKA/Sources/UserProcessScheduler.cxx b/dev/ZKA/Sources/UserProcessScheduler.cxx
index f480bccc..c68104b9 100644
--- a/dev/ZKA/Sources/UserProcessScheduler.cxx
+++ b/dev/ZKA/Sources/UserProcessScheduler.cxx
@@ -54,7 +54,7 @@ namespace Kernel
Void UserProcess::Crash()
{
- if (this->Name == 0)
+ if (*this->Name == 0)
return;
kcout << this->Name << ": crashed, ID = " << number(kErrorProcessFault) << endl;
@@ -202,10 +202,10 @@ namespace Kernel
cLastExitCode = exit_code;
//! Delete image if not done already.
- if (this->Image)
+ if (this->Image && mm_is_valid_heap(this->Image))
mm_delete_ke_heap(this->Image);
- if (this->StackFrame)
+ if (this->StackFrame && mm_is_valid_heap(this->StackFrame))
mm_delete_ke_heap((VoidPtr)this->StackFrame);
this->Image = nullptr;
@@ -225,6 +225,8 @@ namespace Kernel
if (this->StackReserve)
delete[] this->StackReserve;
+ this->ProcessId = 0;
+
if (this->ProcessId > 0)
UserProcessScheduler::The().Remove(this->ProcessId);
}
@@ -271,11 +273,14 @@ namespace Kernel
return -kErrorProcessFault;
}
- process.Status = ProcessStatusKind::kStarting;
- process.ProcessId = mTeam.mProcessAmount;
+ if (mTeam.mProcessAmount > kSchedProcessLimitPerTeam)
+ mTeam.mProcessAmount = 0UL;
++mTeam.mProcessAmount;
+ process.ProcessId = mTeam.mProcessAmount;
+ process.Status = ProcessStatusKind::kStarting;
+
mTeam.AsArray()[process.ProcessId] = process;
return process.ProcessId;
@@ -414,10 +419,13 @@ namespace Kernel
* \param new_pid the process's PID.
*/
- bool UserProcessHelper::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;
+ return No;
+
+ while (Yes)
+ ;
for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Count(); ++index)
{