From b323d403149db3d720a63af1087d44718821bd67 Mon Sep 17 00:00:00 2001 From: Amlal Date: Thu, 12 Sep 2024 03:16:15 +0200 Subject: 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 --- dev/DDK/KernelCall.c | 29 ++++++---- dev/DDK/KernelStd.h | 23 ++++---- dev/DLL/Security/.keep | 0 dev/DLL/Security/build.json | 20 ------- dev/HPFS/Defines.hxx | 15 ----- dev/HPFS/EPM/EBS.i | 2 +- dev/HPFS/ReadMe.md | 9 +++ dev/HPFS/ReadMe.txt | 1 - dev/HPFS/Sources/IFSMain.cxx | 20 ------- dev/HPFS/Sources/hpfs_main.cxx | 20 +++++++ dev/HPFS/hpfs_specs.hxx | 15 +++++ dev/INST/ReadMe.md | 5 ++ dev/INST/ReadMe.txt | 4 -- dev/INST/X64/InstallAPI.asm | 34 ------------ dev/INST/X64/InstallerRoutines.asm | 34 ++++++++++++ dev/SCI/sci_base.hxx | 2 +- dev/ZBA/BootKit/BootKit.hxx | 8 +-- dev/ZKA/FirmwareKit/Handover.hxx | 12 ++-- dev/ZKA/HALKit/AMD64/HalBMPMgr.cxx | 73 ++++++++++++------------- dev/ZKA/HALKit/AMD64/HalCommAPI.cxx | 4 +- dev/ZKA/HALKit/AMD64/HalKernelMain.cxx | 8 +-- dev/ZKA/HALKit/AMD64/Paging.hxx | 47 +++++----------- dev/ZKA/HALKit/ARM64/Paging.hxx | 36 ++++++++---- dev/ZKA/Sources/Storage/AHCIDeviceInterface.cxx | 6 +- dev/ZKA/Sources/Storage/ATADeviceInterface.cxx | 6 +- 25 files changed, 211 insertions(+), 222 deletions(-) delete mode 100644 dev/DLL/Security/.keep delete mode 100644 dev/DLL/Security/build.json delete mode 100644 dev/HPFS/Defines.hxx create mode 100644 dev/HPFS/ReadMe.md delete mode 100644 dev/HPFS/ReadMe.txt delete mode 100644 dev/HPFS/Sources/IFSMain.cxx create mode 100644 dev/HPFS/Sources/hpfs_main.cxx create mode 100644 dev/HPFS/hpfs_specs.hxx create mode 100644 dev/INST/ReadMe.md delete mode 100644 dev/INST/ReadMe.txt delete mode 100644 dev/INST/X64/InstallAPI.asm create mode 100644 dev/INST/X64/InstallerRoutines.asm (limited to 'dev') diff --git a/dev/DDK/KernelCall.c b/dev/DDK/KernelCall.c index 16c36f43..49bf57b5 100644 --- a/dev/DDK/KernelCall.c +++ b/dev/DDK/KernelCall.c @@ -10,7 +10,7 @@ #include /// @brief this is an internal call, do not use it. -DK_EXTERN __attribute__((naked)) void* __KernelCallDispatch(const char* name, int32_t cnt, void* data, size_t sz); +DK_EXTERN ATTRIBUTE(naked) void* __KernelCallDispatch(const char* name, int32_t cnt, void* data, size_t sz); /// @brief Interupt Kernel /// @param KernelRpcName RPC name @@ -19,12 +19,12 @@ DK_EXTERN __attribute__((naked)) void* __KernelCallDispatch(const char* name, in /// @param sz The size of the whole data pointer. /// @retval void* Kernel call was successful. /// @retval nil Kernel call failed, call KernelLastError(void) -DK_EXTERN void* KernelCall(const char* KernelRpcName, int32_t cnt, void* data, size_t sz) +DK_EXTERN void* KernelCall(const char* name, int32_t cnt, void* data, size_t sz) { - if (!KernelRpcName || cnt == 0) + if (!name || *name == 0 || cnt == 0) return nil; - return __KernelCallDispatch(KernelRpcName, cnt, data, sz); + return __KernelCallDispatch(name, cnt, data, sz); } /// @brief Add system call. @@ -37,19 +37,24 @@ DK_EXTERN void KernelAddSyscall(const int slot, void (*slotFn)(void* a0)) /// @brief Get a Kernel property. /// @param slot property id (always 0) -/// @param name the prperty's name. -/// @return property's object. -DK_EXTERN void* KernelGetProperty(const int slot, const char* name) +/// @param name the object's name. +/// @return Object manifest. +DK_EXTERN struct DDK_OBJECT_MANIFEST* KernelGetObject(const int slot, const char* name) { - return KernelCall("RtlGetProperty", slot, (void*)name, 1); + struct DDK_OBJECT_MANIFEST* manifest = (struct DDK_OBJECT_MANIFEST*)KernelCall("RtlGetObject", slot, (void*)name, 1); + + if (!manifest) + return nil; + + return manifest; } /// @brief Set a Kernel property. /// @param slot property id (always 0) -/// @param name the property's name. -/// @param ddk_pr pointer to a property's DDK_PROPERTY_RECORD. +/// @param name the object's name. +/// @param ddk_pr pointer to a object's DDK_OBJECT_MANIFEST. /// @return property's object. -DK_EXTERN void* KernelSetProperty(const int slot, const struct DDK_PROPERTY_RECORD* ddk_pr) +DK_EXTERN void* KernelSetObject(const int slot, const struct DDK_OBJECT_MANIFEST* ddk_pr) { - return KernelCall("RtlSetProperty", slot, (void*)ddk_pr, 1); + return KernelCall("RtlSetObject", slot, (void*)ddk_pr, 1); } diff --git a/dev/DDK/KernelStd.h b/dev/DDK/KernelStd.h index ab0c6eb8..da15f269 100644 --- a/dev/DDK/KernelStd.h +++ b/dev/DDK/KernelStd.h @@ -2,7 +2,8 @@ Copyright ZKA Technologies. - Purpose: DDK DLL Base Header. + FILE: KernelStd.h + PURPOSE: DDK Driver model base header. ------------------------------------------- */ @@ -21,18 +22,20 @@ #define DK_FINAL #endif // defined(__cplusplus) +#define ATTRIBUTE(X) __attribute__((X)) + #ifndef __NEWOSKRNL__ -#error !!! including header in user mode !!! +#error !!! including header in low exception/ring-3 mode !!! #endif // __NEWOSKRNL__ struct DDK_STATUS_STRUCT; -struct DDK_PROPERTY_RECORD; +struct DDK_OBJECT_MANIFEST; -struct DDK_PROPERTY_RECORD DK_FINAL +struct DDK_OBJECT_MANIFEST DK_FINAL { char* p_name; + int32_t p_kind; void* p_object; - void* p_xpcom_object; }; /// \brief DDK status structure (__at_enable, __at_disable...) @@ -50,12 +53,12 @@ struct DDK_STATUS_STRUCT DK_FINAL /// @param dat data ptr /// @param sz sz of whole data ptr. /// @return result of call -DK_EXTERN void* KernelCall(const char* KernelRpcName, int32_t cnt, void* dat, size_t sz); +DK_EXTERN void* KernelCall(const char* name, int32_t cnt, void* dat, size_t sz); /// @brief add system call. /// @param slot system call slot /// @param slotFn, syscall slot. -DK_EXTERN void KernelAddSyscall(const int slot, void (*slotFn)(void* a0)); +DK_EXTERN void KernelAddSyscall(const int32_t slot, void (*slotFn)(void* a0)); /// @brief allocate heap ptr. /// @param sz size of ptr. @@ -70,14 +73,14 @@ DK_EXTERN void KernelFree(void*); /// @param slot property id (always 0) /// @param name the property's name. /// @return property's object. -DK_EXTERN void* KernelGetProperty(const int slot, const char* name); +DK_EXTERN struct DDK_OBJECT_MANIFEST* KernelGetObject(const int slot, const char* name); /// @brief Set a Kernel property. /// @param slot property id (always 0) /// @param name the property's name. -/// @param ddk_pr pointer to a property's DDK_PROPERTY_RECORD. +/// @param ddk_pr pointer to a property's DDK_OBJECT_MANIFEST. /// @return property's object. -DK_EXTERN void* KernelSetProperty(const int slot, const struct DDK_PROPERTY_RECORD* ddk_pr); +DK_EXTERN void* KernelSetObject(const int32_t slot, const struct DDK_OBJECT_MANIFEST* ddk_pr); /// @brief The highest API version of the DDK. DK_EXTERN int32_t c_api_version_highest; diff --git a/dev/DLL/Security/.keep b/dev/DLL/Security/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/DLL/Security/build.json b/dev/DLL/Security/build.json deleted file mode 100644 index 5877cdf6..00000000 --- a/dev/DLL/Security/build.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++", - "compiler_std": "c++20", - "headers_path": ["../"], - "sources_path": ["Sources/*.cxx"], - "output_name": "sec.dll", - "compiler_flags": [ - "-ffreestanding", - "-shared", - "-fno-rtti", - "-fno-exceptions", - "-Wl,--subsystem=17" - ], - "cpp_macros": [ - "__SEC_IMPL__", - "cSECVersion=0x0100", - "cSECVersionHighest=0x0100", - "cSECVersionLowest=0x0100" - ] -} diff --git a/dev/HPFS/Defines.hxx b/dev/HPFS/Defines.hxx deleted file mode 100644 index 8d0536a0..00000000 --- a/dev/HPFS/Defines.hxx +++ /dev/null @@ -1,15 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - FILE: Defines.hxx - PURPOSE: HPFS IFS defines. - -------------------------------------------- */ - -#pragma once - -typedef __INT32_TYPE__ HPFS_INT32; -typedef void HPFS_VOID; - -#define cHPFSVersion 0x0100 diff --git a/dev/HPFS/EPM/EBS.i b/dev/HPFS/EPM/EBS.i index 4fc529da..c137b6f4 100644 --- a/dev/HPFS/EPM/EBS.i +++ b/dev/HPFS/EPM/EBS.i @@ -10,7 +10,7 @@ HPFS_EBS_HEADER: db " HPFS" ;; MAGIC NUMBER OF FILESYSTEM dw 8 ;; MAGIC NUMBER LENGTH. dq 0 ;; RESERVED 4 - dw 1 ;; VERSION + dw 0x0100 ;; VERSION dw 0 ;; PARTITION TYPE dq 0 ;; RESERVED 3 dw 0 ;; DISK TYPE (INVALID = 0, CDROM = 1, SSD = 2, USB = 3) diff --git a/dev/HPFS/ReadMe.md b/dev/HPFS/ReadMe.md new file mode 100644 index 00000000..999b0d30 --- /dev/null +++ b/dev/HPFS/ReadMe.md @@ -0,0 +1,9 @@ +# High Performance File System + +Filesystem driver for the HPFS specification. + +## Installation + +- Use BTB to build filesystem and partition blobs. + +###### Copyright ZKA Technologies. All rights reserved. diff --git a/dev/HPFS/ReadMe.txt b/dev/HPFS/ReadMe.txt deleted file mode 100644 index 04b0e9f0..00000000 --- a/dev/HPFS/ReadMe.txt +++ /dev/null @@ -1 +0,0 @@ -This is the HPFS filesystem driver for ZKA. \ No newline at end of file diff --git a/dev/HPFS/Sources/IFSMain.cxx b/dev/HPFS/Sources/IFSMain.cxx deleted file mode 100644 index c2ae5b0a..00000000 --- a/dev/HPFS/Sources/IFSMain.cxx +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - FILE: IFSMain.cxx - PURPOSE: HPFS IFS entrypoint. - -------------------------------------------- */ - -#include -#include - -/** @brief HPFS IFS main. */ -HPFS_INT32 ModuleMain(HPFS_VOID) -{ - auto ifs_handle = KernelGetProperty(0, "\\.\\IFSObject"); - // TODO: Register IFS... - - return 0; -} diff --git a/dev/HPFS/Sources/hpfs_main.cxx b/dev/HPFS/Sources/hpfs_main.cxx new file mode 100644 index 00000000..52ac32ab --- /dev/null +++ b/dev/HPFS/Sources/hpfs_main.cxx @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + FILE: IFSMain.cxx + PURPOSE: HPFS IFS entrypoint. + +------------------------------------------- */ + +#include +#include + +/** @brief HPFS IFS main. */ +HPFS_INT32 ModuleMain(HPFS_VOID) +{ + auto ifs_handle = KernelGetObject(0, "IFS_OBJECT"); + // TODO: Register this IFS with necessary I/O functions... + + return 0; +} diff --git a/dev/HPFS/hpfs_specs.hxx b/dev/HPFS/hpfs_specs.hxx new file mode 100644 index 00000000..8d0536a0 --- /dev/null +++ b/dev/HPFS/hpfs_specs.hxx @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + FILE: Defines.hxx + PURPOSE: HPFS IFS defines. + +------------------------------------------- */ + +#pragma once + +typedef __INT32_TYPE__ HPFS_INT32; +typedef void HPFS_VOID; + +#define cHPFSVersion 0x0100 diff --git a/dev/INST/ReadMe.md b/dev/INST/ReadMe.md new file mode 100644 index 00000000..a1e39edc --- /dev/null +++ b/dev/INST/ReadMe.md @@ -0,0 +1,5 @@ +# ReadMe: INST + +This file installs ZKA OS into an HDD. +
+It can do both EPM and GPT partitions. diff --git a/dev/INST/ReadMe.txt b/dev/INST/ReadMe.txt deleted file mode 100644 index e7b71b4a..00000000 --- a/dev/INST/ReadMe.txt +++ /dev/null @@ -1,4 +0,0 @@ -ReadMe: INST - -This file installs ZKA OS into an HDD. -It can do both EPM and GPT partitions. \ No newline at end of file diff --git a/dev/INST/X64/InstallAPI.asm b/dev/INST/X64/InstallAPI.asm deleted file mode 100644 index 61c712d0..00000000 --- a/dev/INST/X64/InstallAPI.asm +++ /dev/null @@ -1,34 +0,0 @@ -;; /* -;; * --------------------------------------------------- -;; * -;; * Copyright ZKA Technologies., all rights reserved. -;; * -;; * File: Install.asm -;; * Purpose: ZKA installer program, runs at ring-0. -;; * -;; * --------------------------------------------------- -;; */ - -[bits 64] - -[global kInstallTitle] -[global InstInstallToDir] - -section .data - -kInstallTitle: db "ZKA Installer", 0 - -section .text - -;; @param r8 arg 1 -;; @param r9 arg 2 -;; @return rax, return status of syscall. -;; @note MS-ABI procedure. -InstInstallToDir: - mov r8, rcx ; FILE_INFO_STRUCT (SRC) - mov r9, rdx ; FILE_INFO_STRUCT (DST) - syscall ;; 0 = GOOD, 1 = BAD FIS (SRC), 2 = BAD FIS (DST) - ret - - - diff --git a/dev/INST/X64/InstallerRoutines.asm b/dev/INST/X64/InstallerRoutines.asm new file mode 100644 index 00000000..61c712d0 --- /dev/null +++ b/dev/INST/X64/InstallerRoutines.asm @@ -0,0 +1,34 @@ +;; /* +;; * --------------------------------------------------- +;; * +;; * Copyright ZKA Technologies., all rights reserved. +;; * +;; * File: Install.asm +;; * Purpose: ZKA installer program, runs at ring-0. +;; * +;; * --------------------------------------------------- +;; */ + +[bits 64] + +[global kInstallTitle] +[global InstInstallToDir] + +section .data + +kInstallTitle: db "ZKA Installer", 0 + +section .text + +;; @param r8 arg 1 +;; @param r9 arg 2 +;; @return rax, return status of syscall. +;; @note MS-ABI procedure. +InstInstallToDir: + mov r8, rcx ; FILE_INFO_STRUCT (SRC) + mov r9, rdx ; FILE_INFO_STRUCT (DST) + syscall ;; 0 = GOOD, 1 = BAD FIS (SRC), 2 = BAD FIS (DST) + ret + + + diff --git a/dev/SCI/sci_base.hxx b/dev/SCI/sci_base.hxx index 7f7565de..9b2998ca 100644 --- a/dev/SCI/sci_base.hxx +++ b/dev/SCI/sci_base.hxx @@ -227,7 +227,7 @@ IMPORT_C UInt0 ThrExitJoinThread(UInt0); IMPORT_C UInt0 ThrExitDetachThread(UInt0); // ------------------------------------------------------------------------ -// Disk Management API. +// Drive Management API. // ------------------------------------------------------------------------ #endif // ifndef __SCI_BASE_HXX__ diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx index 0ddd6d30..590e50f4 100644 --- a/dev/ZBA/BootKit/BootKit.hxx +++ b/dev/ZBA/BootKit/BootKit.hxx @@ -185,7 +185,7 @@ static inline const UInt32 kRgbWhite = 0x00FFFFFF; #define kBKBootFileMime "boot-x/file" #define kBKBootDirMime "boot-x/dir" -/// @brief BootKit Disk Formatter. +/// @brief BootKit Drive Formatter. template class BDiskFormatFactory final { @@ -236,7 +236,7 @@ public: return false; } - writer.Write(L"NEWOSLDR: Disk is ").Write(GIB(this->fDiskDev.GetDiskSize())).Write(L" GB.\r"); + writer.Write(L"NEWOSLDR: Drive is ").Write(GIB(this->fDiskDev.GetDiskSize())).Write(L" GB.\r"); if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() || blockPart->DiskSize < 1 || @@ -322,7 +322,7 @@ inline Boolean BDiskFormatFactory::Format(const Char* partName, if (GIB(fDiskDev.GetDiskSize()) < cMinimumDiskSize) { - EFI::ThrowError(L"Disk-Too-Tiny", L"Can't format a New Filesystem partition here."); + EFI::ThrowError(L"Drive-Too-Tiny", L"Can't format a New Filesystem partition here."); return false; } @@ -372,7 +372,7 @@ inline Boolean BDiskFormatFactory::Format(const Char* partName, if (this->WriteRootCatalog(fileBlobs, blobCount, partBlock)) { BTextWriter writer; - writer.Write(L"NEWOSLDR: Disk formatted.\r"); + writer.Write(L"NEWOSLDR: Drive formatted.\r"); return true; } 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 -/* 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 #include +#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(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(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(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), -- cgit v1.2.3