From f511ab3c1e840e1568dec67c4988f42e67d527b7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 11 Feb 2025 08:51:02 +0100 Subject: ADD: LibCF --- dev/Kernel/CFKit/Property.h | 6 +- dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc | 1 - dev/Kernel/HALKit/AMD64/Storage/SATA.cc | 33 ++++--- dev/Kernel/NewKit/Array.h | 7 ++ dev/Kernel/NewKit/ArrayList.h | 13 ++- dev/LibSCI/GPU.h | 13 ++- dev/LibSCI/Macros.h | 15 +++ dev/Mod/AHCI/AHCI.h | 6 +- dev/Usr/LibCF/Array.h | 63 ++++++++++++ dev/Usr/LibCF/Property.h | 53 +++++++++++ dev/Usr/LibCF/Ref.h | 106 +++++++++++++++++++++ dev/Usr/LibCompress/API.h | 18 ---- dev/Usr/LibCompress/LCCompress.s | 7 -- dev/Usr/LibCompress/LCDecompress.s | 7 -- dev/Usr/LibSystem/.keepme | 0 dev/Usr/LibWS/.keepme | 0 16 files changed, 281 insertions(+), 67 deletions(-) create mode 100644 dev/Usr/LibCF/Array.h create mode 100644 dev/Usr/LibCF/Property.h create mode 100644 dev/Usr/LibCF/Ref.h delete mode 100644 dev/Usr/LibCompress/API.h delete mode 100644 dev/Usr/LibCompress/LCCompress.s delete mode 100644 dev/Usr/LibCompress/LCDecompress.s delete mode 100644 dev/Usr/LibSystem/.keepme delete mode 100644 dev/Usr/LibWS/.keepme (limited to 'dev') diff --git a/dev/Kernel/CFKit/Property.h b/dev/Kernel/CFKit/Property.h index 54e028ed..b43434f6 100644 --- a/dev/Kernel/CFKit/Property.h +++ b/dev/Kernel/CFKit/Property.h @@ -13,7 +13,7 @@ #include #include -#define kMaxPropLen (255U) +#define kMaxPropLen (256U) namespace CFKit { @@ -23,7 +23,7 @@ namespace CFKit using PropertyId = UIntPtr; /// @brief Kernel property class. - /// @example /Properties/SmpCoreClass or /Properties/KernelVersionClass + /// @example /prop/smp_max or /prop/kern_ver class Property { public: @@ -34,7 +34,7 @@ namespace CFKit Property& operator=(const Property&) = default; Property(const Property&) = default; - bool StringEquals(KString& name); + BOOL StringEquals(KString& name); PropertyId& GetValue(); KString& GetKey(); diff --git a/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc index fc25b3d8..627f3fcb 100644 --- a/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/Kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -4,7 +4,6 @@ ------------------------------------------- */ -#include "NewKit/Macros.h" #include #include #include diff --git a/dev/Kernel/HALKit/AMD64/Storage/SATA.cc b/dev/Kernel/HALKit/AMD64/Storage/SATA.cc index 1435cfac..56afa303 100644 --- a/dev/Kernel/HALKit/AMD64/Storage/SATA.cc +++ b/dev/Kernel/HALKit/AMD64/Storage/SATA.cc @@ -15,7 +15,6 @@ * */ -#include "NewKit/Macros.h" #include #include @@ -33,12 +32,12 @@ #define kHBAPxCmdFR 0x4000 #define kHBAPxCmdCR 0x8000 -#define kSataLBAMode (1 << 6) +#define kSATALBAMode (1 << 6) -#define kAhciSRBsy (0x80) -#define kAhciSRDrq (0x08) +#define kSATASRBsy (0x80) +#define kSATASRDrq (0x08) -#define kAhciPortCnt (0x20) +#define kSATAPortCnt (0x20) #define kSATAProgIfAHCI (0x01) #define kSATASubClass (0x06) @@ -50,7 +49,7 @@ STATIC Kernel::SizeT kSATAPortIdx = 0UL; STATIC Kernel::Lba kCurrentDiskSectorCount = 0UL; template -static Kernel::Void drv_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer) noexcept; +static Kernel::Void drvi_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer) noexcept; static Kernel::Int32 drvi_find_cmd_slot(HbaPort* port) noexcept; @@ -62,7 +61,7 @@ static Kernel::Void drvi_calculate_disk_geometry() noexcept Kernel::UInt8 identify_data[kib_cast(4)] = {}; - drv_std_input_output(0, identify_data, 0, kib_cast(4)); + drvi_std_input_output(0, identify_data, 0, kib_cast(4)); kCurrentDiskSectorCount = (identify_data[61] << 16) | identify_data[60]; @@ -95,10 +94,10 @@ Kernel::Boolean drv_std_init(Kernel::UInt16& PortsImplemented) Kernel::UInt32 ports_implemented = mem_ahci->Pi; Kernel::UInt16 ahci_index = 0; - const Kernel::UInt16 kMaxPortsImplemented = kAhciPortCnt; + const Kernel::UInt16 kMaxPortsImplemented = kSATAPortCnt; const Kernel::UInt32 kSATASignature = 0x00000101; - const Kernel::UInt8 kAhciPresent = 0x03; - const Kernel::UInt8 kAhciIPMActive = 0x01; + const Kernel::UInt8 kSATAPresent = 0x03; + const Kernel::UInt8 kSATAIPMActive = 0x01; while (ahci_index < kMaxPortsImplemented) { @@ -163,19 +162,19 @@ Kernel::Boolean drv_std_detected(Kernel::Void) Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer) { - drv_std_input_output(lba, (Kernel::UInt8*)buffer, sector_sz, size_buffer); + drvi_std_input_output(lba, (Kernel::UInt8*)buffer, sector_sz, size_buffer); } Kernel::Void drv_std_read(Kernel::UInt64 lba, Kernel::Char* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer) { - drv_std_input_output(lba, (Kernel::UInt8*)buffer, sector_sz, size_buffer); + drvi_std_input_output(lba, (Kernel::UInt8*)buffer, sector_sz, size_buffer); } static Kernel::Int32 drvi_find_cmd_slot(HbaPort* port) noexcept { Kernel::UInt32 slots = port->Ci; - for (Kernel::Int32 i = 0; i < (kAhciPortCnt); i++) + for (Kernel::Int32 i = 0; i < (kSATAPortCnt); i++) { if ((slots & 1) == 0) return i; @@ -187,7 +186,7 @@ static Kernel::Int32 drvi_find_cmd_slot(HbaPort* port) noexcept } template -static Kernel::Void drv_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer) noexcept +static Kernel::Void drvi_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buffer, Kernel::SizeT sector_sz, Kernel::SizeT size_buffer) noexcept { auto slot = 0L; @@ -237,14 +236,14 @@ static Kernel::Void drv_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buff h2d_fis->Lba4 = (lba >> 32) & 0xFF; h2d_fis->Lba5 = (lba >> 40) & 0xFF; - h2d_fis->Device = kSataLBAMode; + h2d_fis->Device = kSATALBAMode; // 28-bit LBA mode, fis is done being configured. h2d_fis->CountLow = sector_sz & 0xFF; h2d_fis->CountHigh = (sector_sz >> 8) & 0xFF; - while ((kSATAPort->Ports[kSATAPortIdx].Tfd & (kAhciSRBsy | kAhciSRDrq))) + while ((kSATAPort->Ports[kSATAPortIdx].Tfd & (kSATASRBsy | kSATASRDrq))) { kout << "Waiting for the TFD to be ready...\r"; } @@ -267,7 +266,7 @@ static Kernel::Void drv_std_input_output(Kernel::UInt64 lba, Kernel::UInt8* buff kout << "TFD: " << Kernel::hex_number(kSATAPort->Ports[kSATAPortIdx].Tfd) << endl; } - while ((kSATAPort->Ports[kSATAPortIdx].Tfd & (kAhciSRBsy | kAhciSRDrq))) + while ((kSATAPort->Ports[kSATAPortIdx].Tfd & (kSATASRBsy | kSATASRDrq))) { kout << "Waiting for the TFD to be ready...\r"; } diff --git a/dev/Kernel/NewKit/Array.h b/dev/Kernel/NewKit/Array.h index f44caae3..aab3ba91 100644 --- a/dev/Kernel/NewKit/Array.h +++ b/dev/Kernel/NewKit/Array.h @@ -24,6 +24,7 @@ namespace Kernel T& operator[](const SizeT& at) { + MUST_PASS(at < this->Count()); return fArray[at]; } @@ -55,4 +56,10 @@ namespace Kernel private: T fArray[N]; }; + + template + auto make_list(ValueType val) + { + return Array{val}; + } } // namespace Kernel diff --git a/dev/Kernel/NewKit/ArrayList.h b/dev/Kernel/NewKit/ArrayList.h index 88d67daa..6d799ad5 100644 --- a/dev/Kernel/NewKit/ArrayList.h +++ b/dev/Kernel/NewKit/ArrayList.h @@ -14,7 +14,7 @@ namespace Kernel class ArrayList final { public: - explicit ArrayList(T* list) + explicit ArrayList(T* list, SizeT length) : fList(reinterpret_cast(list)) { } @@ -36,6 +36,7 @@ namespace Kernel T& operator[](int index) const { + MUST_PASS(index < this->Count()); return fList[index]; } @@ -44,10 +45,14 @@ namespace Kernel return fList; } - private: - T* fList; + SizeT Count() + { + return fLen; + } - friend class InitHelpers; + private: + T* fList{nullptr}; + SizeT fLen{0}; }; template diff --git a/dev/LibSCI/GPU.h b/dev/LibSCI/GPU.h index 892a85ff..6ee937f5 100644 --- a/dev/LibSCI/GPU.h +++ b/dev/LibSCI/GPU.h @@ -23,21 +23,20 @@ struct GPUCmdBuffer; /// ------------------------------------------------------------------------------------------ // struct GPUCmdBuffer final { - SizeT X, Y, Z; - VoidPtr FrameData; - SizeT FrameDataSz; - SizeT BackBufferLayer; + VoidPtr Data; + SizeT DataSz; + SizeT BufferLayer; Bool IsGPGPUData; - Bool BackBufferFirst; + Bool BufferFirst; Bool isGPGPUData() { - return !this->BackBufferFirst && this->IsGPGPUData; + return !this->BufferFirst && this->IsGPGPUData; } Bool isValid() { - return this->FrameData && this->FrameDataSz > 0; + return this->Data && (this->DataSz > 0) && (MmGetHeapFlags(this->Data) != -1); } }; diff --git a/dev/LibSCI/Macros.h b/dev/LibSCI/Macros.h index 5f4253de..62d522c9 100644 --- a/dev/LibSCI/Macros.h +++ b/dev/LibSCI/Macros.h @@ -54,3 +54,18 @@ typedef IOObject FSObject; typedef SCIObject DLLObject; typedef SCIObject ThreadObject; typedef SCIObject SocketObject; + +#ifdef __cplusplus +typedef decltype(nullptr) nullPtr; +typedef decltype(nullptr) NullPtr; +#endif + +EXTERN_C void _rtl_assert(Bool expr, const Char* origin); + +#define MUST_PASS(X) _rtl_assert(X, __FILE__) + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) \ + (((sizeof(a) / sizeof(*(a))) / \ + (static_cast(!(sizeof(a) % sizeof(*(a))))))) +#endif \ No newline at end of file diff --git a/dev/Mod/AHCI/AHCI.h b/dev/Mod/AHCI/AHCI.h index 8e457431..74b08e38 100644 --- a/dev/Mod/AHCI/AHCI.h +++ b/dev/Mod/AHCI/AHCI.h @@ -222,9 +222,9 @@ typedef struct FisDevBits final } FisDevBits; /// \brief Enable AHCI device bit in GHC register. -#ifndef kAhciGHC_AE -#define kAhciGHC_AE (31) -#endif //! ifndef kAhciGHC_AE +#ifndef kSATAGHC_AE +#define kSATAGHC_AE (31) +#endif //! ifndef kSATAGHC_AE typedef struct HbaPort final { diff --git a/dev/Usr/LibCF/Array.h b/dev/Usr/LibCF/Array.h new file mode 100644 index 00000000..8533b649 --- /dev/null +++ b/dev/Usr/LibCF/Array.h @@ -0,0 +1,63 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include + +namespace LibCF +{ + template + class CFArray final + { + public: + explicit CFArray() = default; + ~CFArray() = default; + + CFArray& operator=(const CFArray&) = default; + CFArray(const CFArray&) = default; + + T& operator[](const SizeT& at) + { + MUST_PASS(at < this->Count()); + return fArray[at]; + } + + Bool Empty() + { + return this->Count() > 0; + } + + const SizeT Capacity() + { + return N; + } + + const SizeT Count() + { + return N; + } + + const T* CData() + { + return fArray; + } + + operator bool() + { + return !Empty(); + } + + private: + T fArray[N]; + }; + + template + auto make_list(ValueType val) + { + return CFArray{val}; + } +} // namespace Kernel diff --git a/dev/Usr/LibCF/Property.h b/dev/Usr/LibCF/Property.h new file mode 100644 index 00000000..629dba27 --- /dev/null +++ b/dev/Usr/LibCF/Property.h @@ -0,0 +1,53 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef CFKIT_PROPS_H +#define CFKIT_PROPS_H + +#include +#include + +#define kMaxPropLen (256U) + +namespace LibCF +{ + class CFString; + class CFProperty; + class CFGUID; + + template + class CFArray; + + /// @brief handle to anything (number, ptr, string...) + using CFPropertyId = UIntPtr; + + /// @brief User property class. + /// @example /prop/foo or /prop/bar + class CFProperty + { + public: + CFProperty(); + virtual ~CFProperty(); + + public: + CFProperty& operator=(const CFProperty&) = default; + CFProperty(const CFProperty&) = default; + + Bool StringEquals(CFString& name); + CFPropertyId& GetValue(); + CFString& GetKey(); + + private: + CFString* fName{nullptr}; + CFPropertyId fValue{0UL}; + Ref fGUID{}; + }; + + template + using CFPropertyArray = CFArray; +} // namespace CFKit + +#endif // !CFKIT_PROPS_H diff --git a/dev/Usr/LibCF/Ref.h b/dev/Usr/LibCF/Ref.h new file mode 100644 index 00000000..faad67c5 --- /dev/null +++ b/dev/Usr/LibCF/Ref.h @@ -0,0 +1,106 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef _NEWKIT_REF_H_ +#define _NEWKIT_REF_H_ + +#include + +namespace LibCF +{ + template + class Ref final + { + public: + Ref() = default; + + ~Ref() + { + if (MmGetHeapFlags(fClass) != -1) + delete fClass; + } + + public: + Ref(T* cls) + : fClass(cls) + { + } + + Ref(T cls) + : fClass(&cls) + { + } + + Ref& operator=(T ref) + { + if (!fClass) + return *this; + + fClass = &ref; + return *this; + } + + public: + T operator->() const + { + MUST_PASS(*fClass); + return *fClass; + } + + T& Leak() noexcept + { + return *fClass; + } + + T& TryLeak() const noexcept + { + MUST_PASS(*fClass); + return *fClass; + } + + T operator*() + { + return *fClass; + } + + operator bool() noexcept + { + return fClass; + } + + private: + T* fClass{nullptr}; + }; + + template + class NonNullRef final + { + public: + NonNullRef() = delete; + NonNullRef(nullPtr) = delete; + + NonNullRef(T* ref) + : fRef(ref) + { + MUST_PASS(ref); + } + + Ref& operator->() + { + MUST_PASS(fRef); + return fRef; + } + + NonNullRef& operator=(const NonNullRef& ref) = delete; + NonNullRef(const NonNullRef& ref) = default; + + private: + Ref fRef{nullptr}; + }; +} // namespace Kernel + +#endif // ifndef _NEWKIT_REF_H_ diff --git a/dev/Usr/LibCompress/API.h b/dev/Usr/LibCompress/API.h deleted file mode 100644 index 9c3e9fde..00000000 --- a/dev/Usr/LibCompress/API.h +++ /dev/null @@ -1,18 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -#ifndef COMPRESSKIT_RLE_H -#define COMPRESSKIT_RLE_H - -#include -// #include - -namespace Kernel -{ - class ICompressProxy; -} // namespace Kernel - -#endif // !ifndef COMPRESSKIT_RLE_H diff --git a/dev/Usr/LibCompress/LCCompress.s b/dev/Usr/LibCompress/LCCompress.s deleted file mode 100644 index c490bbba..00000000 --- a/dev/Usr/LibCompress/LCCompress.s +++ /dev/null @@ -1,7 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -.text \ No newline at end of file diff --git a/dev/Usr/LibCompress/LCDecompress.s b/dev/Usr/LibCompress/LCDecompress.s deleted file mode 100644 index c490bbba..00000000 --- a/dev/Usr/LibCompress/LCDecompress.s +++ /dev/null @@ -1,7 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024 Amlal EL Mahrouss, all rights reserved. - -------------------------------------------- */ - -.text \ No newline at end of file diff --git a/dev/Usr/LibSystem/.keepme b/dev/Usr/LibSystem/.keepme deleted file mode 100644 index e69de29b..00000000 diff --git a/dev/Usr/LibWS/.keepme b/dev/Usr/LibWS/.keepme deleted file mode 100644 index e69de29b..00000000 -- cgit v1.2.3