From ff94ce367f7f23e3a78f157f9420c480a4d7f9aa Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 26 Aug 2024 04:07:14 +0200 Subject: [IMP] DLLInterface class and also reworked SCI's API. [IMP] Handover now gives the kernel image, for the OS. Signed-off-by: Amlal El Mahrouss --- dev/ZKA/Sources/DLLInterface.cxx | 23 +++++++ dev/ZKA/Sources/DLLMain.cxx | 30 +++------ dev/ZKA/Sources/PEFDLLInterface.cxx | 100 ++++++++++++++++++++++++++++++ dev/ZKA/Sources/PEFSharedObject.cxx | 110 --------------------------------- dev/ZKA/Sources/ProcessScheduler.cxx | 2 +- dev/ZKA/Sources/ThreadLocalStorage.cxx | 2 +- 6 files changed, 135 insertions(+), 132 deletions(-) create mode 100644 dev/ZKA/Sources/DLLInterface.cxx create mode 100644 dev/ZKA/Sources/PEFDLLInterface.cxx delete mode 100644 dev/ZKA/Sources/PEFSharedObject.cxx (limited to 'dev/ZKA/Sources') diff --git a/dev/ZKA/Sources/DLLInterface.cxx b/dev/ZKA/Sources/DLLInterface.cxx new file mode 100644 index 00000000..ed1793eb --- /dev/null +++ b/dev/ZKA/Sources/DLLInterface.cxx @@ -0,0 +1,23 @@ +/* + * ======================================================== + * + * newoskrnl + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#include +#include + +using namespace Kernel; + +/***********************************************************************************/ +/// @brief Unimplemented function (crashes by default) +/// @param +/***********************************************************************************/ + +EXTERN_C void __zka_pure_call(void) +{ + kcout << "newoskrnl: unimplemented symbol!\r"; +} diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index c8db0c29..997fed52 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -80,7 +80,7 @@ namespace Kernel::Detail if (catalogDir) { - Kernel::kcout << "newoskrnl: already exists.\r"; + Kernel::kcout << "newoskrnl: Already exists.\r"; delete catalogDir; continue; @@ -132,9 +132,9 @@ namespace Kernel::Detail } NFS_CATALOG_STRUCT* catalogDisk = - this->fNewFS->GetParser()->GetCatalog("\\Mount\\NUL:"); + this->fNewFS->GetParser()->GetCatalog("\\System\\newoskrnl.dll"); - const Kernel::Char* cSrcName = "DISK-INF"; + const Kernel::Char* cSrcName = "KERNEL_EXEC"; if (catalogDisk) { @@ -143,17 +143,7 @@ namespace Kernel::Detail else { catalogDisk = - (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias("\\Mount\\NUL:"); - - Kernel::StringView diskFolder(kNewFSSectorSz); - - diskFolder += - "

Kind: alias to NULL.

\r

Created by: system

\r

Edited " - "by: " - "system

\r

Volume Type: NULL.

\r"; - - diskFolder += "

Root: NUL"; - diskFolder += "

