diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-19 10:05:31 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-19 10:05:31 +0100 |
| commit | baf2afd8cd672dcb9c13d956dfdd73b61dfee558 (patch) | |
| tree | 0734d2fe6d480e9805121e1c7d5e42f20bf4e8f4 /Private | |
| parent | 98347089c7e4e2b306d25a0db77e00aa2ea50882 (diff) | |
unstable, secret: See below.
System.Core:
- Add RunTime init function.
- Add ReadMe.md
Kernel:
- Improve TLS code, use Encoder class instead of casting directly.
- Refactor process team to include processscheduler.hpp instead.
ObjectKit:
- Rename Object.hxx to ObjectKit.hxx
Builtins/AHCI:
- Rename API.hxx to Interface.hxx
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private')
| -rw-r--r-- | Private/Builtins/AHCI/API.hxx | 24 | ||||
| -rw-r--r-- | Private/Builtins/AHCI/Interface.hxx | 28 | ||||
| -rw-r--r-- | Private/KernelKit/ProcessScheduler.hpp | 1 | ||||
| -rw-r--r-- | Private/KernelKit/ProcessTeam.hpp | 9 | ||||
| -rw-r--r-- | Private/KernelKit/SMPManager.hpp | 10 | ||||
| -rw-r--r-- | Private/KernelKit/ThreadLocalStorage.hxx | 15 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 2 | ||||
| -rw-r--r-- | Private/NewKit/Defines.hpp | 28 | ||||
| -rw-r--r-- | Private/ObjectKit/ObjectKit.hxx (renamed from Private/ObjectKit/Object.hxx) | 3 | ||||
| -rw-r--r-- | Private/Source/ProcessTeam.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/ThreadLocalStorage.cxx | 15 |
13 files changed, 75 insertions, 66 deletions
diff --git a/Private/Builtins/AHCI/API.hxx b/Private/Builtins/AHCI/API.hxx deleted file mode 100644 index 90e68bad..00000000 --- a/Private/Builtins/AHCI/API.hxx +++ /dev/null @@ -1,24 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - - File: API.hxx - Purpose: AHCI API. - - Revision History: - - 03/17/24: Added file (amlel) - -------------------------------------------- */ - -#pragma once - -#include <AHCI/Defines.hxx> -#include <NewKit/Defines.hpp> -#include <ObjectKit/Object.hxx> - -#define kObjectAHCINamespace "AHCI_DRV\\" - -namespace HCore::Builtins { -inline Boolean ke_get_ahci_handle(ObjectPtr* ppAhciObject); -} // namespace HCore::Builtins
\ No newline at end of file diff --git a/Private/Builtins/AHCI/Interface.hxx b/Private/Builtins/AHCI/Interface.hxx new file mode 100644 index 00000000..72be3d6a --- /dev/null +++ b/Private/Builtins/AHCI/Interface.hxx @@ -0,0 +1,28 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + + File: Interface.hxx + Purpose: AHCI Interface. + + Revision History: + + 03/17/24: Added file (amlel) + +------------------------------------------- */ + +#pragma once + +#include <AHCI/Defines.hxx> +#include <NewKit/Defines.hpp> +#include <ObjectKit/ObjectKit.hxx> +#include <HintKit/CompilerHint.hxx> + +#define kObjectAHCINamespace "AHCI\\" + +namespace HCore::Builtins { +/// @brief Returns an AHCI handle. +/// @param pointerAhciObject the handle to pass. +/// @return +inline Boolean HcGetHandleAHCI(_InOut ObjectPtr* pointerAhciObject); +} // namespace HCore::Builtins
\ No newline at end of file diff --git a/Private/KernelKit/ProcessScheduler.hpp b/Private/KernelKit/ProcessScheduler.hpp index 733c7c65..fa59be4b 100644 --- a/Private/KernelKit/ProcessScheduler.hpp +++ b/Private/KernelKit/ProcessScheduler.hpp @@ -9,7 +9,6 @@ #include <ArchKit/ArchKit.hpp> #include <KernelKit/FileManager.hpp> -#include <KernelKit/ProcessTeam.hpp> #include <KernelKit/PermissionSelector.hxx> #include <NewKit/LockDelegate.hpp> #include <NewKit/MutableArray.hpp> diff --git a/Private/KernelKit/ProcessTeam.hpp b/Private/KernelKit/ProcessTeam.hpp deleted file mode 100644 index 9538bbae..00000000 --- a/Private/KernelKit/ProcessTeam.hpp +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <KernelKit/ProcessScheduler.hpp> diff --git a/Private/KernelKit/SMPManager.hpp b/Private/KernelKit/SMPManager.hpp index 49406f1b..c207be82 100644 --- a/Private/KernelKit/SMPManager.hpp +++ b/Private/KernelKit/SMPManager.hpp @@ -4,8 +4,8 @@ ------------------------------------------- */ -#ifndef _INC_SMP_MANAGER_HPP -#define _INC_SMP_MANAGER_HPP +#ifndef __SMP_MANAGER__ +#define __SMP_MANAGER__ #include <ArchKit/ArchKit.hpp> #include <CompilerKit/CompilerKit.hxx> @@ -112,11 +112,11 @@ class SMPManager final { /// @brief wakes up thread. /// wakes up thread from hang. -void rt_wakeup_thread(HAL::StackFrame* stack); +Void rt_wakeup_thread(HAL::StackFramePtr stack); /// @brief makes thread sleep. /// hooks and hangs thread to prevent code from executing. -void rt_hang_thread(HAL::StackFrame* stack); +Void rt_hang_thread(HAL::StackFramePtr stack); } // namespace HCore -#endif // !_INC_SMP_MANAGER_HPP +#endif // !__SMP_MANAGER__ diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx index 2fab5026..c6be2c2b 100644 --- a/Private/KernelKit/ThreadLocalStorage.hxx +++ b/Private/KernelKit/ThreadLocalStorage.hxx @@ -26,28 +26,21 @@ T *tls_new_class(Args &&...args); #define kTLSCookieLen 3 -typedef HCore::Char* rt_cookie_type; - -#define kTIBNameLen 256 - /// @brief Thread Information Block for Local Storage. /// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) -struct ThreadInformationBlock final { - HCore::Char Name[kTIBNameLen]; // Module Name +struct PACKED ThreadInformationBlock final { + HCore::Char Cookie[kTLSCookieLen]; HCore::UIntPtr StartCode; // Start Address HCore::UIntPtr StartData; // Allocation Heap HCore::UIntPtr StartStack; // Stack Pointer. - HCore::Int32 Arch; // Architecture and/or platform. - HCore::Int32 ID; // Thread execution ID. - rt_cookie_type Cookie; // Not shown in public header, location of the cookie header is store here, this is the way we tell - // something went wrong. + HCore::Int32 ThreadID; // Thread execution ID. }; /// @brief TLS install TIB EXTERN_C void rt_install_tib(ThreadInformationBlock *pTib, HCore::VoidPtr pPib); ///! @brief Cookie Sanity check. -HCore::Boolean tls_check_tib(ThreadInformationBlock *ptr); +HCore::Boolean tls_check_tib(ThreadInformationBlock* ptr); /// @brief TLS check system call EXTERN_C HCore::Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept; diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx index 8418fd4c..350ea0e7 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx @@ -107,7 +107,7 @@ Void BFileReader::ReadAll() { if (auto err = BS->AllocatePool(EfiLoaderCode, mSizeFile, (VoidPtr*)&mBlob) != kEfiOk) { mWriter.Write(L"*** EFI-Code: ").Write(err).Write(L" ***\r\n"); - EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error."); + EFI::RaiseHardError(L"NewBoot_PageError", L"Allocation error."); } } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index cfd58516..a45d12e4 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -45,7 +45,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, for (auto& ch : strDate) writer.WriteCharacter(ch); - writer.Write(L"\r\nHCoreLdr: Firmware Vendor: ") + writer.Write(L"\r\nNewBoot: Firmware Vendor: ") .Write(SystemTable->FirmwareVendor) .Write(L"\r\n"); diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 2eab4a84..fbedfd52 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -33,7 +33,7 @@ invalid-recipe: bootloader-amd64: compile-amd64 $(LD_GNU) $(OBJ) $(LD_FLAGS) -o NewBoot.exe $(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI - $(COPY) NewBoot.exe CDROM/EFI/BOOT/HCORELDR.EFI + $(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI $(ADD_FILE) CDROM/.HCORE .PHONY: compile-amd64 diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp index 563af7d2..c111f80f 100644 --- a/Private/NewKit/Defines.hpp +++ b/Private/NewKit/Defines.hpp @@ -8,10 +8,6 @@ #include <NewKit/Macros.hpp> -#ifndef __KERNEL__ -# error You are not compiling the kernel. -#endif - #define NEWKIT_VERSION "1.01" #if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__) @@ -20,9 +16,11 @@ #ifdef __has_feature #if !__has_feature(cxx_nullptr) +#if !__has_nullptr #error You must at least have nullptr featured on your C++ compiler. #endif #endif +#endif namespace HCore { using voidPtr = void *; @@ -89,6 +87,28 @@ template <typename Args> inline Args &&move(Args &&arg) { return static_cast<Args &&>(arg); } + +/// @brief Encoding class +class Encoder final { +public: + explicit Encoder() = default; + ~Encoder() = default; + + Encoder &operator=(const Encoder &) = default; + Encoder(const Encoder &) = default; + +public: + template <typename T> + Char* AsBytes(T type) { + return reinterpret_cast<Char*>(type); + } + + template <typename T, typename Y> + Y As(T type) { + return reinterpret_cast<Y>(type); + } + +}; } // namespace HCore #define DEDUCE_ENDIAN(address, value) \ diff --git a/Private/ObjectKit/Object.hxx b/Private/ObjectKit/ObjectKit.hxx index dbb7944d..329b2c78 100644 --- a/Private/ObjectKit/Object.hxx +++ b/Private/ObjectKit/ObjectKit.hxx @@ -18,7 +18,8 @@ enum { kObjectTypeDevice, kObjectTypeNetwork, kObjectTypeInvalid, - kObjectTypeCount, + KObjectTypeUserDefined = 0xCF, + kObjectTypeCount = 5, }; /// \brief Object handle. diff --git a/Private/Source/ProcessTeam.cxx b/Private/Source/ProcessTeam.cxx index 569d417d..9e16c0cd 100644 --- a/Private/Source/ProcessTeam.cxx +++ b/Private/Source/ProcessTeam.cxx @@ -9,7 +9,7 @@ /// @brief Process Team API. /***********************************************************************************/ -#include <KernelKit/ProcessTeam.hpp> +#include <KernelKit/ProcessScheduler.hpp> namespace HCore { MutableArray<Ref<Process>>& ProcessTeam::AsArray() { return mProcessList; } diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index 8fd61d5e..30a241ea 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -25,26 +25,27 @@ using namespace HCore; * @return if the cookie is enabled. */ -Boolean tls_check_tib(VoidPtr ptr) { - if (!ptr) return false; +Boolean tls_check_tib(ThreadInformationBlock* tib) { + if (!tib) return false; - const char* _ptr = (const char*)ptr; + HCore::Encoder encoder; + const char* tibAsBytes = encoder.AsBytes(tib); kcout << "HCoreKrnl\\TLS: Checking for a valid cookie...\n"; - return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && - _ptr[2] == kCookieMag2; + return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && + tibAsBytes[2] == kCookieMag2; } /** - * System call implementation in HCore + * System call implementation of the TLS check. * @param ptr * @return */ EXTERN_C Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept { ThreadInformationBlock* tib = (ThreadInformationBlock*)stackPtr->Gs; - if (!tls_check_tib(tib->Cookie)) { + if (!tls_check_tib(tib)) { kcout << "HCoreKrnl\\TLS: Verification failed, Crashing...\n"; ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); } |
