summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-24 09:36:47 +0100
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-24 09:36:47 +0100
commitc1c1c7cb8ec2518b746804ecc2be9e0613fe685f (patch)
tree2c43f6637c9de551ad695a4d149dd66e0d6a18b7
parent09383c793fe953da6441902b4f66b1382df46738 (diff)
Kernel: Add CRC32 check inside the kernel's heap,
Handover: Rename f_VendorTable to f_RsdPtr and f_SmBios. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
-rw-r--r--Private/Builtins/ACPI/ACPI.hxx (renamed from Private/Builtins/ACPI/ACPI.hpp)1
-rw-r--r--Private/Builtins/ACPI/ACPIFactoryInterface.hxx2
-rw-r--r--Private/Builtins/PS2/PS2MouseInterface.hxx4
-rw-r--r--Private/FirmwareKit/Handover.hxx5
-rw-r--r--Private/HALKit/AMD64/HalInterruptAPI.asm (renamed from Private/HALKit/AMD64/HalInterruptRouting.asm)12
-rw-r--r--Private/HALKit/AMD64/HalKernelMain.cxx21
-rw-r--r--Private/KernelKit/KernelHeap.hpp3
-rw-r--r--Private/KernelKit/Rsrc/Util.hxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx2
-rw-r--r--Private/Source/Crc32.cxx10
-rw-r--r--Private/Source/KernelCheck.cxx2
-rw-r--r--Private/Source/KernelHeap.cxx40
-rw-r--r--Private/makefile2
13 files changed, 62 insertions, 44 deletions
diff --git a/Private/Builtins/ACPI/ACPI.hpp b/Private/Builtins/ACPI/ACPI.hxx
index c17acac9..c0076c5e 100644
--- a/Private/Builtins/ACPI/ACPI.hpp
+++ b/Private/Builtins/ACPI/ACPI.hxx
@@ -50,6 +50,7 @@ enum class AddressSpace : UInt8 {
Pci = 2,
Controller = 3,
SmBus = 4,
+ Count = 5,
Invalid = 0xFF,
};
diff --git a/Private/Builtins/ACPI/ACPIFactoryInterface.hxx b/Private/Builtins/ACPI/ACPIFactoryInterface.hxx
index 21cd026e..b81a8dde 100644
--- a/Private/Builtins/ACPI/ACPIFactoryInterface.hxx
+++ b/Private/Builtins/ACPI/ACPIFactoryInterface.hxx
@@ -7,7 +7,7 @@
#ifndef __ACPI_MANAGER__
#define __ACPI_MANAGER__
-#include <Builtins/ACPI/ACPI.hpp>
+#include <Builtins/ACPI/ACPI.hxx>
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/Defines.hpp>
#include <NewKit/Ref.hpp>
diff --git a/Private/Builtins/PS2/PS2MouseInterface.hxx b/Private/Builtins/PS2/PS2MouseInterface.hxx
index 5e964962..2be85af1 100644
--- a/Private/Builtins/PS2/PS2MouseInterface.hxx
+++ b/Private/Builtins/PS2/PS2MouseInterface.hxx
@@ -61,14 +61,12 @@ class PS2MouseInterface final {
while (timeout) {
if ((HAL::In8(0x64) & 0x1)) {
- HCore::kcout << "NewKernel.exe: Wait: OK\r\n";
return true;
}
--timeout;
} // wait until we can read
- HCore::kcout << "NewKernel.exe: Wait: Timeout\r\n";
// return the ack bit.
return false;
}
@@ -78,14 +76,12 @@ class PS2MouseInterface final {
while (timeout) {
if ((HAL::In8(0x64) & 0b10) == 0) {
- HCore::kcout << "NewKernel.exe: Wait: OK\r\n";
return true;
}
--timeout;
} // wait until we can read
- HCore::kcout << "NewKernel.exe: Wait: Timeout\r\n";
// return the ack bit.
return false;
}
diff --git a/Private/FirmwareKit/Handover.hxx b/Private/FirmwareKit/Handover.hxx
index be308e13..03242c04 100644
--- a/Private/FirmwareKit/Handover.hxx
+++ b/Private/FirmwareKit/Handover.hxx
@@ -8,7 +8,7 @@
* @file Handover.hxx
* @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
* @brief The handover boot protocol.
- * @version 0.2
+ * @version 0.3
* @date 2024-02-23
*
* @copyright Copyright (c) 2024, Mahrouss Logic
@@ -68,7 +68,8 @@ struct HandoverInformationHeader {
WideChar f_FirmwareVendorName[32];
SizeT f_FirmwareVendorLen;
struct {
- VoidPtr f_VendorTable;
+ VoidPtr f_SmBios;
+ VoidPtr f_RsdPtr;
} f_HardwareTables;
struct {
UIntPtr f_The;
diff --git a/Private/HALKit/AMD64/HalInterruptRouting.asm b/Private/HALKit/AMD64/HalInterruptAPI.asm
index c00ce375..b62d2151 100644
--- a/Private/HALKit/AMD64/HalInterruptRouting.asm
+++ b/Private/HALKit/AMD64/HalInterruptAPI.asm
@@ -3,7 +3,7 @@
;; *
;; * Copyright Mahrouss Logic, all rights reserved.
;; *
-;; * File: HalInterruptRouting.asm
+;; * File: HalInterruptAPI.asm
;; * Purpose: Interrupt routing, redirect raw interrupts into their handlers.
;; *
;; * ---------------------------------------------------
@@ -129,13 +129,6 @@ IntNormal 49
__HCR_INT_50:
cli
- push rax
-
- mov rcx, kSystemCallLabel
- call ke_io_print
-
- pop rax
-
sti
iretq
@@ -198,6 +191,3 @@ kInterruptVectorTable:
dq __HCR_INT_%+i
%assign i i+1
%endrep
-
-kSystemCallLabel:
- db "NewKernel.exe: SystemCall: Enter SCM.", 0xa, 0xd, 0 \ No newline at end of file
diff --git a/Private/HALKit/AMD64/HalKernelMain.cxx b/Private/HALKit/AMD64/HalKernelMain.cxx
index 90a09556..10a0fe09 100644
--- a/Private/HALKit/AMD64/HalKernelMain.cxx
+++ b/Private/HALKit/AMD64/HalKernelMain.cxx
@@ -17,7 +17,7 @@
#include <KernelKit/UserHeap.hpp>
#include <NewKit/Json.hpp>
-///! @brief Disk contains HCore files.
+///! @brief Disk already contains an installation.
#define kInstalledMedia 0xDD
EXTERN_C HCore::VoidPtr kInterruptVectorTable[];
@@ -70,26 +70,33 @@ EXTERN_C void RuntimeMain(
/// END POST
/// Mounts a NewFS block.
- HCore::FilesystemManagerInterface::Mount(new HCore::NewFilesystemManager());
- HCore::ke_delete_ke_heap(HCore::FilesystemManagerInterface::Unmount());
+ HCore::NewFilesystemManager* newFS = new HCore::NewFilesystemManager();
+ HCore::ke_protect_ke_heap(newFS);
+
+ HCore::FilesystemManagerInterface::Mount(newFS);
/// We already have an install of HCore.
if (HandoverHeader->f_Bootloader == kInstalledMedia) {
ToolboxInitRsrc();
- ToolboxDrawRsrc(MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH,
- ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2),
- ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2));
+ ToolboxDrawRsrc(
+ MahroussLogic, MAHROUSSLOGIC_HEIGHT, MAHROUSSLOGIC_WIDTH,
+ ((kHandoverHeader->f_GOP.f_Width - MAHROUSSLOGIC_WIDTH) / 2),
+ ((kHandoverHeader->f_GOP.f_Height - MAHROUSSLOGIC_HEIGHT) / 2));
ToolboxClearRsrc();
+
+ TOOLBOX_LOOP() {}
} else {
/// TODO: Install hcore on host.
_hal_init_mouse();
- ToolboxDrawZone(kClearClr, kHandoverHeader->f_GOP.f_Height, kHandoverHeader->f_GOP.f_Width, 0, 0);
+ ToolboxDrawZone(kClearClr, kHandoverHeader->f_GOP.f_Height,
+ kHandoverHeader->f_GOP.f_Width, 0, 0);
TOOLBOX_LOOP() { _hal_draw_mouse(); }
}
+ HCore::ke_delete_ke_heap(newFS);
HCore::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
diff --git a/Private/KernelKit/KernelHeap.hpp b/Private/KernelKit/KernelHeap.hpp
index 974cf0f3..f8c1c9c3 100644
--- a/Private/KernelKit/KernelHeap.hpp
+++ b/Private/KernelKit/KernelHeap.hpp
@@ -14,6 +14,7 @@
namespace HCore {
Int32 ke_delete_ke_heap(voidPtr allocatedPtr);
-Boolean ke_is_valid_ptr(VoidPtr ptr);
+Boolean ke_is_valid_heap(VoidPtr ptr);
voidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user);
+Boolean ke_protect_ke_heap(VoidPtr heapPtr);
} // namespace HCore
diff --git a/Private/KernelKit/Rsrc/Util.hxx b/Private/KernelKit/Rsrc/Util.hxx
index ccca0c97..2be185e1 100644
--- a/Private/KernelKit/Rsrc/Util.hxx
+++ b/Private/KernelKit/Rsrc/Util.hxx
@@ -6,7 +6,7 @@
#define ToolboxInitRsrc() HCore::SizeT uA = 0
-#define kClearClr RGB(26, 67, B3)
+#define kClearClr RGB(00, 00, 00)
#define ToolboxClearRsrc() uA = 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index ffe7af73..663c33d9 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -145,7 +145,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
vendorTable[5] == 'T' &&
vendorTable[6] == 'R' &&
vendorTable[7] == ' ') {
- handoverHdrPtr->f_HardwareTables.f_VendorTable = (VoidPtr)vendorTable;
+ handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable;
writer.Write(L"NewBoot.exe: Found ACPI's 'RSD PTR' table on this machine.").Write(L"\r\n");
break;
diff --git a/Private/Source/Crc32.cxx b/Private/Source/Crc32.cxx
index 53de6d13..eab12c37 100644
--- a/Private/Source/Crc32.cxx
+++ b/Private/Source/Crc32.cxx
@@ -7,9 +7,10 @@
#include <NewKit/Crc32.hpp>
// @file CRC32.cpp
-// @brief Checksum implementation.
+// @brief Check sequence implementation.
namespace HCore {
+/// @brief The CRC32 table.
UInt kCrcTbl[kCrcCnt] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@@ -55,13 +56,16 @@ UInt kCrcTbl[kCrcCnt] = {
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
-/// @brief calculate CRC32 of pointer.
+/// @brief Calculate CRC32 of p
+/// @param p the data to compute.
+/// @param len the length of the data.
+/// @return the CRC32.
UInt ke_calculate_crc32(const Char *p, UInt len) noexcept {
UInt crc = 0xffffffff;
while (len-- != 0) crc = kCrcTbl[((UInt8)crc ^ *(p++))] ^ (crc >> 8);
- // return (~crc); also works
+ // return (~crc); also works, does the same thing.
return (crc ^ 0xffffffff);
}
} // namespace HCore
diff --git a/Private/Source/KernelCheck.cxx b/Private/Source/KernelCheck.cxx
index bf7ac939..dcf8a06d 100644
--- a/Private/Source/KernelCheck.cxx
+++ b/Private/Source/KernelCheck.cxx
@@ -37,7 +37,7 @@ void ke_stop(const HCore::Int &id) {
}
case RUNTIME_CHECK_POINTER: {
kcout << "*** CAUSE: RUNTIME_CHECK_POINTER *** \r\n";
- kcout << "*** WHAT: HEAP ERROR, UNSTABLE STATE. *** \r\n";
+ kcout << "*** WHAT: HEAP CRC32 ERROR, UNSTABLE STATE. *** \r\n";
break;
}
case RUNTIME_CHECK_BAD_BEHAVIOR: {
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 03e5f250..09f62004 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -5,10 +5,10 @@
------------------------------------------- */
#include <KernelKit/DebugOutput.hpp>
-#include <KernelKit/KernelHeap.hpp>
-#include <NewKit/PageManager.hpp>
#include <KernelKit/HError.hpp>
+#include <KernelKit/KernelHeap.hpp>
#include <NewKit/Crc32.hpp>
+#include <NewKit/PageManager.hpp>
//! @file KernelHeap.cxx
//! @brief Kernel allocator.
@@ -60,14 +60,14 @@ VoidPtr ke_new_ke_heap(SizeT sz, const bool rw, const bool user) {
}
/// @brief Declare pointer as free.
-/// @param ptr the pointer.
+/// @param heapPtr the pointer.
/// @return
-Int32 ke_delete_ke_heap(VoidPtr ptr) {
+Int32 ke_delete_ke_heap(VoidPtr heapPtr) {
if (kHeapCount < 1) return -kErrorInternal;
Detail::HeapInformationBlockPtr virtualAddress =
- reinterpret_cast<Detail::HeapInformationBlockPtr>((UIntPtr)ptr -
- sizeof(Detail::HeapInformationBlock));
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(
+ (UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock));
if (virtualAddress && virtualAddress->hMagic == kHeapMagic) {
if (virtualAddress->hCRC32 != 0) {
@@ -91,17 +91,35 @@ Int32 ke_delete_ke_heap(VoidPtr ptr) {
}
/// @brief Check if pointer is a valid kernel pointer.
-/// @param ptr the pointer
+/// @param heapPtr the pointer
/// @return if it exists.
-Boolean ke_is_valid_ptr(VoidPtr ptr) {
+Boolean ke_is_valid_heap(VoidPtr heapPtr) {
if (kHeapCount < 1) return false;
- if (ptr) {
+ if (heapPtr) {
+ Detail::HeapInformationBlockPtr virtualAddress =
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(
+ (UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock));
+
+ if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/// @brief Protect the heap pointer with a CRC32.
+/// @param heapPtr
+/// @return
+Boolean ke_protect_ke_heap(VoidPtr heapPtr) {
+ if (heapPtr) {
Detail::HeapInformationBlockPtr virtualAddress =
- reinterpret_cast<Detail::HeapInformationBlockPtr>((UIntPtr)ptr -
- sizeof(Detail::HeapInformationBlock));
+ reinterpret_cast<Detail::HeapInformationBlockPtr>(
+ (UIntPtr)heapPtr - sizeof(Detail::HeapInformationBlock));
if (virtualAddress->hPresent && virtualAddress->hMagic == kHeapMagic) {
+ virtualAddress->hCRC32 = ke_calculate_crc32((Char*)heapPtr, virtualAddress->hSizeAddress);
return true;
}
}
diff --git a/Private/makefile b/Private/makefile
index f1971238..b7e99049 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -29,7 +29,7 @@ MOVEALL=./MoveAll.sh
h-core-amd64-pc: clean
$(CC) $(CCFLAGS) $(DEBUG) Source/*.cxx HALKit/AMD64/Storage/*.cxx HALKit/AMD64/PCI/*.cxx Source/Network/*.cxx\
Source/Storage/*.cxx HALKit/AMD64/*.cxx HALKit/AMD64/*.cpp HALKit/AMD64/*.s
- $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptRouting.asm
+ $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalNewBoot.asm
$(ASM) $(ASMFLAGS) HALKit/AMD64/HalInstallTIB.asm