summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Private/Builtins/AHCI/API.hxx24
-rw-r--r--Private/Builtins/AHCI/Interface.hxx28
-rw-r--r--Private/KernelKit/ProcessScheduler.hpp1
-rw-r--r--Private/KernelKit/ProcessTeam.hpp9
-rw-r--r--Private/KernelKit/SMPManager.hpp10
-rw-r--r--Private/KernelKit/ThreadLocalStorage.hxx15
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx2
-rw-r--r--Private/NewBoot/Source/makefile2
-rw-r--r--Private/NewKit/Defines.hpp28
-rw-r--r--Private/ObjectKit/ObjectKit.hxx (renamed from Private/ObjectKit/Object.hxx)3
-rw-r--r--Private/Source/ProcessTeam.cxx2
-rw-r--r--Private/Source/ThreadLocalStorage.cxx15
-rw-r--r--Public/Kits/System.Core/Defs.hxx20
-rw-r--r--Public/Kits/System.Core/HCoreHeap+Impl.cxx44
-rw-r--r--Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx27
-rw-r--r--Public/Kits/System.Core/Heap+Impl.cxx (renamed from Public/Kits/System.Core/Heap.cxx)1
-rw-r--r--Public/Kits/System.Core/ReadMe.md10
-rw-r--r--Public/Kits/System.Core/RuntimeInit.cxx12
-rw-r--r--Public/Kits/System.Core/Threading.hxx9
20 files changed, 155 insertions, 109 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();
}
diff --git a/Public/Kits/System.Core/Defs.hxx b/Public/Kits/System.Core/Defs.hxx
index d1e5d483..bcb3585c 100644
--- a/Public/Kits/System.Core/Defs.hxx
+++ b/Public/Kits/System.Core/Defs.hxx
@@ -14,7 +14,7 @@
#undef CA_MUST_PASS
#endif
-#include <ObjectKit/Object.hxx>
+#include <ObjectKit/ObjectKit.hxx>
#ifdef _DEBUG
#define CA_MUST_PASS(e) { if (!e) { __assert_chk_fail() } }
@@ -97,15 +97,15 @@ typedef bool BOOL;
CA_INLINE ObjectPtr kInstanceObject;
-enum {
- kProcessHeapCallAlloc = 1,
- kProcessHeapCallFree,
- kProcessHeapCallSize,
- kProcessHeapCallCheck,
- kProcessHeapCallAllocStack,
- kProcessHeapCallOpenHandle,
- kProcessHeapCallCloseHandle,
- kProcessHeapCallsCnt,
+enum HcProcessCall {
+ kProcessCallAllocPtr = 1,
+ kProcessCallFreePtr,
+ kProcessCallSizePtr,
+ kProcessCallCheckPtr,
+ kProcessCallAllocStack,
+ kProcessCallOpenHandle,
+ kProcessCallCloseHandle,
+ kProcessCallsCount = 7,
};
#include <System.Core/HintBase.hxx>
diff --git a/Public/Kits/System.Core/HCoreHeap+Impl.cxx b/Public/Kits/System.Core/HCoreHeap+Impl.cxx
new file mode 100644
index 00000000..0e1b1732
--- /dev/null
+++ b/Public/Kits/System.Core/HCoreHeap+Impl.cxx
@@ -0,0 +1,44 @@
+/** ===========================================
+ (C) Mahrouss Logic
+ ===========================================*/
+
+#include <System.Core/HCoreHeap.hxx>
+
+/// @brief Allocate from the user's heap.
+/// @param refObj
+/// @param sz
+/// @param flags
+/// @return
+CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags)
+{
+ return (PVOID)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags);
+}
+
+/// @brief Free pointer from the user's heap.
+/// @param refObj
+/// @param ptr
+/// @return
+CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr)
+{
+ CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr));
+}
+
+/// @brief Get pointer size.
+/// @param refObj
+/// @param ptr
+/// @return
+CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr)
+{
+ return refObj->Invoke(refObj, kProcessCallSizePtr, ptr);
+}
+
+/// @brief Check if the pointer exists.
+/// @param refObj Process object.
+/// @param ptr
+/// @return
+CA_EXTERN_C QWORD HcProcessHeapExists(ObjectPtr refObj, PVOID ptr)
+{
+ return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr);
+}
+
+// EOF.
diff --git a/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx b/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx
deleted file mode 100644
index 86b2bf47..00000000
--- a/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx
+++ /dev/null
@@ -1,27 +0,0 @@
-/** ===========================================
- (C) Mahrouss Logic
- ===========================================*/
-
-#include <System.Core/HCoreHeap.hxx>
-
-CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags)
-{
- return (PVOID)refObj->Invoke(refObj, kProcessHeapCallAlloc, sz, flags);
-}
-
-CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr)
-{
- CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessHeapCallFree, ptr));
-}
-
-CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr)
-{
- return refObj->Invoke(refObj, kProcessHeapCallSize, ptr);
-}
-
-CA_EXTERN_C QWORD HcProcessHeapExists(ObjectPtr refObj, PVOID ptr)
-{
- return refObj->Invoke(refObj, kProcessHeapCallCheck, ptr);
-}
-
-// eof.
diff --git a/Public/Kits/System.Core/Heap.cxx b/Public/Kits/System.Core/Heap+Impl.cxx
index aaac37a8..e3dcb11c 100644
--- a/Public/Kits/System.Core/Heap.cxx
+++ b/Public/Kits/System.Core/Heap+Impl.cxx
@@ -14,7 +14,6 @@ Heap* Heap::Shared() noexcept {
if (!heap) {
heap = new Heap();
- kInstanceObject = HcGetProcessObject();
}
return heap;
diff --git a/Public/Kits/System.Core/ReadMe.md b/Public/Kits/System.Core/ReadMe.md
new file mode 100644
index 00000000..92bfca25
--- /dev/null
+++ b/Public/Kits/System.Core/ReadMe.md
@@ -0,0 +1,10 @@
+# System.Core
+## Core System API.
+
+Currently contains:
+- System Call Interface.
+- Heap API.
+- System Heap API.
+- File API.
+- Core functions and data types.
+- System Threading API. \ No newline at end of file
diff --git a/Public/Kits/System.Core/RuntimeInit.cxx b/Public/Kits/System.Core/RuntimeInit.cxx
new file mode 100644
index 00000000..b6022bef
--- /dev/null
+++ b/Public/Kits/System.Core/RuntimeInit.cxx
@@ -0,0 +1,12 @@
+/** ===========================================
+ (C) Mahrouss Logic
+ ===========================================*/
+
+#include <System.Core/HCoreHeap.hxx>
+
+/// @brief Inits the C runtime
+/// @return if it was succesful or not.
+DWORD HcInitRuntime(VOID) {
+ kInstanceObject = HcGetProcessObject();
+ return 0;
+} \ No newline at end of file
diff --git a/Public/Kits/System.Core/Threading.hxx b/Public/Kits/System.Core/Threading.hxx
index 5d5ed0a6..bddbbf3f 100644
--- a/Public/Kits/System.Core/Threading.hxx
+++ b/Public/Kits/System.Core/Threading.hxx
@@ -14,17 +14,16 @@
#include <System.Core/Defs.hxx>
/// @brief Thread Information Block variant for scheduling.
-struct ThreadInformationBlock final {
- const CHAR Name[255]; // Module Name
+struct PACKED ThreadInformationBlock final {
const UINT_PTR StartAddress; // Start Address
const UINT_PTR StartHeap; // Allocation Heap
const UINT_PTR StartStack; // Stack Pointer.
- const DWORD Arch; // Architecture and/or platform.
- const WORD TID; // Execution Thread ID.
+ const WORD ThreadID; // Execution Thread ID.
};
ThreadInformationBlock* HcCreateThread(_Input PVOID Start,
- _Optional _InOut PVOID HeapOpt, _Optional _InOut PVOID StackOpt);
+ _Optional _InOut PVOID HeapOpt,
+ _Optional _InOut PVOID StackOpt);
BOOL HcDestroyThread(_Input ThreadInformationBlock* TIB);