summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA
diff options
context:
space:
mode:
authorAmlal <amlal@el-mahrouss-logic.com>2024-09-12 03:16:15 +0200
committerAmlal <amlal@el-mahrouss-logic.com>2024-09-12 03:20:24 +0200
commitb323d403149db3d720a63af1087d44718821bd67 (patch)
treec15fdaf7053f40d8d6b89bc554e85998162391c7 /dev/ZKA
parent6d31d6e0959f224630317d247f489d18e65aa5bc (diff)
Kernel improvements, and Paging API changes.
ZKA: - Updated and fixed 4KB pages on ARM64. - Fixed 4KB pages on AMD64. - Refactor BMP allocator. ZBA: - Refactor Handover protocol. DDK: - Refactor and breaking API changes. HPFS: - Update code according to DDK. Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/ZKA')
-rw-r--r--dev/ZKA/FirmwareKit/Handover.hxx12
-rw-r--r--dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx73
-rw-r--r--dev/ZKA/HALKit/AMD64/HalCommAPI.cxx4
-rw-r--r--dev/ZKA/HALKit/AMD64/HalKernelMain.cxx8
-rw-r--r--dev/ZKA/HALKit/AMD64/Paging.hxx47
-rw-r--r--dev/ZKA/HALKit/ARM64/Paging.hxx36
-rw-r--r--dev/ZKA/Sources/Storage/AHCIDeviceInterface.cxx6
-rw-r--r--dev/ZKA/Sources/Storage/ATADeviceInterface.cxx6
8 files changed, 92 insertions, 100 deletions
diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx
index 8e021754..41c038ae 100644
--- a/dev/ZKA/FirmwareKit/Handover.hxx
+++ b/dev/ZKA/FirmwareKit/Handover.hxx
@@ -19,14 +19,16 @@
#include <NewKit/Defines.hxx>
-/* Handover macros. */
-
#define kHandoverMagic 0xBADCC
#define kHandoverVersion 0x0117
-/* Initial bitmap size. */
-#define kHandoverBitMapStart 0x100000000
-#define kHandoverBitMapSz gib_cast(4)
+/* Initial bitmap pointer location and size. */
+#define kHandoverBitMapStart (0x100000000)
+#define kHandoverBitMapSz (gib_cast(4))
+
+/* Executable base */
+#define kHandoverExecBase (0x4000000)
+
#define kHandoverStructSz sizeof(HEL::HANDOVER_INFO_HEADER)
namespace Kernel::HEL
diff --git a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
index 1d7d37c0..4549021f 100644
--- a/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx
@@ -17,6 +17,10 @@
#include <NewKit/Defines.hxx>
#include <NewKit/KernelCheck.hxx>
+#define cBitMapMagIdx 0
+#define cBitMapSizeIdx 1
+#define cBitMapUsedIdx 2
+
namespace Kernel
{
namespace HAL
@@ -32,21 +36,14 @@ namespace Kernel
UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(page_ptr);
- if (!ptr_bit_set[0] ||
- ptr_bit_set[0] != cBitMpMagic)
+ if (!ptr_bit_set[cBitMapMagIdx] ||
+ ptr_bit_set[cBitMapMagIdx] != cBitMpMagic)
return No;
- kcout << "BMPMgr: Freed Range!\r";
- kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl;
- kcout << "Size of pointer (B): " << number(ptr_bit_set[1]) << endl;
- kcout << "Size of pointer (KIB): " << number(KIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (MIB): " << number(MIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (GIB): " << number(GIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl;
- kcout << "Address Of Header: " << hex_number((UIntPtr)ptr_bit_set) << endl;
+ ptr_bit_set[cBitMapMagIdx] = cBitMpMagic;
+ ptr_bit_set[cBitMapUsedIdx] = No;
- ptr_bit_set[0] = cBitMpMagic;
- ptr_bit_set[2] = No;
+ this->PrintStatus(ptr_bit_set);
mm_map_page(ptr_bit_set, ~eFlagsPresent);
mm_map_page(ptr_bit_set, ~eFlagsRw);
@@ -65,23 +62,16 @@ namespace Kernel
{
UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base_ptr);
- if (ptr_bit_set[0] == cBitMpMagic)
+ if (ptr_bit_set[cBitMapMagIdx] == cBitMpMagic)
{
- if (ptr_bit_set[1] != 0 &&
- ptr_bit_set[1] <= size &&
- ptr_bit_set[2] == No)
+ if (ptr_bit_set[cBitMapSizeIdx] != 0 &&
+ ptr_bit_set[cBitMapSizeIdx] <= size &&
+ ptr_bit_set[cBitMapUsedIdx] == No)
{
- ptr_bit_set[1] = size;
- ptr_bit_set[2] = Yes;
-
- kcout << "BMPMgr: Allocated Range!\r";
- kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl;
- kcout << "Size of pointer (B): " << number(ptr_bit_set[1]) << endl;
- kcout << "Size of pointer (KIB): " << number(KIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (MIB): " << number(MIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (GIB): " << number(GIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl;
- kcout << "Address Of BMP: " << hex_number((UIntPtr)ptr_bit_set) << endl;
+ ptr_bit_set[cBitMapSizeIdx] = size;
+ ptr_bit_set[cBitMapUsedIdx] = Yes;
+
+ this->PrintStatus(ptr_bit_set);
return (VoidPtr)ptr_bit_set;
}
@@ -90,18 +80,12 @@ namespace Kernel
{
UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base_ptr);
- ptr_bit_set[0] = cBitMpMagic;
- ptr_bit_set[1] = size;
- ptr_bit_set[2] = Yes;
+ ptr_bit_set[cBitMapMagIdx] = cBitMpMagic;
+
+ ptr_bit_set[cBitMapSizeIdx] = size;
+ ptr_bit_set[cBitMapUsedIdx] = Yes;
- kcout << "BMPMgr: Allocated Range!\r";
- kcout << "Magic Number: " << hex_number(ptr_bit_set[0]) << endl;
- kcout << "Size of pointer (B): " << number(ptr_bit_set[1]) << endl;
- kcout << "Size of pointer (KIB): " << number(KIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (MIB): " << number(MIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (GIB): " << number(GIB(ptr_bit_set[1])) << endl;
- kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[1])) << endl;
- kcout << "Address Of BMP: " << hex_number((UIntPtr)ptr_bit_set) << endl;
+ this->PrintStatus(ptr_bit_set);
return (VoidPtr)ptr_bit_set;
}
@@ -114,6 +98,19 @@ namespace Kernel
return nullptr;
}
+
+ /// @brief Print Bitmap status
+ Void PrintStatus(UIntPtr* ptr_bit_set)
+ {
+ kcout << "Magic Number: " << hex_number(ptr_bit_set[cBitMapMagIdx]) << endl;
+ kcout << "Allocated: " << (ptr_bit_set[cBitMapUsedIdx] ? "Yes" : "No") << endl;
+ kcout << "Size of pointer (B): " << number(ptr_bit_set[cBitMapSizeIdx]) << endl;
+ kcout << "Size of pointer (KIB): " << number(KIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Size of pointer (MIB): " << number(MIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Size of pointer (GIB): " << number(GIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Size of pointer (TIB): " << number(TIB(ptr_bit_set[cBitMapSizeIdx])) << endl;
+ kcout << "Address Of BMP: " << hex_number((UIntPtr)ptr_bit_set) << endl;
+ }
};
} // namespace Detail
diff --git a/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx b/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx
index 087090b0..b78fd1f0 100644
--- a/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalCommAPI.cxx
@@ -12,9 +12,11 @@
/**
* @file HalCommAPI.cxx
- * @brief CPU Processor common API.
+ * @brief CPU Common API.
*/
+#define PhysShift36(ADDR) ((UInt64)ADDR >> 12)
+
namespace Kernel::HAL
{
/// @brief Maps or allocates a page from virt_addr.
diff --git a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
index df3986a1..b7dfee8a 100644
--- a/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
+++ b/dev/ZKA/HALKit/AMD64/HalKernelMain.cxx
@@ -69,8 +69,8 @@ EXTERN_C void hal_init_platform(
gdtBase.Limit = (sizeof(Kernel::HAL::Detail::ZKA_GDT_ENTRY) * cEntriesCount) - 1;
//! GDT will load hal_read_init after it successfully loads the segments.
- CONST Kernel::HAL::GDTLoader cGDT;
- cGDT.Load(gdtBase);
+ Kernel::HAL::GDTLoader gdtLoader;
+ gdtLoader.Load(gdtBase);
Kernel::ke_stop(RUNTIME_CHECK_BOOTSTRAP);
}
@@ -80,8 +80,8 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept
Kernel::HAL::Register64 idtBase;
idtBase.Base = (Kernel::UIntPtr)kInterruptVectorTable;
- CONST Kernel::HAL::IDTLoader cIDT;
- cIDT.Load(idtBase);
+ Kernel::HAL::IDTLoader idtLoader;
+ idtLoader.Load(idtBase);
if (kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled)
Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr);
diff --git a/dev/ZKA/HALKit/AMD64/Paging.hxx b/dev/ZKA/HALKit/AMD64/Paging.hxx
index a4744631..f127d0e4 100644
--- a/dev/ZKA/HALKit/AMD64/Paging.hxx
+++ b/dev/ZKA/HALKit/AMD64/Paging.hxx
@@ -41,39 +41,23 @@ EXTERN_C Kernel::VoidPtr hal_read_cr3(); // @brief Page table.
namespace Kernel::HAL
{
- struct PACKED ZKA_PTE_GENERIC
- {
- Bool Present : 1;
- Bool Wr : 1;
- Bool User : 1;
- Bool Wt : 1;
- Int32 Dirty : 1;
- Int32 MemoryType : 1;
- Int32 Global : 1;
- Int32 Resvered_0 : 3;
- UInt64 PhysicalAddress : 36;
- Int32 Reserved_1 : 10;
- Bool ProtectionKey : 5;
- Bool ExecDisable : 1;
- };
-
/// @brief Final page entry (Not PML, PDPT)
struct PACKED ZKA_PTE final
{
- Bool Present : 1;
- Bool Wr : 1;
- Bool User : 1;
- Bool Wt : 1;
- Bool Cache : 1;
- Bool Accessed : 1;
- Int32 Dirty : 1;
- Int32 MemoryType : 1;
- Int32 Global : 1;
- Int32 Resvered_0 : 3;
+ UInt64 Present : 1;
+ UInt64 Wr : 1;
+ UInt64 User : 1;
+ UInt64 Wt : 1;
+ UInt64 Cache : 1;
+ UInt64 Accessed : 1;
+ UInt64 Dirty : 1;
+ UInt64 MemoryType : 1;
+ UInt64 Global : 1;
+ UInt64 Resvered1 : 3;
UInt64 PhysicalAddress : 36;
- Int32 Reserved_1 : 10;
- Bool ProtectionKey : 5;
- Bool ExecDisable : 1;
+ UInt64 Reserved2 : 10;
+ UInt64 ProtectionKey : 5;
+ UInt64 ExecDisable : 1;
};
namespace Detail
@@ -104,11 +88,6 @@ namespace Kernel::HAL
ZKA_PTE* ALIGN(kPageAlign) fEntries[kPageMax];
};
- struct ZKA_PDE_GENERIC final
- {
- ZKA_PTE_GENERIC* ALIGN(kPageAlign) fEntries[kPageMax];
- };
-
auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr;
auto mm_free_bitmap(VoidPtr page_ptr) -> Bool;
} // namespace Kernel::HAL
diff --git a/dev/ZKA/HALKit/ARM64/Paging.hxx b/dev/ZKA/HALKit/ARM64/Paging.hxx
index 6cfeacf3..7fe020ef 100644
--- a/dev/ZKA/HALKit/ARM64/Paging.hxx
+++ b/dev/ZKA/HALKit/ARM64/Paging.hxx
@@ -58,14 +58,25 @@
namespace Kernel::HAL
{
- struct PACKED LongDescLevel3 final
+ struct PACKED PTE_4KB final
{
- Boolean Present : 1;
- Boolean Rw : 1;
- UInt16 Lpat : 9;
- UInt32 Address : 27;
- UInt32 Sbzp : 12;
- UInt32 UPat : 11;
+ UInt64 Valid : 1;
+ UInt64 Table : 1;
+ UInt64 AttrIndex : 3;
+ UInt64 NS : 1;
+ UInt64 AP : 2;
+ UInt64 SH : 2;
+ UInt64 AF : 1;
+ UInt64 NG : 1;
+ UInt64 Reserved1 : 1;
+ UInt64 Contiguous : 1;
+ UInt64 Dirty : 1;
+ UInt64 Reserved : 2;
+ UInt64 PhysicalAddress : 36;
+ UInt64 Reserved3 : 4;
+ UInt64 PXN : 1;
+ UInt64 XN : 1;
+ UInt64 Reserved4 : 9;
};
namespace Detail
@@ -91,18 +102,19 @@ namespace Kernel::HAL
}
} // namespace Detail
- struct PageDirectory64 final
+ struct PDE_4KB final
{
- LongDescLevel3 ALIGN(kPageAlign) Pte[kPageMax];
+ PTE_4KB ALIGN(kPageAlign) fEntries[kPageMax];
};
- VoidPtr mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size);
+ auto mm_alloc_bitmap(Boolean rw, Boolean user, SizeT size) -> VoidPtr;
+ auto mm_free_bitmap(VoidPtr page_ptr) -> Bool;
} // namespace Kernel::HAL
namespace Kernel
{
- typedef HAL::LongDescLevel3 PTE;
- typedef HAL::PageDirectory64 PDE;
+ typedef HAL::PTE_4KB PTE;
+ typedef HAL::PDE_4KB PDE;
} // namespace Kernel
EXTERN_C void hal_flush_tlb();
diff --git a/dev/ZKA/Sources/Storage/AHCIDeviceInterface.cxx b/dev/ZKA/Sources/Storage/AHCIDeviceInterface.cxx
index cfb80c0f..1dc52b72 100644
--- a/dev/ZKA/Sources/Storage/AHCIDeviceInterface.cxx
+++ b/dev/ZKA/Sources/Storage/AHCIDeviceInterface.cxx
@@ -9,9 +9,9 @@
using namespace Kernel;
/// @brief Class constructor
-/// @param Out Disk output
-/// @param In Disk input
-/// @param Cleanup Disk cleanup.
+/// @param Out Drive output
+/// @param In Drive input
+/// @param Cleanup Drive cleanup.
AHCIDeviceInterface::AHCIDeviceInterface(void (*Out)(MountpointInterface* outpacket),
void (*In)(MountpointInterface* inpacket),
void (*Cleanup)(void))
diff --git a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx
index 97d2e2e4..78abada0 100644
--- a/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx
+++ b/dev/ZKA/Sources/Storage/ATADeviceInterface.cxx
@@ -9,9 +9,9 @@
using namespace Kernel;
/// @brief Class constructor
-/// @param Out Disk output
-/// @param In Disk input
-/// @param Cleanup Disk cleanup.
+/// @param Out Drive output
+/// @param In Drive input
+/// @param Cleanup Drive cleanup.
ATADeviceInterface::ATADeviceInterface(
void (*Out)(MountpointInterface* outpacket),
void (*In)(MountpointInterface* inpacket),