From 5339d016c07bf717ee388f4feb73544087324af0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 6 Jan 2024 09:14:11 +0100 Subject: git: port from mercurial repo. Signed-off-by: Amlal El Mahrouss --- StorageKit/ATA.hpp | 104 +++++++++++++++++++++++++++++++++++++++++++++ StorageKit/NVME.hpp | 48 +++++++++++++++++++++ StorageKit/PRDT.hpp | 54 +++++++++++++++++++++++ StorageKit/Storage.hpp | 28 ++++++++++++ StorageKit/StorageCore.inl | 56 ++++++++++++++++++++++++ 5 files changed, 290 insertions(+) create mode 100644 StorageKit/ATA.hpp create mode 100644 StorageKit/NVME.hpp create mode 100644 StorageKit/PRDT.hpp create mode 100644 StorageKit/Storage.hpp create mode 100644 StorageKit/StorageCore.inl (limited to 'StorageKit') diff --git a/StorageKit/ATA.hpp b/StorageKit/ATA.hpp new file mode 100644 index 00000000..0531e933 --- /dev/null +++ b/StorageKit/ATA.hpp @@ -0,0 +1,104 @@ +/* +* ======================================================== +* +* hCore +* Copyright Mahrouss Logic, all rights reserved. +* +* ======================================================== +*/ + +#pragma once + +#include +#include +#include +#include +#include + +namespace hCore +{ + enum class PATAType + { + kRead28, + kRead48, + kWrite28, + kWrite48, + kUnknown + }; + + const char* ata_read_28(ULong lba); + const char* ata_read_48(ULong lba); + + Int32 ata_write_48(ULong lba, const char *text = nullptr); + Int32 ata_write_28(ULong lba, const char *text = nullptr); + + class PATACommandManager final + { + public: + PATACommandManager() = default; + ~PATACommandManager() = default; + + PATACommandManager &operator=(const PATACommandManager &) = default; + PATACommandManager(const PATACommandManager &) = default; + + public: + static Ref Shared() + { + static Ref manager; + return manager; + } + + public: + template + ErrorOr operator()(ULong lba, const char *text = nullptr) noexcept + { + switch (Command) + { + case PATAType::kRead28: + return ErrorOr(ata_read_28(lba)); + case PATAType::kRead48: + return ErrorOr(ata_read_48(lba)); + case PATAType::kWrite28: + { + if (text) + { + ata_write_28(lba, text); + kcout << "ErrorOr ata_read: Write ATA Command... " + "(Write28)\n"; + + return {}; + } + + kcout << "ErrorOr ata_read: Bad ATA Command... " + "(Write28)\n"; + + return {}; + } + case PATAType::kWrite48: + { + if (text) + { + ata_write_48(lba, text); + kcout << "ErrorOr ata_read: Write ATA Command... " + "(Write48)\n"; + + return {}; + } + + kcout << "ErrorOr ata_read: Bad ATA Command... " + "(Write48)\n"; + + return {}; + } + case PATAType::kUnknown: + { + kcout << "ErrorOr ata_read: Unknown ATA Command...\n"; + return {}; + } + } + + return ErrorOr(nullptr); + } + + }; +} // namespace hCore diff --git a/StorageKit/NVME.hpp b/StorageKit/NVME.hpp new file mode 100644 index 00000000..1b8fa836 --- /dev/null +++ b/StorageKit/NVME.hpp @@ -0,0 +1,48 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include +#include + +namespace hCore +{ + class NVMEPacket; + + class NVMEDevice : public IDevice + { + public: + NVMEDevice(void(*Out)(NVMEPacket outpacket), + void(*In)(NVMEPacket inpacket), + void(*Cleanup)(void)) + : IDevice(Out, In), fCleanup(Cleanup) + {} + + virtual ~NVMEDevice() + { + if (fCleanup) + fCleanup(); + } + + public: + NVMEDevice &operator=(const NVMEDevice &) = default; + NVMEDevice(const NVMEDevice &) = default; + + virtual const char *Name() const; + + public: + OwnPtr operator()(UInt32 dmaLow, UInt32 dmaHigh, SizeT sz); + + private: + void(*fCleanup)(void); + + + }; +} // namespace hCore diff --git a/StorageKit/PRDT.hpp b/StorageKit/PRDT.hpp new file mode 100644 index 00000000..152bc6f1 --- /dev/null +++ b/StorageKit/PRDT.hpp @@ -0,0 +1,54 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ +#pragma once + +#include +#include + +#define PRDT_TRANSFER_SIZE (sizeof(hCore::UShort)) + +namespace hCore +{ + class PRDT final + { + public: + PRDT() = delete; + explicit PRDT(const UIntPtr &physAddr); + ~PRDT(); + + PRDT &operator=(const PRDT &) = default; + PRDT(const PRDT &) = default; + + public: + const UInt &Low(); + const UShort &High(); + const UIntPtr &PhysicalAddress(); + + public: + PRDT &operator=(const UIntPtr& prdtAddress); + + public: + operator bool() + { + return m_PrdtAddr != 0; + } + + private: + union + { + UInt m_Low; + UShort m_High; + }; + + UIntPtr m_PrdtAddr; + + }; + + using PhysicalAddress = PRDT; // here +} // namespace hCore diff --git a/StorageKit/Storage.hpp b/StorageKit/Storage.hpp new file mode 100644 index 00000000..420e67fd --- /dev/null +++ b/StorageKit/Storage.hpp @@ -0,0 +1,28 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include + +#include +#include + +#include + +typedef hCore::UInt16 OSScsiPacket[12]; + +extern const OSScsiPacket kCDRomPacketTemplate; + +#define f_kDriveSectorSize 2048 +#define f_kDriveSize(last_lba) (last_lba + 1) * f_kDriveSectorSize + + + + diff --git a/StorageKit/StorageCore.inl b/StorageKit/StorageCore.inl new file mode 100644 index 00000000..f0891880 --- /dev/null +++ b/StorageKit/StorageCore.inl @@ -0,0 +1,56 @@ +/* + * ======================================================== + * + * hCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#ifndef __STORAGEKIT_STORAGECORE_INL__ +#define __STORAGEKIT_STORAGECORE_INL__ + +#include + +// @brief Storage management unit. +// swap files, files, dirs optimization. + +namespace hCore +{ + typedef Char* SKStr; + + //! @brief Storage context, reads and write file according to the descriptor layout. + class StorageContext + { + public: + explicit StorageContext() = default; + ~StorageContext() = default; + + StorageContext& operator=(const StorageContext&) = default; + StorageContext(const StorageContext&) = default; + + public: + bool Write(VoidPtr fileDescriptor, SizeT sizeFileDescriptor); + + struct SDescriptor + { + VoidPtr fFilePtr; + SizeT fFilePtrSz; + }; + + SDescriptor Read(const SKStr name); + + }; + +#define kMaxPathSK 4096 + + struct StorageLayout final + { + Char fName[kMaxPathSK]; + VoidPtr fData; + SizeT fDataSz; + Int32 fType; + }; +} + +#endif /* ifndef __STORAGEKIT_STORAGECORE_INL__ */ -- cgit v1.2.3