summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
Diffstat (limited to 'Private')
-rw-r--r--Private/ArchKit/ArchKit.hpp24
-rw-r--r--Private/HALKit/AMD64/HalInterruptRouting.asm17
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx3
-rw-r--r--Private/HALKit/RISCV/Hart.hxx2
-rw-r--r--Private/KernelKit/HError.hpp1
-rw-r--r--Private/Source/KernelCheck.cxx4
-rw-r--r--Private/Source/KernelHeap.cxx49
7 files changed, 38 insertions, 62 deletions
diff --git a/Private/ArchKit/ArchKit.hpp b/Private/ArchKit/ArchKit.hpp
index 17b70aa7..7f5624c1 100644
--- a/Private/ArchKit/ArchKit.hpp
+++ b/Private/ArchKit/ArchKit.hpp
@@ -20,25 +20,10 @@
#error Unknown architecture
#endif
-namespace HCore {
-template <SSizeT ID>
-class SystemCall {
- public:
- explicit SystemCall() { kcout << "SystemCall::SystemCall"; }
-
- virtual ~SystemCall() { kcout << "SystemCall::~SystemCall"; }
+#define kVirtualAddressStartOffset 0x100
- SystemCall &operator=(const SystemCall &) = default;
- SystemCall(const SystemCall &) = default;
-
- // Should not be called alone!
- virtual bool Exec() const {
- kcout << "SystemCall->Exec<RET>()";
- return false;
- }
-};
-
-constexpr static inline SSizeT syscall_hash(const char *seed, int mul) {
+namespace HCore {
+constexpr static inline SSizeT rt_hash_seed(const char *seed, int mul) {
SSizeT hash = 0;
for (SSizeT idx = 0; seed[idx] != 0; ++idx) {
@@ -48,8 +33,6 @@ constexpr static inline SSizeT syscall_hash(const char *seed, int mul) {
return hash;
}
-
-bool ke_init_hal();
} // namespace HCore
#define kKernelMaxSystemCalls (256)
@@ -61,7 +44,6 @@ extern HCore::Array<rt_syscall_proc,
kSyscalls;
EXTERN_C HCore::Void rt_wait_400ns();
-EXTERN_C HCore::Void ATTRIBUTE(interrupt) rt_syscall_handle(HCore::HAL::StackFramePtr stackFrame);
EXTERN_C HCore::HAL::StackFramePtr rt_get_current_context();
EXTERN_C HCore::Void rt_do_context_switch(HCore::HAL::StackFramePtr stackFrame);
diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptRouting.asm
index ae3d51c5..fe6fd2b5 100644
--- a/Private/HALKit/AMD64/HalInterruptRouting.asm
+++ b/Private/HALKit/AMD64/HalInterruptRouting.asm
@@ -111,16 +111,7 @@ __HCR_INT_33:
push rax
- mov rcx, kSystemCallLabelEnter
- call ke_io_print
-
- pop rax
-
- push rax
-
- ;; Find and execute system call TODO
-
- mov rcx, kSystemCallLabelExit
+ mov rcx, kSystemCallLabel
call ke_io_print
pop rax
@@ -228,9 +219,7 @@ kInterruptVectorTable:
%assign i i+1
%endrep
-kSystemCallLabelEnter:
- db "HCoreKrnl.exe: SystemCall: Enter.", 0xa, 0xd, 0
-kSystemCallLabelExit:
- db "HCoreKrnl.exe: SystemCall: Exit.", 0xa, 0xd, 0
+kSystemCallLabel:
+ db "HCoreKrnl.exe: SystemCall: Enter SCM.", 0xa, 0xd, 0
kMouseLabelExit:
db "HCoreKrnl.exe: KernelMouse: Acknowledge Interrupt.", 0xa, 0xd, 0 \ No newline at end of file
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
index 6c2ad263..abbf5feb 100644
--- a/Private/HALKit/AMD64/HalKernelMain.cxx
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -27,7 +27,7 @@ EXTERN_C void RuntimeMain(
/// Setup kernel globals.
kKernelVirtualSize = HandoverHeader->f_VirtualSize;
- kKernelVirtualStart = HandoverHeader->f_VirtualStart;
+ kKernelVirtualStart = (HandoverHeader->f_VirtualStart + kVirtualAddressStartOffset);
kKernelPhysicalSize = HandoverHeader->f_PhysicalSize;
kKernelPhysicalStart = HandoverHeader->f_PhysicalStart;
@@ -76,6 +76,7 @@ EXTERN_C void RuntimeMain(
/// Mounts a NewFS block.
HCore::FilesystemManagerInterface::Mount(new HCore::NewFilesystemManager());
+ HCore::ke_delete_ke_heap(HCore::FilesystemManagerInterface::Unmount());
/// We already have an install of HCore.
if (HandoverHeader->f_Bootloader == kInstalledMedia) {
diff --git a/Private/HALKit/RISCV/Hart.hxx b/Private/HALKit/RISCV/Hart.hxx
index f351d3e5..fbf7dca1 100644
--- a/Private/HALKit/RISCV/Hart.hxx
+++ b/Private/HALKit/RISCV/Hart.hxx
@@ -3,7 +3,7 @@
Copyright Mahrouss Logic
File: Hart.hxx
- Purpose: RISC-V hart abstraction.
+ Purpose: RISC-V hardware threads.
Revision History:
diff --git a/Private/KernelKit/HError.hpp b/Private/KernelKit/HError.hpp
index 6fb55f5a..af498520 100644
--- a/Private/KernelKit/HError.hpp
+++ b/Private/KernelKit/HError.hpp
@@ -29,6 +29,7 @@ inline constexpr HError kErrorNoSuchDisk = 45;
inline constexpr HError kErrorFileExists = 46;
inline constexpr HError kErrorFormatFailed = 47;
inline constexpr HError kErrorNetworkTimeout = 48;
+inline constexpr HError kErrorInternal = 49;
inline constexpr HError kErrorUnimplemented = 0;
Boolean ke_bug_check(void) noexcept;
diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx
index 30c76050..0fb81d47 100644
--- a/Private/Source/KernelCheck.cxx
+++ b/Private/Source/KernelCheck.cxx
@@ -32,12 +32,12 @@ void ke_stop(const HCore::Int &id) {
}
case RUNTIME_CHECK_ACPI: {
kcout << "*** CAUSE: RUNTIME_CHECK_ACPI *** \r\n";
- kcout << "*** WHAT: ACPI DEFECT. *** \r\n";
+ kcout << "*** WHAT: ACPI ERROR, UNSTABLE STATE. *** \r\n";
break;
}
case RUNTIME_CHECK_POINTER: {
kcout << "*** CAUSE: RUNTIME_CHECK_POINTER *** \r\n";
- kcout << "*** WHAT: BAD POINTER. *** \r\n";
+ kcout << "*** WHAT: HEAP ERROR, UNSTABLE STATE. *** \r\n";
break;
}
case RUNTIME_CHECK_BAD_BEHAVIOR: {
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 438df005..f5cb01da 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -6,8 +6,9 @@
#include <KernelKit/DebugOutput.hpp>
#include <KernelKit/KernelHeap.hpp>
-#include <NewKit/Crc32.hpp>
#include <NewKit/PageManager.hpp>
+#include <KernelKit/HError.hpp>
+#include <NewKit/Crc32.hpp>
//! @file KernelHeap.cxx
//! @brief Kernel allocator.
@@ -16,14 +17,13 @@
namespace HCore {
STATIC SizeT kHeapCount = 0UL;
-STATIC Ref<PTEWrapper> kHeapLastWrapper;
STATIC PageManager kHeapPageManager;
namespace Detail {
/// @brief Kernel heap information block.
/// Located before the address bytes.
/// | HIB | ADDRESS |
-struct HeapInformationBlock final {
+struct PACKED HeapInformationBlock final {
UInt16 hMagic;
Boolean hPresent;
Int32 hCRC32;
@@ -43,9 +43,6 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
if (sz == 0) ++sz;
auto wrapper = kHeapPageManager.Request(rw, user, false);
- kHeapLastWrapper = wrapper;
-
- kcout << "HCoreKrnl.exe: Populating HIB...\r\n";
Detail::HeapInformationBlockPtr heapInfo =
reinterpret_cast<Detail::HeapInformationBlockPtr>(
@@ -58,8 +55,6 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
++kHeapCount;
- kcout << "HCoreKrnl.exe: Return address...\r\n";
-
return reinterpret_cast<VoidPtr>(wrapper.VirtualAddress() +
sizeof(Detail::HeapInformationBlock));
}
@@ -68,23 +63,31 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
/// @param ptr the pointer.
/// @return
Int32 ke_delete_ke_heap(VoidPtr ptr) {
- if (ptr) {
- Detail::HeapInformationBlockPtr virtualAddress =
- reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr) -
- sizeof(Detail::HeapInformationBlock);
-
- if (kHeapLastWrapper && virtualAddress->hMagic == kHeapMagic &&
- virtualAddress->hAddress == kHeapLastWrapper.Leak().VirtualAddress()) {
- virtualAddress->hSizeAddress = 0UL;
- virtualAddress->hPresent = false;
+ if (kHeapCount < 1) return -kErrorInternal;
+
+ Detail::HeapInformationBlockPtr virtualAddress =
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr -
+ sizeof(Detail::HeapInformationBlock));
+
+ if (virtualAddress && virtualAddress->hMagic == kHeapMagic) {
+ if (virtualAddress->hCRC32 != 0) {
+ if (virtualAddress->hCRC32 !=
+ ke_calculate_crc32((Char *)virtualAddress->hAddress,
+ virtualAddress->hSizeAddress))
+ ke_stop(RUNTIME_CHECK_POINTER);
+ }
- --kHeapCount;
+ virtualAddress->hSizeAddress = 0UL;
+ virtualAddress->hPresent = false;
+ virtualAddress->hAddress = 0;
+ virtualAddress->hCRC32 = 0;
+ virtualAddress->hMagic = 0;
- return true;
- }
+ --kHeapCount;
+ return 0;
}
- return -1;
+ return -kErrorInternal;
}
/// @brief Check if pointer is a valid kernel pointer.
@@ -95,8 +98,8 @@ Boolean ke_is_valid_ptr(VoidPtr ptr) {
if (ptr) {
Detail::HeapInformationBlockPtr virtualAddress =
- reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr) -
- sizeof(Detail::HeapInformationBlock);
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(ptr -
+ sizeof(Detail::HeapInformationBlock));
if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) {
return true;