\r"; + (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias("\\System\\newoskrnl.dll"); NFS_FORK_STRUCT theDiskFork{0}; @@ -164,16 +154,16 @@ namespace Kernel::Detail theDiskFork.CatalogName, Kernel::rt_string_len(catalogDisk->Name)); - theDiskFork.DataSize = kNewFSForkSize; - theDiskFork.ResourceId = 0; - theDiskFork.ResourceKind = Kernel::kNewFSRsrcForkKind; + theDiskFork.DataSize = kHandoverHeader->f_HardwareTables.f_ImageSz; + theDiskFork.ResourceId = Kernel::kPefKindExec | 0xFFFF000; + theDiskFork.ResourceKind = Kernel::kNewFSDataForkKind; theDiskFork.Kind = Kernel::kNewFSDataForkKind; fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); fNewFS->GetParser()->WriteCatalog(catalogDisk, - true, - (Kernel::VoidPtr)diskFolder.CData(), - kNewFSSectorSz, cSrcName); + false, + kHandoverHeader->f_HardwareTables.f_ImagePtr, + kHandoverHeader->f_HardwareTables.f_ImageSz, cSrcName); delete catalogDisk; } diff --git a/dev/ZKA/Sources/PEFDLLInterface.cxx b/dev/ZKA/Sources/PEFDLLInterface.cxx new file mode 100644 index 00000000..0ca6b85e --- /dev/null +++ b/dev/ZKA/Sources/PEFDLLInterface.cxx @@ -0,0 +1,100 @@ +/* + * ======================================================== + * + * newoskrnl + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#include +#include +#include +#include +#include +#include + +/* ------------------------------------------- + + 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 + routines. (amlel) + + 07/28/24: Replace rt_library_free with rtl_fini_shared_object + + ------------------------------------------- */ + +using namespace Kernel; + +/***********************************************************************************/ +/// @file PEFSharedObjectRT.cxx +/// @brief PEF's shared object runtime. +/***********************************************************************************/ + +/***********************************************************************************/ +/** @brief Library initializer. */ +/***********************************************************************************/ + +EXTERN_C DLLInterfacePtr rtl_init_shared_object(PROCESS_HEADER_BLOCK* header) +{ + DLLInterfacePtr sharedObj = tls_new_class(); + + if (!sharedObj) + { + header->Crash(); + + return nullptr; + } + + sharedObj->Mount(tls_new_class()); + + if (!sharedObj->Get()) + { + header->Crash(); + + return nullptr; + } + + sharedObj->Get()->fImageObject = + header->Image; + + if (!sharedObj->Get()->fImageObject) + { + header->Crash(); + + return nullptr; + } + + sharedObj->Get()->fImageEntrypointOffset = + sharedObj->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); + + return sharedObj; +} + +/***********************************************************************************/ +/** @brief Frees the sharedObj. */ +/** @note Please check if the lib got freed! */ +/** @param lib The sharedObj to free. */ +/** @param successful Reports if successful or not. */ +/***********************************************************************************/ + +EXTERN_C Void rtl_fini_shared_object(PROCESS_HEADER_BLOCK* header, DLLInterfacePtr lib, Bool* successful) +{ + MUST_PASS(successful); + + // sanity check (will also trigger a bug check if this fails) + if (lib == nullptr) + { + *successful = false; + header->Crash(); + } + + delete lib->Get(); + delete lib; + + lib = nullptr; + + *successful = true; +} diff --git a/dev/ZKA/Sources/PEFSharedObject.cxx b/dev/ZKA/Sources/PEFSharedObject.cxx deleted file mode 100644 index 22890e22..00000000 --- a/dev/ZKA/Sources/PEFSharedObject.cxx +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ======================================================== - * - * Kernel - * Copyright ZKA Technologies., all rights reserved. - * - * ======================================================== - */ - -#include -#include -#include -#include -#include -#include - -/* ------------------------------------------- - - 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 - routines. (amlel) - - 07/28/24: Replace rt_library_free with rtl_fini_shared_object - - ------------------------------------------- */ - -using namespace Kernel; - -/***********************************************************************************/ -/// @file PEFSharedObjectRT.cxx -/// @brief PEF's shared object runtime. -/***********************************************************************************/ - -/***********************************************************************************/ -/** @brief Library initializer. */ -/***********************************************************************************/ - -EXTERN_C SharedObjectPtr rtl_init_shared_object(PROCESS_HEADER_BLOCK* header) -{ - SharedObjectPtr sharedObj = tls_new_class(); - - if (!sharedObj) - { - header->Crash(); - - return nullptr; - } - - sharedObj->Mount(tls_new_class()); - - if (!sharedObj->Get()) - { - header->Crash(); - - return nullptr; - } - - sharedObj->Get()->fImageObject = - header->Image; - - if (!sharedObj->Get()->fImageObject) - { - header->Crash(); - - return nullptr; - } - - sharedObj->Get()->fImageEntrypointOffset = - sharedObj->Load(kPefStart, rt_string_len(kPefStart, 0), kPefCode); - - return sharedObj; -} - -/***********************************************************************************/ -/** @brief Frees the sharedObj. */ -/** @note Please check if the lib got freed! */ -/** @param lib The sharedObj to free. */ -/** @param successful Reports if successful or not. */ -/***********************************************************************************/ - -EXTERN_C Void rtl_fini_shared_object(PROCESS_HEADER_BLOCK* header, SharedObjectPtr lib, Bool* successful) -{ - MUST_PASS(successful); - - // sanity check (will also trigger a bug check if this fails) - if (lib == nullptr) - { - *successful = false; - header->Crash(); - } - - delete lib->Get(); - delete lib; - - lib = nullptr; - - *successful = true; -} - -/***********************************************************************************/ -/// @brief Unimplemented function (crashes by default) -/// @param -/***********************************************************************************/ - -EXTERN_C void __mh_purecall(void) -{ - kcout << "newoskrnl: unimplemented symbol!\r"; -} diff --git a/dev/ZKA/Sources/ProcessScheduler.cxx b/dev/ZKA/Sources/ProcessScheduler.cxx index d33c7e85..965c5eb1 100644 --- a/dev/ZKA/Sources/ProcessScheduler.cxx +++ b/dev/ZKA/Sources/ProcessScheduler.cxx @@ -10,7 +10,7 @@ /***********************************************************************************/ #include -#include +#include #include #include #include diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx index a29f153e..ed12c890 100644 --- a/dev/ZKA/Sources/ThreadLocalStorage.cxx +++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx @@ -1,7 +1,7 @@ /* * ======================================================== * - * Kernel + * newoskrnl * Copyright ZKA Technologies., all rights reserved. * * ======================================================== -- cgit v1.2.3