From 4a9b18d4fc40aae00dc8c658ecf28bee73c4643a Mon Sep 17 00:00:00 2001 From: Amlal Date: Wed, 2 Oct 2024 09:07:16 +0200 Subject: IMP: Updated Kernel with refactors and fixes. - Fix HalPagingMgr.cxx, use a ZKA_PDE* struct before accessing PTE. - Refactor Kernel files and refactor ATA driver. Signed-off-by: Amlal --- dev/zka/HALKit/AMD64/HalPagingMgr.cxx | 4 +- dev/zka/HALKit/AMD64/PCI/DMA.cxx | 82 ++++++++++++++++++++++++++++++++ dev/zka/HALKit/AMD64/PCI/Dma.cxx | 82 -------------------------------- dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx | 6 +-- dev/zka/KernelKit/PCI/DMA.hxx | 81 +++++++++++++++++++++++++++++++ dev/zka/KernelKit/PCI/DMA.inl | 20 ++++++++ dev/zka/KernelKit/PCI/Dma.hxx | 81 ------------------------------- dev/zka/KernelKit/PCI/Dma.inl | 20 -------- dev/zka/StorageKit/PRDT.hxx | 2 +- 9 files changed, 188 insertions(+), 190 deletions(-) create mode 100644 dev/zka/HALKit/AMD64/PCI/DMA.cxx delete mode 100644 dev/zka/HALKit/AMD64/PCI/Dma.cxx create mode 100644 dev/zka/KernelKit/PCI/DMA.hxx create mode 100644 dev/zka/KernelKit/PCI/DMA.inl delete mode 100644 dev/zka/KernelKit/PCI/Dma.hxx delete mode 100644 dev/zka/KernelKit/PCI/Dma.inl (limited to 'dev') diff --git a/dev/zka/HALKit/AMD64/HalPagingMgr.cxx b/dev/zka/HALKit/AMD64/HalPagingMgr.cxx index db27aaf5..06a8b7d2 100644 --- a/dev/zka/HALKit/AMD64/HalPagingMgr.cxx +++ b/dev/zka/HALKit/AMD64/HalPagingMgr.cxx @@ -114,9 +114,9 @@ namespace Kernel::HAL UInt64 pt_entry = (pt_base + pt_index * cPmlEntrySize); // Lastly, grab the pte entry. - ZKA_PTE* pte_struct = reinterpret_cast(pt_entry); + ZKA_PDE* pte_struct = reinterpret_cast(pt_base); - return mmi_map_page_table_entry(virtual_address, flags, pte_struct); + return mmi_map_page_table_entry(virtual_address, flags, pte_struct->fEntries[pt_entry]); } /// @brief Maps flags for a specific pte. diff --git a/dev/zka/HALKit/AMD64/PCI/DMA.cxx b/dev/zka/HALKit/AMD64/PCI/DMA.cxx new file mode 100644 index 00000000..d40e0e6d --- /dev/null +++ b/dev/zka/HALKit/AMD64/PCI/DMA.cxx @@ -0,0 +1,82 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include + +namespace Kernel +{ + DMAWrapper::operator bool() + { + return fAddress; + } + + bool DMAWrapper::operator!() + { + return !fAddress; + } + + Boolean DMAWrapper::Check(UIntPtr offset) const + { + if (!fAddress) + return false; + if (offset == 0) + return true; + + kcout << "[DMAWrapper::IsIn] Checking offset..\n"; + return reinterpret_cast(fAddress) >= offset; + } + + bool DMAWrapper::Write(const UIntPtr& bit, const UIntPtr& offset) + { + if (!fAddress) + return false; + + kcout << "[DMAWrapper::Write] Writing at address..\n"; + + auto addr = + (volatile UIntPtr*)(reinterpret_cast(fAddress) + offset); + *addr = bit; + + return true; + } + + UIntPtr DMAWrapper::Read(const UIntPtr& offset) + { + kcout << "[DMAWrapper::Read] checking fAddress..\n"; + if (!fAddress) + return 0; + + kcout << "[DMAWrapper::Read] Reading fAddress..\n"; + return *(volatile UIntPtr*)(reinterpret_cast(fAddress) + offset); + ; + } + + UIntPtr DMAWrapper::operator[](const UIntPtr& offset) + { + return this->Read(offset); + } + + OwnPtr> DMAFactory::Construct(OwnPtr& dma) + { + if (!dma) + return {}; + + OwnPtr> dmaOwnPtr = + make_ptr, char*>(reinterpret_cast(dma->fAddress)); + + if (!dmaOwnPtr) + return {}; + + kcout << "Returning the new OwnPtr>!\r"; + return dmaOwnPtr; + } + + DMAWrapper& DMAWrapper::operator=(voidPtr Ptr) + { + fAddress = Ptr; + return *this; + } +} // namespace Kernel diff --git a/dev/zka/HALKit/AMD64/PCI/Dma.cxx b/dev/zka/HALKit/AMD64/PCI/Dma.cxx deleted file mode 100644 index bf1730d8..00000000 --- a/dev/zka/HALKit/AMD64/PCI/Dma.cxx +++ /dev/null @@ -1,82 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include - -namespace Kernel -{ - DMAWrapper::operator bool() - { - return fAddress; - } - - bool DMAWrapper::operator!() - { - return !fAddress; - } - - Boolean DMAWrapper::Check(UIntPtr offset) const - { - if (!fAddress) - return false; - if (offset == 0) - return true; - - kcout << "[DMAWrapper::IsIn] Checking offset..\n"; - return reinterpret_cast(fAddress) >= offset; - } - - bool DMAWrapper::Write(const UIntPtr& bit, const UIntPtr& offset) - { - if (!fAddress) - return false; - - kcout << "[DMAWrapper::Write] Writing at address..\n"; - - auto addr = - (volatile UIntPtr*)(reinterpret_cast(fAddress) + offset); - *addr = bit; - - return true; - } - - UIntPtr DMAWrapper::Read(const UIntPtr& offset) - { - kcout << "[DMAWrapper::Read] checking fAddress..\n"; - if (!fAddress) - return 0; - - kcout << "[DMAWrapper::Read] Reading fAddress..\n"; - return *(volatile UIntPtr*)(reinterpret_cast(fAddress) + offset); - ; - } - - UIntPtr DMAWrapper::operator[](const UIntPtr& offset) - { - return this->Read(offset); - } - - OwnPtr> DMAFactory::Construct(OwnPtr& dma) - { - if (!dma) - return {}; - - OwnPtr> dmaOwnPtr = - make_ptr, char*>(reinterpret_cast(dma->fAddress)); - - if (!dmaOwnPtr) - return {}; - - kcout << "Returning the new OwnPtr>!\r"; - return dmaOwnPtr; - } - - DMAWrapper& DMAWrapper::operator=(voidPtr Ptr) - { - fAddress = Ptr; - return *this; - } -} // namespace Kernel diff --git a/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx b/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx index e09a4277..2d02d89a 100644 --- a/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/dev/zka/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -68,8 +68,6 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) drv_std_select(IO); - kcout << "Initializing drive...\r"; - ATAInit_Retry: // Bus init, NEIN bit. Out8(IO + ATA_REG_NEIN, 1); @@ -80,7 +78,7 @@ ATAInit_Retry: if (statRdy & ATA_SR_ERR) { - kcout << "Failing drive...\r"; + kcout << "ERROR: ATA DRIVE RETURNED ERROR BIT! ABORTING...\r"; return false; } @@ -107,7 +105,7 @@ ATAInit_Retry: OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - kcout << "Created IDE module.\r"; + kcout << "INFO: INITIALIZED ATA DRIVE!\r"; return true; } diff --git a/dev/zka/KernelKit/PCI/DMA.hxx b/dev/zka/KernelKit/PCI/DMA.hxx new file mode 100644 index 00000000..6aa06d1e --- /dev/null +++ b/dev/zka/KernelKit/PCI/DMA.hxx @@ -0,0 +1,81 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Kernel +{ + enum class DmaKind + { + PCI, // Bus mastering is required to be turned on. Basiaclly a request + // control system. 64-Bit access depends on the PAE bit and the device + // (if Double Address Cycle is available) + ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM. + Invalid, + }; + + class DMAWrapper final + { + public: + explicit DMAWrapper() = delete; + + public: + explicit DMAWrapper(nullPtr) = delete; + explicit DMAWrapper(voidPtr Ptr, DmaKind Kind = DmaKind::PCI) + : fAddress(Ptr), fKind(Kind) + { + } + + public: + DMAWrapper& operator=(voidPtr Ptr); + + public: + DMAWrapper& operator=(const DMAWrapper&) = default; + DMAWrapper(const DMAWrapper&) = default; + + public: + ~DMAWrapper() = default; + + template + T* operator->(); + + template + T* Get(const UIntPtr off = 0); + + public: + operator bool(); + bool operator!(); + + public: + bool Write(const UIntPtr& bit, const UIntPtr& offset); + UIntPtr Read(const UIntPtr& offset); + Boolean Check(UIntPtr offset) const; + + public: + UIntPtr operator[](const UIntPtr& offset); + + private: + voidPtr fAddress{nullptr}; + DmaKind fKind{DmaKind::Invalid}; + + private: + friend class DMAFactory; + }; + + class DMAFactory final + { + public: + static OwnPtr> Construct(OwnPtr& dma); + }; +} // namespace Kernel + +#include diff --git a/dev/zka/KernelKit/PCI/DMA.inl b/dev/zka/KernelKit/PCI/DMA.inl new file mode 100644 index 00000000..1c164af8 --- /dev/null +++ b/dev/zka/KernelKit/PCI/DMA.inl @@ -0,0 +1,20 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +namespace Kernel +{ + template + T* DMAWrapper::operator->() + { + return fAddress; + } + + template + T* DMAWrapper::Get(const UIntPtr offset) + { + return reinterpret_cast((UIntPtr)fAddress + offset); + } +} // namespace Kernel diff --git a/dev/zka/KernelKit/PCI/Dma.hxx b/dev/zka/KernelKit/PCI/Dma.hxx deleted file mode 100644 index b265f738..00000000 --- a/dev/zka/KernelKit/PCI/Dma.hxx +++ /dev/null @@ -1,81 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace Kernel -{ - enum class DmaKind - { - PCI, // Bus mastering is required to be turned on. Basiaclly a request - // control system. 64-Bit access depends on the PAE bit and the device - // (if Double Address Cycle is available) - ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM. - Invalid, - }; - - class DMAWrapper final - { - public: - explicit DMAWrapper() = delete; - - public: - explicit DMAWrapper(nullPtr) = delete; - explicit DMAWrapper(voidPtr Ptr, DmaKind Kind = DmaKind::PCI) - : fAddress(Ptr), fKind(Kind) - { - } - - public: - DMAWrapper& operator=(voidPtr Ptr); - - public: - DMAWrapper& operator=(const DMAWrapper&) = default; - DMAWrapper(const DMAWrapper&) = default; - - public: - ~DMAWrapper() = default; - - template - T* operator->(); - - template - T* Get(const UIntPtr off = 0); - - public: - operator bool(); - bool operator!(); - - public: - bool Write(const UIntPtr& bit, const UIntPtr& offset); - UIntPtr Read(const UIntPtr& offset); - Boolean Check(UIntPtr offset) const; - - public: - UIntPtr operator[](const UIntPtr& offset); - - private: - voidPtr fAddress{nullptr}; - DmaKind fKind{DmaKind::Invalid}; - - private: - friend class DMAFactory; - }; - - class DMAFactory final - { - public: - static OwnPtr> Construct(OwnPtr& dma); - }; -} // namespace Kernel - -#include diff --git a/dev/zka/KernelKit/PCI/Dma.inl b/dev/zka/KernelKit/PCI/Dma.inl deleted file mode 100644 index 1c164af8..00000000 --- a/dev/zka/KernelKit/PCI/Dma.inl +++ /dev/null @@ -1,20 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -namespace Kernel -{ - template - T* DMAWrapper::operator->() - { - return fAddress; - } - - template - T* DMAWrapper::Get(const UIntPtr offset) - { - return reinterpret_cast((UIntPtr)fAddress + offset); - } -} // namespace Kernel diff --git a/dev/zka/StorageKit/PRDT.hxx b/dev/zka/StorageKit/PRDT.hxx index 6dec22c2..324a3f63 100644 --- a/dev/zka/StorageKit/PRDT.hxx +++ b/dev/zka/StorageKit/PRDT.hxx @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include -- cgit v1.2.3