From ec11d85709965521ba7151fa18d0f71ea9c2eae2 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 25 Mar 2025 20:07:48 +0100 Subject: cli(diutil): moved CommandLine.cc to src/ ahci(generic): set err_global_get() when probing or command fails, use HbaMemRef when refering to HbaMem* Signed-off-by: Amlal El Mahrouss --- ReadMe.md | 4 +- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 34 +++++++++---- dev/modules/AHCI/AHCI.h | 2 + public/tools/diutil/CommandLine.cc | 68 ------------------------- public/tools/diutil/dist/.keep | 0 public/tools/diutil/diutil.json | 8 +-- public/tools/diutil/src/CommandLine.cc | 68 +++++++++++++++++++++++++ 7 files changed, 101 insertions(+), 83 deletions(-) delete mode 100644 public/tools/diutil/CommandLine.cc delete mode 100644 public/tools/diutil/dist/.keep create mode 100644 public/tools/diutil/src/CommandLine.cc diff --git a/ReadMe.md b/ReadMe.md index ee92d9ca..486bc8df 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -3,6 +3,8 @@ # NeKernel Use the doxygen command to build documentation. +
+A documentation regarding building, and developing for NeKernel will also be available soon. ## Requirements: @@ -23,7 +25,7 @@ Clone the repository: ```sh git clone git@github.com:amlel-el-mahrouss/nekernel.git -cd kernel +cd nekernel ./setup_amd64.sh ./debug_ata.sh # Generic ATA PIO target ``` diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index b1584c80..e3be5fb6 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -56,16 +56,16 @@ using namespace NeOS; STATIC PCI::Device kSATADev; -STATIC HbaMem* kSATAHba; -STATIC Lba kSATASectorCount = 0UL; -STATIC UInt16 kSATAIndex = 0U; -STATIC Char kCurrentDiskModel[50] = {"UNKNOWN AHCI DRIVE"}; -STATIC UInt16 kSATAPortsImplemented = 0U; +STATIC HbaMemRef kSATAHba; +STATIC Lba kSATASectorCount = 0UL; +STATIC UInt16 kSATAIndex = 0U; +STATIC Char kCurrentDiskModel[50] = {"UNKNOWN AHCI DRIVE"}; +STATIC UInt16 kSATAPortsImplemented = 0U; template STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz, SizeT size_buffer) noexcept; -STATIC Int32 drv_find_cmd_slot(HbaPort* port) noexcept; +STATIC Int32 drv_find_cmd_slot_ahci(HbaPort* port) noexcept; STATIC Void drv_compute_disk_ahci() noexcept; @@ -96,7 +96,7 @@ STATIC Void drv_compute_disk_ahci() noexcept /// @brief Finds a command slot for a HBA port. /// @param port The port to search on. /// @return The slot, or ~0. -STATIC Int32 drv_find_cmd_slot(HbaPort* port) noexcept +STATIC Int32 drv_find_cmd_slot_ahci(HbaPort* port) noexcept { UInt32 slots = (port->Sact | port->Ci); @@ -121,10 +121,14 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz { UIntPtr slot = 0UL; - slot = drv_find_cmd_slot(&kSATAHba->Ports[kSATAIndex]); + slot = drv_find_cmd_slot_ahci(&kSATAHba->Ports[kSATAIndex]); if (slot == ~0) + { + err_global_get() = kErrorDisk; + return; + } if (!Write) { @@ -297,7 +301,7 @@ STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) if (mem_ahci->Ports[ahci_index].Sig == kSATASignature) { - kout << "Detect: /dev/sat" << number(ahci_index) << kendl; + kout << "detect device: /dev/sat" << number(ahci_index) << kendl; kSATAIndex = ahci_index; kSATAHba = mem_ahci; @@ -308,7 +312,7 @@ STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) } else if (atapi && kSATAPISignature == mem_ahci->Ports[ahci_index].Sig) { - kout << "Detect: /dev/atp" << number(ahci_index) << kendl; + kout << "detect device: /dev/atp" << number(ahci_index) << kendl; kSATAIndex = ahci_index; kSATAHba = mem_ahci; @@ -326,6 +330,8 @@ STATIC Bool drv_std_init_ahci(UInt16& pi, BOOL& atapi) } } + err_global_get() = kErrorDisk; + return NO; } @@ -359,6 +365,8 @@ namespace NeOS { AHCIDeviceInterface* dev = (AHCIDeviceInterface*)self; + err_global_get() = kErrorDisk; + if (!dev) return; @@ -367,6 +375,8 @@ namespace NeOS if (!disk) return; + err_global_get() = kErrorSuccess; + drv_std_input_output_ahci(disk->fPacket.fPacketLba, (UInt8*)disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize); } @@ -377,6 +387,8 @@ namespace NeOS { AHCIDeviceInterface* dev = (AHCIDeviceInterface*)self; + err_global_get() = kErrorDisk; + if (!dev) return; @@ -385,6 +397,8 @@ namespace NeOS if (!disk) return; + err_global_get() = kErrorSuccess; + drv_std_input_output_ahci(disk->fPacket.fPacketLba, (UInt8*)disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize); } } // namespace Detail diff --git a/dev/modules/AHCI/AHCI.h b/dev/modules/AHCI/AHCI.h index 2ff54be9..535045a3 100644 --- a/dev/modules/AHCI/AHCI.h +++ b/dev/modules/AHCI/AHCI.h @@ -268,6 +268,8 @@ typedef struct HbaMem final HbaPort Ports[1]; // 1 ~ 32, 32 is the max ahci devices per controller. } HbaMem; +typedef HbaMem* HbaMemRef; + typedef struct HbaCmdHeader final { // DW0 diff --git a/public/tools/diutil/CommandLine.cc b/public/tools/diutil/CommandLine.cc deleted file mode 100644 index c0388611..00000000 --- a/public/tools/diutil/CommandLine.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal EL Mahrouss, all rights reserved. - - FILE: CommandLine.cc - PURPOSE: DIUTIL CLI. - - ------------------------------------------- */ - -#include - -static const Char kDiskName[kDIDiskNameLen] = "Disk"; -static SInt32 kDiskSectorSz = 512; -static const SInt32 kDiskBlockCnt = 1; -static SizeT kDiskSz = gib_cast(4); -static const Char kOutDisk[kDIOutNameLen] = "disk.eimg"; - -/// @brief Filesystem tool entrypoint. -int main(int argc, char** argv) -{ - for (SizeT arg = 0; arg < argc; ++arg) - { - const Char* arg_s = argv[arg]; - - if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-output-name", MmStrLen("--disk-output-name") == 0)) - { - if ((arg + 1) < argc) - { - MmCopyMemory((VoidPtr)kOutDisk, argv[arg + 1], kDIDiskNameLen); - } - } - else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-output-size", MmStrLen("--disk-output-size") == 0)) - { - if ((arg + 1) < argc) - { - kDiskSz = MathToNumber(argv[arg + 1], nullptr, 10); - } - } - else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-sector-size", MmStrLen("--disk-sector-size") == 0)) - { - if ((arg + 1) < argc) - { - kDiskSectorSz = MathToNumber(argv[arg + 1], nullptr, 10); - } - } - else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-part-name", MmStrLen("--disk-part-name") == 0)) - { - if ((arg + 1) < argc) - { - MmCopyMemory((VoidPtr)kDiskName, argv[arg + 1], kDIDiskNameLen); - } - } - } - - // create disk image. - - DI_DISK_IMAGE img{}; - - img.disk_sz = kDiskSz; - img.sector_sz = kDiskSectorSz; - img.block_cnt = 0; - - MmCopyMemory((VoidPtr)img.disk_name, (VoidPtr)kDiskName, kDIDiskNameLen); - MmCopyMemory((VoidPtr)img.out_name, (VoidPtr)kOutDisk, kDIDiskNameLen); - - // format disk image. - return DIFormatPartitionEPM(img); -} \ No newline at end of file diff --git a/public/tools/diutil/dist/.keep b/public/tools/diutil/dist/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/public/tools/diutil/diutil.json b/public/tools/diutil/diutil.json index fce2166e..0805e69f 100644 --- a/public/tools/diutil/diutil.json +++ b/public/tools/diutil/diutil.json @@ -2,12 +2,12 @@ "compiler_path": "g++", "compiler_std": "c++20", "headers_path": ["./", "../../../dev/kernel", "../../../dev/", "./"], - "sources_path": ["CommandLine.cc"], + "sources_path": ["src/CommandLine.cc"], "output_name": "./dist/diutil", "cpp_macros": [ - "kMKFSVersion=0x0100", - "kMKFSVersionHighest=0x0100", - "kMKFSVersionLowest=0x0100", + "kDUTILVersion=0x0100", + "kDUTILVersionHighest=0x0100", + "kDUTILVersionLowest=0x0100", "__NE_SDK__" ] } diff --git a/public/tools/diutil/src/CommandLine.cc b/public/tools/diutil/src/CommandLine.cc new file mode 100644 index 00000000..c0388611 --- /dev/null +++ b/public/tools/diutil/src/CommandLine.cc @@ -0,0 +1,68 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal EL Mahrouss, all rights reserved. + + FILE: CommandLine.cc + PURPOSE: DIUTIL CLI. + + ------------------------------------------- */ + +#include + +static const Char kDiskName[kDIDiskNameLen] = "Disk"; +static SInt32 kDiskSectorSz = 512; +static const SInt32 kDiskBlockCnt = 1; +static SizeT kDiskSz = gib_cast(4); +static const Char kOutDisk[kDIOutNameLen] = "disk.eimg"; + +/// @brief Filesystem tool entrypoint. +int main(int argc, char** argv) +{ + for (SizeT arg = 0; arg < argc; ++arg) + { + const Char* arg_s = argv[arg]; + + if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-output-name", MmStrLen("--disk-output-name") == 0)) + { + if ((arg + 1) < argc) + { + MmCopyMemory((VoidPtr)kOutDisk, argv[arg + 1], kDIDiskNameLen); + } + } + else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-output-size", MmStrLen("--disk-output-size") == 0)) + { + if ((arg + 1) < argc) + { + kDiskSz = MathToNumber(argv[arg + 1], nullptr, 10); + } + } + else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-sector-size", MmStrLen("--disk-sector-size") == 0)) + { + if ((arg + 1) < argc) + { + kDiskSectorSz = MathToNumber(argv[arg + 1], nullptr, 10); + } + } + else if (MmCmpMemory((VoidPtr)arg_s, (VoidPtr) "--disk-part-name", MmStrLen("--disk-part-name") == 0)) + { + if ((arg + 1) < argc) + { + MmCopyMemory((VoidPtr)kDiskName, argv[arg + 1], kDIDiskNameLen); + } + } + } + + // create disk image. + + DI_DISK_IMAGE img{}; + + img.disk_sz = kDiskSz; + img.sector_sz = kDiskSectorSz; + img.block_cnt = 0; + + MmCopyMemory((VoidPtr)img.disk_name, (VoidPtr)kDiskName, kDIDiskNameLen); + MmCopyMemory((VoidPtr)img.out_name, (VoidPtr)kOutDisk, kDIDiskNameLen); + + // format disk image. + return DIFormatPartitionEPM(img); +} \ No newline at end of file -- cgit v1.2.3