summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
Diffstat (limited to 'Private')
-rw-r--r--Private/EFIKit/EFILib.hxx7
-rw-r--r--Private/HALKit/AMD64/DebugManager.asm2
-rw-r--r--Private/HALKit/AMD64/HalPageAlloc.hpp2
-rw-r--r--Private/KernelKit/DebugOutput.hpp48
-rw-r--r--Private/KernelKit/DriveManager.hpp3
-rw-r--r--Private/KernelKit/FileManager.hpp1
-rw-r--r--Private/KernelKit/Framebuffer.hpp82
-rw-r--r--Private/KernelKit/OSErr.hpp31
-rw-r--r--Private/KernelKit/PEF.hpp1
-rw-r--r--Private/KernelKit/PEFSharedObject.hxx39
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx12
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx4
-rw-r--r--Private/NewBoot/Source/compile_flags.txt3
-rw-r--r--Private/NewBoot/Source/makefile2
-rw-r--r--Private/NewKit/Macros.hpp12
-rw-r--r--Private/NewKit/PageManager.hpp103
-rw-r--r--Private/NewKit/Pmm.hpp58
-rw-r--r--Private/NewKit/Ref.hpp124
-rw-r--r--Private/Source/Framebuffer.cxx48
-rw-r--r--Private/Source/KernelHeap.cxx29
-rw-r--r--Private/Source/PEFCodeManager.cxx2
-rw-r--r--Private/Source/PEFSharedObjectMain.cxx58
-rw-r--r--Private/Source/PEFSharedObjectRT.cxx107
-rw-r--r--Private/Source/PageManager.cxx21
-rw-r--r--Private/Source/Pmm.cxx9
25 files changed, 444 insertions, 364 deletions
diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx
index e7b135ef..b08c2866 100644
--- a/Private/EFIKit/EFILib.hxx
+++ b/Private/EFIKit/EFILib.hxx
@@ -61,6 +61,13 @@ inline void KeRuntimeStop(const EfiCharType* ErrorCode,
EFI::Stop();
}
+enum {
+ kPartEPM,
+ kPartGPT,
+ kPartMBR,
+ kPartCnt,
+};
+
#ifdef __BOOTLOADER__
#include <BootKit/Platform.hxx>
#endif // IF TARGET=BOOTLOADER
diff --git a/Private/HALKit/AMD64/DebugManager.asm b/Private/HALKit/AMD64/DebugManager.asm
index cf3a4539..5cc0cd10 100644
--- a/Private/HALKit/AMD64/DebugManager.asm
+++ b/Private/HALKit/AMD64/DebugManager.asm
@@ -14,8 +14,6 @@
__rt_debug_record_table:
db "DebugMgr/HCore", 0xa, 0xd, 0
- ;; User Data goes there
- resb 64
__rt_debug_int_3:
push 0x6677 ;; Debug check error
;; then halt and goes back to L0, thens halts...
diff --git a/Private/HALKit/AMD64/HalPageAlloc.hpp b/Private/HALKit/AMD64/HalPageAlloc.hpp
index 809b6a3d..3f9428b9 100644
--- a/Private/HALKit/AMD64/HalPageAlloc.hpp
+++ b/Private/HALKit/AMD64/HalPageAlloc.hpp
@@ -19,7 +19,7 @@
#define PTE_ALIGN (4096)
#endif //! PTE_ALIGN
-#define kPagePtrAddress 0x0900000
+#define kPagePtrAddress 0x9000000
extern "C" void flush_tlb(HCore::UIntPtr VirtualAddr);
extern "C" void write_cr3(HCore::UIntPtr pde);
diff --git a/Private/KernelKit/DebugOutput.hpp b/Private/KernelKit/DebugOutput.hpp
index a651cb8b..875884ba 100644
--- a/Private/KernelKit/DebugOutput.hpp
+++ b/Private/KernelKit/DebugOutput.hpp
@@ -13,28 +13,26 @@
#include <NewKit/OwnPtr.hpp>
#include <NewKit/Stream.hpp>
-namespace HCore
-{
- // @brief Emulates a VT100 terminal.
- class TerminalDevice final : public DeviceInterface<const char*>
- {
- public:
- TerminalDevice(void (*print)(const char *), void (*get)(const char *)) : DeviceInterface<const char*>(print, get) {}
- virtual ~TerminalDevice() {}
-
- /// @brief returns device name (terminal name)
- /// @return string type (const char*)
- virtual const char* Name() const override { return ("TerminalDevice"); }
-
- TerminalDevice &operator=(const TerminalDevice &) = default;
- TerminalDevice(const TerminalDevice &) = default;
-
- };
-
- namespace Detail
- {
- bool serial_init();
- }
-
- extern TerminalDevice kcout;
-} // namespace HCore
+namespace HCore {
+// @brief Emulates a VT100 terminal.
+class TerminalDevice final : public DeviceInterface<const char *> {
+ public:
+ TerminalDevice(void (*print)(const char *), void (*get)(const char *))
+ : DeviceInterface<const char *>(print, get) {}
+
+ virtual ~TerminalDevice() {}
+
+ /// @brief returns device name (terminal name)
+ /// @return string type (const char*)
+ virtual const char *Name() const override { return ("TerminalDevice"); }
+
+ TerminalDevice &operator=(const TerminalDevice &) = default;
+ TerminalDevice(const TerminalDevice &) = default;
+};
+
+namespace Detail {
+bool serial_init();
+}
+
+extern TerminalDevice kcout;
+} // namespace HCore
diff --git a/Private/KernelKit/DriveManager.hpp b/Private/KernelKit/DriveManager.hpp
index da478a45..ac39c177 100644
--- a/Private/KernelKit/DriveManager.hpp
+++ b/Private/KernelKit/DriveManager.hpp
@@ -29,11 +29,12 @@ enum {
kEPMDrive = 0x11, // Explicit Partition Map.
kEPTDrive = 0x12, // ESP w/ EPM partition.
kMBRDrive = 0x13, // IBM PC classic partition scheme
+ kDriveCnt = 9,
};
typedef Int64 DriveID;
-// Mounted drive.
+/// @brief Mounted drive traits.
struct DriveTraits final {
char fName[kDriveNameLen]; // /System, /Boot, /USBDevice...
Int32 fKind; // fMassStorage, fFloppy, fOpticalDisc.
diff --git a/Private/KernelKit/FileManager.hpp b/Private/KernelKit/FileManager.hpp
index 6ed713c4..b65bdfe1 100644
--- a/Private/KernelKit/FileManager.hpp
+++ b/Private/KernelKit/FileManager.hpp
@@ -39,6 +39,7 @@ enum {
kFileReadAll = 101,
kFileReadChunk = 102,
kFileWriteChunk = 103,
+ kFileIOCnt = (kFileWriteChunk - kFileWriteAll) + 1,
};
typedef VoidPtr NodePtr;
diff --git a/Private/KernelKit/Framebuffer.hpp b/Private/KernelKit/Framebuffer.hpp
index 6dc94a3b..8ad23571 100644
--- a/Private/KernelKit/Framebuffer.hpp
+++ b/Private/KernelKit/Framebuffer.hpp
@@ -13,47 +13,45 @@
#include <NewKit/Defines.hpp>
#include <NewKit/Ref.hpp>
-namespace HCore
-{
- enum class FramebufferColorKind : UChar
- {
- RGB32,
- RGB16,
- RGB8,
- INVALID,
- };
-
- class FramebufferContext final
- {
- public:
- UIntPtr m_Base;
- UIntPtr m_Bpp;
- UInt m_Width;
- UInt m_Height;
-
- };
-
- class Framebuffer final
- {
- public:
- Framebuffer(Ref<FramebufferContext*> &addr);
- ~Framebuffer();
-
- Framebuffer &operator=(const Framebuffer &) = delete;
- Framebuffer(const Framebuffer &) = default;
-
- volatile UIntPtr* operator[](const UIntPtr &width_and_height);
- operator bool();
-
- const FramebufferColorKind& Color(const FramebufferColorKind &colour = FramebufferColorKind::INVALID);
-
- Ref<FramebufferContext*>& Leak();
-
- private:
- Ref<FramebufferContext*> m_FrameBufferAddr;
- FramebufferColorKind m_Colour;
-
- };
-} // namespace HCore
+namespace HCore {
+enum class FramebufferColorKind : UChar {
+ RGB32,
+ RGB16,
+ RGB8,
+ INVALID,
+};
+
+class FramebufferContext final {
+ public:
+ UIntPtr m_Base;
+ UIntPtr m_Bpp;
+ UInt m_Width;
+ UInt m_Height;
+};
+
+class Framebuffer final {
+ public:
+ Framebuffer(Ref<FramebufferContext *> &addr) : m_FrameBufferAddr(addr) {}
+ ~Framebuffer() {}
+
+ Framebuffer &operator=(const Framebuffer &) = delete;
+ Framebuffer(const Framebuffer &) = default;
+
+ volatile UIntPtr *operator[](const UIntPtr &width_and_height);
+
+ operator bool() {
+ return m_FrameBufferAddr && m_Colour != FramebufferColorKind::INVALID;
+ }
+
+ const FramebufferColorKind &Color(
+ const FramebufferColorKind &colour = FramebufferColorKind::INVALID);
+
+ Ref<FramebufferContext *> &Leak();
+
+ private:
+ Ref<FramebufferContext *> m_FrameBufferAddr;
+ FramebufferColorKind m_Colour;
+};
+} // namespace HCore
#endif /* ifndef __INC_FB_HPP__ */
diff --git a/Private/KernelKit/OSErr.hpp b/Private/KernelKit/OSErr.hpp
index 975de898..62916959 100644
--- a/Private/KernelKit/OSErr.hpp
+++ b/Private/KernelKit/OSErr.hpp
@@ -11,20 +11,19 @@
#include <NewKit/Defines.hpp>
-namespace HCore
-{
- typedef Int32 OSErr;
+namespace HCore {
+typedef Int32 OSErr;
- inline constexpr OSErr kErrorExecutable = 33;
- inline constexpr OSErr kErrorExecutableLib = 34;
- inline constexpr OSErr kErrorFileNotFound = 35;
- inline constexpr OSErr kErrorDirectoryNotFound = 36;
- inline constexpr OSErr kErrorDiskReadOnly = 37;
- inline constexpr OSErr kErrorDiskIsFull = 38;
- inline constexpr OSErr kErrorProcessFault = 39;
- inline constexpr OSErr kErrorSocketHangUp = 40;
- inline constexpr OSErr kErrorThreadLocalStorage = 41;
- inline constexpr OSErr kErrorMath = 42;
- inline constexpr OSErr kErrorNoNetwork = 43;
- inline constexpr OSErr kErrorHeapOutOfMemory = 44;
-} \ No newline at end of file
+inline constexpr OSErr kErrorExecutable = 33;
+inline constexpr OSErr kErrorExecutableLib = 34;
+inline constexpr OSErr kErrorFileNotFound = 35;
+inline constexpr OSErr kErrorDirectoryNotFound = 36;
+inline constexpr OSErr kErrorDiskReadOnly = 37;
+inline constexpr OSErr kErrorDiskIsFull = 38;
+inline constexpr OSErr kErrorProcessFault = 39;
+inline constexpr OSErr kErrorSocketHangUp = 40;
+inline constexpr OSErr kErrorThreadLocalStorage = 41;
+inline constexpr OSErr kErrorMath = 42;
+inline constexpr OSErr kErrorNoNetwork = 43;
+inline constexpr OSErr kErrorHeapOutOfMemory = 44;
+} // namespace HCore
diff --git a/Private/KernelKit/PEF.hpp b/Private/KernelKit/PEF.hpp
index afa43968..8c67c6ae 100644
--- a/Private/KernelKit/PEF.hpp
+++ b/Private/KernelKit/PEF.hpp
@@ -31,6 +31,7 @@ enum {
kPefArchRISCV,
kPefArch64x0, /* 64x000. */
kPefArch32x0,
+ kPefArchCount = (kPefArch32x0 - kPefArchIntel86S) + 1,
kPefArchInvalid = 0xFF,
};
diff --git a/Private/KernelKit/PEFSharedObject.hxx b/Private/KernelKit/PEFSharedObject.hxx
index af90858e..263f08f4 100644
--- a/Private/KernelKit/PEFSharedObject.hxx
+++ b/Private/KernelKit/PEFSharedObject.hxx
@@ -16,10 +16,13 @@
#include <NewKit/Defines.hpp>
namespace HCore {
- /**
- * @brief Shared Library class
- * Load library from this class
- */
+/// @brief Pure implementation, missing method/function handler.
+extern "C" void __mh_purecall(void);
+
+/**
+ * @brief Shared Library class
+ * Load library from this class
+ */
class SharedObject final {
public:
struct SharedObjectTraits final {
@@ -44,9 +47,7 @@ class SharedObject final {
public:
void Mount(SharedObjectTraits *to_mount) {
- if (!to_mount ||
- !to_mount->fImageObject)
- return;
+ if (!to_mount || !to_mount->fImageObject) return;
fMounted = to_mount;
@@ -65,17 +66,18 @@ class SharedObject final {
};
template <typename SymbolType>
- SymbolType Load(const char *symbol_name) {
- auto ret = reinterpret_cast<SymbolType>(
- fLoader->FindSymbol(symbol_name, kPefCode));
+ SymbolType Load(const char *symbol_name, SizeT len, Int32 kind) {
+ if (symbol_name == nullptr || *symbol_name == 0) return nullptr;
+ if (len > kPathLen || len < 1) return nullptr;
- if (!ret)
- ret = reinterpret_cast<SymbolType>(
- fLoader->FindSymbol(symbol_name, kPefData));
+ auto ret =
+ reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kind));
- if (!ret)
- ret = reinterpret_cast<SymbolType>(
- fLoader->FindSymbol(symbol_name, kPefZero));
+ if (!ret) {
+ if (kind == kPefCode) return (VoidPtr)__mh_purecall;
+
+ return nullptr;
+ }
return ret;
}
@@ -84,10 +86,7 @@ class SharedObject final {
PEFLoader *fLoader{nullptr};
};
-inline void hcore_pure_call(void) {
- // virtual placeholder.
- return;
-}
+typedef SharedObject *SharedObjectPtr;
} // namespace HCore
#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 54f1d5d9..cec3bdc2 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -62,11 +62,23 @@ class BFileReader final {
HCore::VoidPtr ReadAll();
+ enum {
+ kOperationOkay,
+ kNotSupported,
+ kEmptyDirectory,
+ kNoSuchEntry,
+ kIsDirectory,
+ kCount,
+ };
+
+ Int32 &Error() { return mErrorCode; }
+
public:
BFileReader &operator=(const BFileReader &) = default;
BFileReader(const BFileReader &) = default;
private:
+ Int32 mErrorCode{kOperationOkay};
CharacterType mPath[255];
};
diff --git a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
index d1d230b6..d06338b5 100644
--- a/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/Entrypoint.cxx
@@ -19,7 +19,9 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle,
KeInitEFI(SystemTable);
BTextWriter writer;
- writer.WriteString(L"HCoreLdr: Booting from \\Volume0\\...")
+ writer.WriteString(L"HCoreLdr: Firmware: ")
+ .WriteString(SystemTable->FirmwareVendor)
+ .WriteString(L"\r\nHCoreLdr: Booting on \\Volume0\\ (FAT32)")
.WriteString(L"\r\n");
UInt64 mapKey = 0;
diff --git a/Private/NewBoot/Source/compile_flags.txt b/Private/NewBoot/Source/compile_flags.txt
new file mode 100644
index 00000000..e58d7ab9
--- /dev/null
+++ b/Private/NewBoot/Source/compile_flags.txt
@@ -0,0 +1,3 @@
+-std=c++20
+-I../
+-I../../
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 4193f12d..f10a4194 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -14,7 +14,7 @@ invalid-recipe:
.PHONY: bootloader-amd64
bootloader-amd64:
- $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx
+ $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx
$(LD_GNU) *.o -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe
cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI
cp ../../HCoreKrnl.exe CDROM/EFI/BOOT/HCoreKrnl.exe
diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp
index 02be7180..94fd8fe8 100644
--- a/Private/NewKit/Macros.hpp
+++ b/Private/NewKit/Macros.hpp
@@ -65,7 +65,7 @@
#endif
#ifndef ENUM_STRING
-#define ENUM_STRING(NAME, VAL) constexpr const char *NAME = VAL
+#define ENUM_STRING(NAME, VAL) inline constexpr const char *NAME = VAL
#endif
#ifndef END_STRING_ENUM
@@ -76,9 +76,13 @@
#define Alloca(Sz) __builtin_alloca(Sz)
#endif // #ifndef Alloca
-#ifndef CantReach
-#define CantReach() __builtin_unreachable()
+#ifndef CANT_REACH
+#define CANT_REACH() __builtin_unreachable()
#endif
#define kBadPtr 0xFBFBFBFBFBFBFBFB
-#define kmaxAddr 0xFFFFFFFFFFFFFFFF
+#define kMaxAddr 0xFFFFFFFFFFFFFFFF
+#define kPathLen 255
+
+#define PACKED ATTRIBUTE(packed)
+#define NO_EXEC ATTRIBUTE(noexec)
diff --git a/Private/NewKit/PageManager.hpp b/Private/NewKit/PageManager.hpp
index b5337268..fdde95f8 100644
--- a/Private/NewKit/PageManager.hpp
+++ b/Private/NewKit/PageManager.hpp
@@ -18,64 +18,65 @@
#ifndef kBadAddress
#define kBadAddress (0)
-#endif // #ifndef kBadAddress
+#endif // #ifndef kBadAddress
-namespace HCore
-{
+namespace HCore {
class PageManager;
-class PTEWrapper final
-{
- public:
- explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0);
- ~PTEWrapper();
-
- PTEWrapper &operator=(const PTEWrapper &) = default;
- PTEWrapper(const PTEWrapper &) = default;
-
- public:
- void FlushTLB(Ref<PageManager> &pm);
- const UIntPtr &VirtualAddress();
-
- bool Reclaim();
- bool Shareable();
- bool Present();
- bool Access();
-
- private:
- Boolean m_Rw;
- Boolean m_User;
- Boolean m_ExecDisable;
- UIntPtr m_VirtAddr;
- Boolean m_Cache;
- Boolean m_Shareable;
- Boolean m_Wt;
- Boolean m_Present;
- Boolean m_Accessed;
-
- private:
- friend class PageManager;
- friend class Pmm;
+class PTEWrapper final {
+ public:
+ explicit PTEWrapper(Boolean Rw = false, Boolean User = false,
+ Boolean ExecDisable = false, UIntPtr Address = 0);
+ ~PTEWrapper();
+
+ PTEWrapper &operator=(const PTEWrapper &) = default;
+ PTEWrapper(const PTEWrapper &) = default;
+
+ public:
+ void FlushTLB(Ref<PageManager> &pm);
+ const UIntPtr &VirtualAddress();
+
+ void NoExecute(const bool enable = false);
+ const bool &NoExecute();
+
+ bool Reclaim();
+ bool Shareable();
+ bool Present();
+ bool Access();
+
+ private:
+ Boolean m_Rw;
+ Boolean m_User;
+ Boolean m_ExecDisable;
+ UIntPtr m_VirtAddr;
+ Boolean m_Cache;
+ Boolean m_Shareable;
+ Boolean m_Wt;
+ Boolean m_Present;
+ Boolean m_Accessed;
+
+ private:
+ friend class PageManager;
+ friend class Pmm;
};
-struct PageManager final
-{
- public:
- PageManager() = default;
- ~PageManager() = default;
+struct PageManager final {
+ public:
+ PageManager() = default;
+ ~PageManager() = default;
- PageManager &operator=(const PageManager &) = default;
- PageManager(const PageManager &) = default;
+ PageManager &operator=(const PageManager &) = default;
+ PageManager(const PageManager &) = default;
- public:
- PTEWrapper *Request(Boolean Rw, Boolean User, Boolean ExecDisable);
- bool Free(Ref<PTEWrapper*> &wrapper);
+ public:
+ PTEWrapper *Request(Boolean Rw, Boolean User, Boolean ExecDisable);
+ bool Free(Ref<PTEWrapper *> &wrapper);
- private:
- void FlushTLB(UIntPtr VirtAddr);
+ private:
+ void FlushTLB(UIntPtr VirtAddr);
- private:
- friend PTEWrapper;
- friend class Pmm;
+ private:
+ friend PTEWrapper;
+ friend class Pmm;
};
-} // namespace HCore
+} // namespace HCore
diff --git a/Private/NewKit/Pmm.hpp b/Private/NewKit/Pmm.hpp
index 58bf7609..eb7f75ab 100644
--- a/Private/NewKit/Pmm.hpp
+++ b/Private/NewKit/Pmm.hpp
@@ -13,33 +13,31 @@
#include <NewKit/PageManager.hpp>
#include <NewKit/Ref.hpp>
-namespace HCore
-{
- class Pmm;
- class PTEWrapper;
-
- class Pmm final
- {
- public:
- Pmm();
- ~Pmm();
-
- public:
- explicit Pmm(Ref<PageManager*> &pm);
-
- Pmm &operator=(const Pmm &) = delete;
- Pmm(const Pmm &) = delete;
-
- Ref<PTEWrapper*> RequestPage(Boolean user = false, Boolean readWrite = false);
- Boolean FreePage(Ref<PTEWrapper*> refPage);
-
- Boolean ToggleRw(Ref<PTEWrapper*> refPage, Boolean enable = true);
- Boolean TogglePresent(Ref<PTEWrapper*> refPage, Boolean enable = true);
- Boolean ToggleUser(Ref<PTEWrapper*> refPage, Boolean enable = true);
- Boolean ToggleShare(Ref<PTEWrapper*> refPage, Boolean enable = true);
-
- private:
- Ref<PageManager*> m_PageManager;
-
- };
-} // namespace HCore
+namespace HCore {
+class Pmm;
+class PTEWrapper;
+
+class Pmm final {
+ public:
+ explicit Pmm();
+ ~Pmm();
+
+ Pmm &operator=(const Pmm &) = delete;
+ Pmm(const Pmm &) = default;
+
+ Ref<PTEWrapper *> RequestPage(Boolean user = false,
+ Boolean readWrite = false);
+ Boolean FreePage(Ref<PTEWrapper *> refPage);
+
+ Boolean ToggleRw(Ref<PTEWrapper *> refPage, Boolean enable = true);
+ Boolean TogglePresent(Ref<PTEWrapper *> refPage, Boolean enable = true);
+ Boolean ToggleUser(Ref<PTEWrapper *> refPage, Boolean enable = true);
+ Boolean ToggleShare(Ref<PTEWrapper *> refPage, Boolean enable = true);
+
+ /// @brief Get the page manager of this.
+ Ref<PageManager> &Leak() { return m_PageManager; }
+
+ private:
+ Ref<PageManager> m_PageManager;
+};
+} // namespace HCore
diff --git a/Private/NewKit/Ref.hpp b/Private/NewKit/Ref.hpp
index d11f3f75..9988c213 100644
--- a/Private/NewKit/Ref.hpp
+++ b/Private/NewKit/Ref.hpp
@@ -13,76 +13,54 @@
#include <NewKit/Defines.hpp>
#include <NewKit/RuntimeCheck.hpp>
-namespace HCore
-{
- template <typename T>
- class Ref final
- {
- public:
- Ref() = default;
- ~Ref() = default;
-
- public:
- Ref(T cls, const bool &strong = false) : m_Class(cls), m_Strong(strong) {}
-
- Ref &operator=(T ref)
- {
- m_Class = ref;
- return *this;
- }
-
- public:
- T operator->() const
- {
- return m_Class;
- }
-
- T &Leak()
- {
- return m_Class;
- }
-
- T operator*()
- {
- return m_Class;
- }
-
- bool IsStrong() const
- {
- return m_Strong;
- }
-
- operator bool()
- {
- return m_Class;
- }
-
- private:
- T m_Class;
- bool m_Strong{ false };
-
- };
-
- template <typename T>
- class NonNullRef final
- {
- public:
- NonNullRef() = delete;
- NonNullRef(nullPtr) = delete;
-
- NonNullRef(T *ref) : m_Ref(ref, true) {}
-
- Ref<T> &operator->()
- {
- MUST_PASS(m_Ref);
- return m_Ref;
- }
-
- NonNullRef &operator=(const NonNullRef<T> &ref) = delete;
- NonNullRef(const NonNullRef<T> &ref) = default;
-
- private:
- Ref<T> m_Ref{nullptr};
-
- };
-} // namespace HCore
+namespace HCore {
+template <typename T>
+class Ref final {
+ public:
+ Ref() = default;
+ ~Ref() = default;
+
+ public:
+ Ref(T cls, const bool &strong = false) : m_Class(cls), m_Strong(strong) {}
+
+ Ref &operator=(T ref) {
+ m_Class = ref;
+ return *this;
+ }
+
+ public:
+ T operator->() const { return m_Class; }
+
+ T &Leak() { return m_Class; }
+
+ T operator*() { return m_Class; }
+
+ bool IsStrong() const { return m_Strong; }
+
+ operator bool() { return m_Strong; }
+
+ private:
+ T m_Class;
+ bool m_Strong{false};
+};
+
+template <typename T>
+class NonNullRef final {
+ public:
+ NonNullRef() = delete;
+ NonNullRef(nullPtr) = delete;
+
+ NonNullRef(T *ref) : m_Ref(ref, true) {}
+
+ Ref<T> &operator->() {
+ MUST_PASS(m_Ref);
+ return m_Ref;
+ }
+
+ NonNullRef &operator=(const NonNullRef<T> &ref) = delete;
+ NonNullRef(const NonNullRef<T> &ref) = default;
+
+ private:
+ Ref<T> m_Ref{nullptr};
+};
+} // namespace HCore
diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx
index 251cdb93..3b8fa229 100644
--- a/Private/Source/Framebuffer.cxx
+++ b/Private/Source/Framebuffer.cxx
@@ -1,36 +1,34 @@
-/*
- * ========================================================
- *
- * HCore
- * Copyright Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
+/* -------------------------------------------
-#include <KernelKit/Framebuffer.hpp>
+ Copyright Mahrouss Logic
-namespace HCore {
-Framebuffer::Framebuffer(HCore::Ref<FramebufferContext*>& addr)
- : m_FrameBufferAddr(addr), m_Colour(FramebufferColorKind::RGB32) {}
+ File: Framebuffer.cxx
+ Purpose: EFI C++ library
-Framebuffer::~Framebuffer() = default;
+ Revision History:
-volatile UIntPtr* Framebuffer::operator[](const UIntPtr& width_and_height) {
- if (m_FrameBufferAddr)
- return reinterpret_cast<volatile HCore::UIntPtr*>(
- m_FrameBufferAddr->m_Base + width_and_height);
+ 01/02/24: Added file (amlel)
- return nullptr;
-}
+------------------------------------------- */
-Ref<FramebufferContext*>& Framebuffer::Leak() { return m_FrameBufferAddr; }
+#include <KernelKit/Framebuffer.hpp>
-Framebuffer::operator bool() { return m_FrameBufferAddr; }
+using namespace HCore;
-const FramebufferColorKind& Framebuffer::Color(
- const FramebufferColorKind& colour) {
- if (colour != FramebufferColorKind::INVALID) m_Colour = colour;
+volatile UIntPtr *Framebuffer::operator[](const UIntPtr &width_and_height) {
+ return (UIntPtr *)(m_FrameBufferAddr->m_Base * width_and_height);
+}
+
+const FramebufferColorKind &Framebuffer::Color(
+ const FramebufferColorKind &colour) {
+ if (m_Colour != FramebufferColorKind::INVALID &&
+ colour != FramebufferColorKind::INVALID) {
+ m_Colour = colour;
+ }
return m_Colour;
}
-} // namespace HCore
+
+Ref<FramebufferContext *> &Framebuffer::Leak() {
+ return this->m_FrameBufferAddr;
+}
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 42ea0187..603b91b3 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -9,6 +9,8 @@
#include <NewKit/KernelHeap.hpp>
+#include "NewKit/PageManager.hpp"
+
//! @file KernelHeap.cpp
//! @brief Kernel allocator.
@@ -48,6 +50,8 @@ VoidPtr ke_new_ke_heap(const SizeT &sz, const bool rw, const bool user) {
Ref<PTEWrapper *> wrapper = kPmm.RequestPage(user, rw);
if (wrapper) {
+ wrapper->NoExecute(true);
+
kLastWrapper = wrapper;
kWrapperList[kWrapperCount] = wrapper;
@@ -67,15 +71,27 @@ Int32 ke_delete_ke_heap(voidPtr ptr) {
const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) {
- return kPmm.FreePage(kLastWrapper);
+ if (kPmm.FreePage(kLastWrapper)) {
+ kLastWrapper->NoExecute(false);
+ return true;
+ }
+
+ return false;
}
- Ref<PTEWrapper *> wrapper;
+ Ref<PTEWrapper *> wrapper{nullptr};
for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) {
if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) {
wrapper = kWrapperList[indexWrapper];
- return kPmm.FreePage(wrapper);
+
+ // if page is no more, then mark it also as non executable.
+ if (kPmm.FreePage(wrapper)) {
+ wrapper->NoExecute(false);
+ return true;
+ }
+
+ return false;
}
}
}
@@ -108,11 +124,10 @@ Boolean kernel_valid_ptr(voidPtr ptr) {
}
/// @brief The Kernel heap initializer function.
-/// @return
-Void ke_init_ke_heap() noexcept
-{
+/// @return
+Void ke_init_ke_heap() noexcept {
kWrapperCount = 0UL;
- Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper*>(nullptr);
+ Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper *>(nullptr);
Pmm kPmm = Pmm();
}
} // namespace HCore
diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx
index 8804d1ca..63e8659f 100644
--- a/Private/Source/PEFCodeManager.cxx
+++ b/Private/Source/PEFCodeManager.cxx
@@ -7,9 +7,9 @@
* ========================================================
*/
-#include <KernelKit/CodeManager.hpp>
#include <KernelKit/DebugOutput.hpp>
#include <KernelKit/FileManager.hpp>
+#include <KernelKit/PEFCodeManager.hxx>
#include <KernelKit/ProcessManager.hpp>
#include <NewKit/Defines.hpp>
#include <NewKit/ErrorID.hpp>
diff --git a/Private/Source/PEFSharedObjectMain.cxx b/Private/Source/PEFSharedObjectMain.cxx
deleted file mode 100644
index c1803312..00000000
--- a/Private/Source/PEFSharedObjectMain.cxx
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * ========================================================
- *
- * HCore
- * Copyright Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
-
-#include <KernelKit/DebugOutput.hpp>
-#include <KernelKit/PEF.hpp>
-#include <KernelKit/ProcessManager.hpp>
-#include <KernelKit/PEFSharedObject.hxx>
-#include <KernelKit/ThreadLocalStorage.hxx>
-#include <NewKit/Defines.hpp>
-
-using namespace HCore;
-
-/***********************************************************************************/
-/// @file SharedObjectEntry.cxx
-/// @brief Shared Object Init code.
-/***********************************************************************************/
-
-/***********************************************************************************/
-/* @brief Allocate new library to be added to the lookup table.
- */
-/***********************************************************************************/
-
-extern "C" SharedObject *__LibMain(VoidPtr image) {
- SharedObject *library = hcore_tls_new_class<SharedObject>();
-
- if (!library) {
- kcout << "__LibMain: Out of Memory!\n";
- ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
-
- return nullptr;
- }
-
- library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>());
-
- if (!library->Get()) {
- kcout << "__LibMain: Out of Memory!\n";
- ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
-
- return nullptr;
- }
-
- library->Get()->fImageObject =
- ProcessManager::Shared().Leak().GetCurrent().Leak().Image;
-
- library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart);
-
- kcout << "__LibMain: Done jumping to library...\n";
-
- return library;
-}
-
-/***********************************************************************************/
diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx
new file mode 100644
index 00000000..018b618e
--- /dev/null
+++ b/Private/Source/PEFSharedObjectRT.cxx
@@ -0,0 +1,107 @@
+/*
+ * ========================================================
+ *
+ * HCore
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <KernelKit/DebugOutput.hpp>
+#include <KernelKit/PEF.hpp>
+#include <KernelKit/PEFSharedObject.hxx>
+#include <KernelKit/ProcessManager.hpp>
+#include <KernelKit/ThreadLocalStorage.hxx>
+#include <NewKit/Defines.hpp>
+
+#include "NewKit/RuntimeCheck.hpp"
+
+/* -------------------------------------------
+
+ Revision History:
+
+ 01/02/24: Rework shared library ABI, except a __LibInit and __LibFini
+ (amlel)
+
+ ------------------------------------------- */
+
+using namespace HCore;
+
+/***********************************************************************************/
+/// @file SharedObjectRT.cxx
+/// @brief Shared Object runtime.
+/***********************************************************************************/
+
+/***********************************************************************************/
+/* @brief Allocates a new library. */
+/***********************************************************************************/
+
+extern "C" SharedObject *__LibInit() {
+ SharedObject *library = hcore_tls_new_class<SharedObject>();
+
+ if (!library) {
+ kcout << "__LibInit: Out of Memory!\n";
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
+
+ return nullptr;
+ }
+
+ library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>());
+
+ if (!library->Get()) {
+ kcout << "__LibInit: Out of Memory!\n";
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
+
+ return nullptr;
+ }
+
+ library->Get()->fImageObject =
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Image;
+
+ if (!library->Get()->fImageObject) {
+ kcout << "__LibInit: Invalid image!\n";
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
+
+ return nullptr;
+ }
+
+ library->Get()->fImageEntrypointOffset =
+ library->Load<VoidPtr>(kPefStart, string_length(kPefStart, 0), kPefCode);
+
+ kcout << "__LibInit: Task was successful... Returning library...\n";
+
+ return library;
+}
+
+/***********************************************************************************/
+
+/***********************************************************************************/
+/* @brief Frees the library. */
+/* @note Please check if the lib got freed! */
+/* @param SharedObjectPtr the library to free. */
+/***********************************************************************************/
+
+extern "C" Void __LibFini(SharedObjectPtr lib, bool *successful) {
+ MUST_PASS(successful);
+
+ // sanity check (will also trigger a bug check)
+ if (lib == nullptr) {
+ kcout << "__LibFini: Invalid image!\n";
+ *successful = false;
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
+ }
+
+ delete lib->Get();
+ delete lib;
+
+ lib = nullptr;
+
+ *successful = true;
+}
+
+/***********************************************************************************/
+
+extern "C" void __mh_purecall(void) {
+ // virtual placeholder.
+ return;
+}
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index 95097f99..d6455a18 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -85,8 +85,20 @@ bool PageManager::Free(Ref<PTEWrapper *> &wrapper) {
return false;
}
+////////////////////////////
+
+// VIRTUAL ADDRESS
+
+////////////////////////////
+
const UIntPtr &PTEWrapper::VirtualAddress() { return m_VirtAddr; }
+////////////////////////////
+
+// PAGE GETTERS
+
+////////////////////////////
+
bool PTEWrapper::Shareable() {
auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
@@ -120,4 +132,13 @@ bool PTEWrapper::Access() {
return m_Accessed;
}
+
+////////////////////////////
+
+// NO EXECUTE PROTECTION
+
+////////////////////////////
+
+void PTEWrapper::NoExecute(const bool enable) { this->m_ExecDisable = enable; }
+const bool &PTEWrapper::NoExecute() { return this->m_ExecDisable; }
} // namespace HCore
diff --git a/Private/Source/Pmm.cxx b/Private/Source/Pmm.cxx
index aa5a3c89..76191fdd 100644
--- a/Private/Source/Pmm.cxx
+++ b/Private/Source/Pmm.cxx
@@ -11,11 +11,8 @@
#include <NewKit/Pmm.hpp>
namespace HCore {
-Pmm::Pmm() = default;
-
-Pmm::Pmm(Ref<PageManager *> &pm) : m_PageManager(pm) {
- MUST_PASS(pm.Leak());
- kcout << "[PMM] New PhysicalMemoryManager\r\n";
+Pmm::Pmm() : m_PageManager() {
+ kcout << "[PMM] Allocate PageMemoryManager\r\n";
}
Pmm::~Pmm() = default;
@@ -23,7 +20,7 @@ Pmm::~Pmm() = default;
/* If this returns Null pointer, enter emergency mode */
Ref<PTEWrapper *> Pmm::RequestPage(Boolean user, Boolean readWrite) {
if (m_PageManager) {
- PTEWrapper *pt = m_PageManager.Leak()->Request(user, readWrite, true);
+ PTEWrapper *pt = m_PageManager.Leak().Request(user, readWrite, true);
if (pt) return Ref<PTEWrapper *>(pt);