summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKAKit/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-11-07 08:44:53 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-11-07 08:44:53 +0100
commit696d6ffdd2404f2aca526075a0df9022e3397d72 (patch)
treea34b4a3026dbd3a2ed41794555ab2f9020c4df35 /dev/ZKAKit/src
parent50c9f923a00e2fc1b80c9a7d860f96a4509d2232 (diff)
IMP: made make_application to executable, and refactor source code with
better comments. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/src')
-rw-r--r--dev/ZKAKit/src/PEFCodeMgr.cc17
-rw-r--r--dev/ZKAKit/src/PRDT.cc2
-rw-r--r--dev/ZKAKit/src/Pmm.cc6
-rw-r--r--dev/ZKAKit/src/Property.cc20
-rw-r--r--dev/ZKAKit/src/Semaphore.cc33
-rw-r--r--dev/ZKAKit/src/Stop.cc38
-rw-r--r--dev/ZKAKit/src/UserProcessScheduler.cc26
7 files changed, 93 insertions, 49 deletions
diff --git a/dev/ZKAKit/src/PEFCodeMgr.cc b/dev/ZKAKit/src/PEFCodeMgr.cc
index 311c2d2d..f929a01f 100644
--- a/dev/ZKAKit/src/PEFCodeMgr.cc
+++ b/dev/ZKAKit/src/PEFCodeMgr.cc
@@ -22,7 +22,9 @@ namespace Kernel
{
namespace Detail
{
- /// @brief Get the PEF platform signature according to the compiled backebnd
+ /***********************************************************************************/
+ /// @brief Get the PEF platform signature according to the compiled architecture.
+ /***********************************************************************************/
UInt32 ldr_get_platform(void) noexcept
{
#if defined(__ZKA_32X0__)
@@ -41,8 +43,10 @@ namespace Kernel
}
} // namespace Detail
+ /***********************************************************************************/
/// @brief PEF loader constructor w/ blob.
- /// @param blob
+ /// @param blob file blob.
+ /***********************************************************************************/
PEFLoader::PEFLoader(const VoidPtr blob)
: fCachedBlob(blob)
{
@@ -50,8 +54,10 @@ namespace Kernel
fBad = false;
}
+ /***********************************************************************************/
/// @brief PEF loader constructor.
/// @param path the filesystem path.
+ /***********************************************************************************/
PEFLoader::PEFLoader(const Char* path)
: fCachedBlob(nullptr), fBad(false), fFatBinary(false)
{
@@ -94,7 +100,9 @@ namespace Kernel
fCachedBlob = nullptr;
}
+ /***********************************************************************************/
/// @brief PEF destructor.
+ /***********************************************************************************/
PEFLoader::~PEFLoader()
{
if (fCachedBlob)
@@ -103,6 +111,11 @@ namespace Kernel
fFile.Delete();
}
+ /***********************************************************************************/
+ /// @brief Finds the symbol according to it's name.
+ /// @param name name of symbol.
+ /// @param kind kind of symbol we want.
+ /***********************************************************************************/
VoidPtr PEFLoader::FindSymbol(const Char* name, Int32 kind)
{
if (!fCachedBlob || fBad || !name)
diff --git a/dev/ZKAKit/src/PRDT.cc b/dev/ZKAKit/src/PRDT.cc
index 3aa07bb1..7df6875a 100644
--- a/dev/ZKAKit/src/PRDT.cc
+++ b/dev/ZKAKit/src/PRDT.cc
@@ -10,9 +10,11 @@
namespace Kernel
{
+ /***********************************************************************************/
/// @brief constructs a new PRD.
/// @param prd PRD reference.
/// @note This doesnt construct a valid, please fill it by yourself.
+ /***********************************************************************************/
void construct_prdt(Ref<PRDT>& prd)
{
prd.Leak().fPhysAddress = 0x0;
diff --git a/dev/ZKAKit/src/Pmm.cc b/dev/ZKAKit/src/Pmm.cc
index 4eb30df8..e9a9c9d3 100644
--- a/dev/ZKAKit/src/Pmm.cc
+++ b/dev/ZKAKit/src/Pmm.cc
@@ -17,7 +17,9 @@
namespace Kernel
{
+ /***********************************************************************************/
/// @brief Pmm constructor.
+ /***********************************************************************************/
Pmm::Pmm()
: fPageMgr()
{
@@ -26,9 +28,11 @@ namespace Kernel
Pmm::~Pmm() = default;
- /* If this returns Null pointer, enter emergency mode */
+ /***********************************************************************************/
+ /// @param If this returns Null pointer, enter emergency mode.
/// @param user is this a user page?
/// @param readWrite is it r/w?
+ /***********************************************************************************/
Ref<PTEWrapper> Pmm::RequestPage(Boolean user, Boolean readWrite)
{
PTEWrapper pt = fPageMgr.Leak().Request(user, readWrite, false, kPageSize);
diff --git a/dev/ZKAKit/src/Property.cc b/dev/ZKAKit/src/Property.cc
index f4799b97..cd9f0833 100644
--- a/dev/ZKAKit/src/Property.cc
+++ b/dev/ZKAKit/src/Property.cc
@@ -8,20 +8,38 @@
namespace CFKit
{
+ /***********************************************************************************/
+ /// @brief Destructor.
+ /***********************************************************************************/
Property::~Property() = default;
+ /***********************************************************************************/
+ /// @brief Constructor.
+ /***********************************************************************************/
+ Property::Property() = default;
+
+ /***********************************************************************************/
+ /// @brief Check if property's name equals to name.
+ /// @param name string to check.
+ /***********************************************************************************/
Bool Property::StringEquals(KString& name)
{
return this->fName && this->fName == name;
}
+ /***********************************************************************************/
+ /// @brief Gets the key (name) of property.
+ /***********************************************************************************/
KString& Property::GetKey()
{
return this->fName;
}
+ /***********************************************************************************/
+ /// @brief Gets the value of the property.
+ /***********************************************************************************/
PropertyId& Property::GetValue()
{
- return fAction;
+ return fValue;
}
} // namespace CFKit
diff --git a/dev/ZKAKit/src/Semaphore.cc b/dev/ZKAKit/src/Semaphore.cc
index b32cd3c6..29490498 100644
--- a/dev/ZKAKit/src/Semaphore.cc
+++ b/dev/ZKAKit/src/Semaphore.cc
@@ -9,6 +9,9 @@
namespace Kernel
{
+ /***********************************************************************************/
+ /// @brief Unlocks process out of the semaphore.
+ /***********************************************************************************/
Bool Semaphore::Unlock() noexcept
{
if (fLockingProcess)
@@ -19,28 +22,37 @@ namespace Kernel
return Yes;
}
+ /***********************************************************************************/
+ /// @brief Locks process in the semaphore.
+ /***********************************************************************************/
Bool Semaphore::Lock(UserProcess* process)
{
if (!process || fLockingProcess)
- return false;
+ return No;
fLockingProcess = process;
- return true;
+ return Yes;
}
+ /***********************************************************************************/
+ /// @brief Checks if process is locked.
+ /***********************************************************************************/
Bool Semaphore::IsLocked() const
{
return fLockingProcess;
}
+ /***********************************************************************************/
+ /// @brief Try lock or wait.
+ /***********************************************************************************/
Bool Semaphore::LockOrWait(UserProcess* process, TimerInterface* timer)
{
if (process == nullptr)
- return false;
+ return No;
if (timer == nullptr)
- return false;
+ return No;
this->Lock(process);
@@ -49,16 +61,11 @@ namespace Kernel
return this->Lock(process);
}
- /// @brief Wait with process, either wait for it to be being invalid, or not being run.
+ /***********************************************************************************/
+ /// @brief Wait for process to be free.
+ /***********************************************************************************/
Void Semaphore::WaitForProcess() noexcept
{
- while (fLockingProcess)
- {
- if (fLockingProcess->GetStatus() != ProcessStatusKind::kRunning)
- {
- this->Unlock();
- break;
- }
- }
+ while (fLockingProcess);
}
} // namespace Kernel
diff --git a/dev/ZKAKit/src/Stop.cc b/dev/ZKAKit/src/Stop.cc
index 53531cdd..1374c842 100644
--- a/dev/ZKAKit/src/Stop.cc
+++ b/dev/ZKAKit/src/Stop.cc
@@ -21,75 +21,73 @@
namespace Kernel
{
+ /***********************************************************************************/
+ /// @brief Stops execution of the kernel.
+ /// @param id kernel stop ID.
+ /***********************************************************************************/
Void ke_stop(const Kernel::Int32& id)
{
CGInit();
auto panic_text = RGB(0xff, 0xff, 0xff);
- auto start_y = 10;
+ auto start_y = 30;
auto x = 10;
- CGDrawString("minoskrnl.exe, bug check error raised, stopping...", start_y, x, panic_text);
+ CGDrawString("Kernel Panic!", start_y, x, panic_text);
start_y += 10;
- // simply offset from previous string and then write the website.
- CGDrawString("Please visit: ", start_y, x, panic_text);
- CGDrawString(kWebsiteURL, start_y, x + (FONT_SIZE_X * rt_string_len("Please visit: ")), panic_text);
-
CGFini();
- start_y += 10;
-
// show text according to error id.
switch (id)
{
case RUNTIME_CHECK_PROCESS: {
- CGDrawString("0x00000008 Invalid process behavior, aborting.", start_y, x, panic_text);
+ CGDrawString("0x00000008: Invalid process behavior.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_ACPI: {
- CGDrawString("0x00000006 ACPI configuration error.", start_y, x, panic_text);
+ CGDrawString("0x00000006: ACPI configuration error.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_PAGE: {
- CGDrawString("0x0000000B Write/Read in non paged area.", start_y, x, panic_text);
+ CGDrawString("0x0000000B: Write/Read in non paged area.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_FILESYSTEM: {
- CGDrawString("0x0000000A Filesystem error.", start_y, x, panic_text);
+ CGDrawString("0x0000000A: Filesystem driver error.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_POINTER: {
- CGDrawString("0x00000000 Heap is corrupted.", start_y, x, panic_text);
+ CGDrawString("0x00000000: Kernel heap is corrupted.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_BAD_BEHAVIOR: {
- CGDrawString("0x00000009 Bad Behavior.", start_y, x, panic_text);
+ CGDrawString("0x00000009: Bad behavior.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_BOOTSTRAP: {
- CGDrawString("0x0000000A Boot code has finished executing, waiting for scheduler and other cores.", start_y, x, panic_text);
+ CGDrawString("0x0000000A: Boot code has finished executing, waiting for scheduler and other cores.", start_y, x, panic_text);
return;
}
case RUNTIME_CHECK_HANDSHAKE: {
- CGDrawString("0x00000005 Handshake fault.", start_y, x, panic_text);
+ CGDrawString("0x00000005: Handshake fault.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_IPC: {
- CGDrawString("0x00000003 Bad IPC/XPCOM message.", start_y, x, panic_text);
+ CGDrawString("0x00000003: Bad LPC message.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_INVALID_PRIVILEGE: {
- CGDrawString("0x00000007 Privilege access violation.", start_y, x, panic_text);
+ CGDrawString("0x00000007: Privilege access violation.", start_y, x, panic_text);
break;
case RUNTIME_CHECK_UNEXCPECTED: {
- CGDrawString("0x0000000B Unexpected violation.", start_y, x, panic_text);
+ CGDrawString("0x0000000B: Unexpected violation.", start_y, x, panic_text);
break;
}
case RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM: {
- CGDrawString("0x10000001 Out of virtual memory.", start_y, x, panic_text);
+ CGDrawString("0x10000001: Out of virtual memory.", start_y, x, panic_text);
break;
}
diff --git a/dev/ZKAKit/src/UserProcessScheduler.cc b/dev/ZKAKit/src/UserProcessScheduler.cc
index 1a060041..4550af4e 100644
--- a/dev/ZKAKit/src/UserProcessScheduler.cc
+++ b/dev/ZKAKit/src/UserProcessScheduler.cc
@@ -118,11 +118,11 @@ namespace Kernel
{
#ifdef __ZKA_AMD64__
auto vm_register = hal_read_cr3();
- hal_write_cr3(reinterpret_cast<VoidPtr>(this->VMRegister));
+ hal_write_cr3(this->VMRegister);
auto ptr = mm_new_heap(sz + pad_amount, Yes, Yes);
- hal_write_cr3(reinterpret_cast<VoidPtr>(vm_register));
+ hal_write_cr3(vm_register);
#else
auto ptr = mm_new_heap(sz + pad_amount, Yes, Yes);
#endif
@@ -183,7 +183,7 @@ namespace Kernel
{
#ifdef __ZKA_AMD64__
auto pd = hal_read_cr3();
- hal_write_cr3(reinterpret_cast<VoidPtr>(this->VMRegister));
+ hal_write_cr3(this->VMRegister);
auto ret = mm_delete_heap(entry->MemoryEntry);
@@ -262,7 +262,7 @@ namespace Kernel
{
#ifdef __ZKA_AMD64__
auto pd = hal_read_cr3();
- hal_write_cr3(reinterpret_cast<VoidPtr>(this->VMRegister));
+ hal_write_cr3(this->VMRegister);
#endif
MUST_PASS(mm_delete_heap(memory_list->MemoryEntry));
@@ -281,7 +281,7 @@ namespace Kernel
}
//! Free the memory's page directory.
- HAL::mm_free_bitmap(reinterpret_cast<VoidPtr>(this->VMRegister));
+ HAL::mm_free_bitmap(this->VMRegister);
//! Delete image if not done already.
if (this->Code && mm_is_valid_heap(this->Code))
@@ -325,10 +325,8 @@ namespace Kernel
ProcessID UserProcessScheduler::Add(UserProcess* process)
{
- kcout << "Create VMRegister of: " << process->Name << endl;
-
#ifdef __ZKA_AMD64__
- process->VMRegister = reinterpret_cast<UIntPtr>(mm_new_heap(sizeof(PDE), No, Yes));
+ process->VMRegister = mm_new_heap(sizeof(PDE), No, Yes);
if (!process->VMRegister)
{
@@ -337,7 +335,7 @@ namespace Kernel
}
#endif // __ZKA_AMD64__
- kcout << "Create StackFrame of: " << process->Name << endl;
+ kcout << "Create page directory for: " << process->Name << endl;
process->StackFrame = reinterpret_cast<HAL::StackFramePtr>(mm_new_heap(sizeof(HAL::StackFrame), Yes, Yes));
@@ -347,11 +345,15 @@ namespace Kernel
return -kErrorProcessFault;
}
+ kcout << "Create stack for: " << process->Name << endl;
+
// Create heap according to type of process->
if (process->Kind == UserProcess::kExectuableDLLKind)
{
- kcout << "Create delegate dylib for: " << process->Name << endl;
process->PefDLLDelegate = rtl_init_dll(process);
+ MUST_PASS(process->PefDLLDelegate);
+
+ kcout << "Create delegate dylib for: " << process->Name << endl;
}
process->StackReserve = new UInt8[process->StackSize];
@@ -362,14 +364,14 @@ namespace Kernel
HAL::mm_map_page((VoidPtr)process->StackReserve, flags);
- kcout << "Validate stack reserve: " << number((UIntPtr)process->StackReserve) << endl;
-
if (!process->StackReserve)
{
process->Crash();
return -kErrorProcessFault;
}
+ kcout << "Created stack reserve for: " << process->Name << endl;
+
auto pid = kProcessIDCounter;
process->ProcessId = pid;