From 95f1448a371f563071a755b9ed507cd64d70ed5b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 18 Apr 2025 09:18:55 +0200 Subject: kernel, boot: improvements and tweaks on the kernel's filesystems. - HeFS requires a 4gb disk at minimum now. - make_app fully supports STEPS. - Errata of NeFS.tex, add HeFS.tex. - Better boot flow. - New filesystems for FileMgr. Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/FS/Ext2+FileMgr.cc | 14 ++++++++++++++ dev/kernel/src/FS/HeFS+FileMgr.cc | 14 ++++++++++++++ dev/kernel/src/FS/NeFS+FileMgr.cc | 6 +++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 dev/kernel/src/FS/Ext2+FileMgr.cc create mode 100644 dev/kernel/src/FS/HeFS+FileMgr.cc (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/FS/Ext2+FileMgr.cc b/dev/kernel/src/FS/Ext2+FileMgr.cc new file mode 100644 index 00000000..cb17b587 --- /dev/null +++ b/dev/kernel/src/FS/Ext2+FileMgr.cc @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef __NE_MINIMAL_OS__ +#ifdef __FSKIT_INCLUDES_EXT2__ + +#include +#include + +#endif // ifdef __FSKIT_INCLUDES_EXT2__ +#endif // ifndef __NE_MINIMAL_OS__ diff --git a/dev/kernel/src/FS/HeFS+FileMgr.cc b/dev/kernel/src/FS/HeFS+FileMgr.cc new file mode 100644 index 00000000..e6719e1b --- /dev/null +++ b/dev/kernel/src/FS/HeFS+FileMgr.cc @@ -0,0 +1,14 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef __NE_MINIMAL_OS__ +#ifdef __FSKIT_INCLUDES_HEFS__ + +#include +#include + +#endif // ifdef __FSKIT_INCLUDES_HEFS__ +#endif // ifndef __NE_MINIMAL_OS__ diff --git a/dev/kernel/src/FS/NeFS+FileMgr.cc b/dev/kernel/src/FS/NeFS+FileMgr.cc index 0107bd9e..348ae61b 100644 --- a/dev/kernel/src/FS/NeFS+FileMgr.cc +++ b/dev/kernel/src/FS/NeFS+FileMgr.cc @@ -4,12 +4,12 @@ ------------------------------------------- */ -#include -#include - #ifndef __NE_MINIMAL_OS__ #ifdef __FSKIT_INCLUDES_NEFS__ +#include +#include + /// @brief NeFS File manager. /// BUGS: 0 -- cgit v1.2.3 From b69c498953dc47900e6ccdd0f501727480836f23 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 18 Apr 2025 18:24:44 +0200 Subject: kernel, IMP: GfxKit: GraphicsKit. kernel, IMP: StorageKit: Remove usage of cleanup method on AHCI, DMA, and PIO. Signed-off-by: Amlal El Mahrouss --- dev/kernel/GfxKit/Gfx.h | 51 ++++++++++++++++++++++ dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 3 +- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 3 +- dev/kernel/StorageKit/AHCI.h | 7 +-- dev/kernel/StorageKit/ATA.h | 4 +- dev/kernel/StorageKit/PRDT.h | 4 +- dev/kernel/amd64-ci.make | 2 +- dev/kernel/amd64-desktop.make | 2 +- dev/kernel/src/Gfx/FBDeviceInterface.cc | 58 +++++++++++++++++++++++++ dev/kernel/src/Storage/AHCIDeviceInterface.cc | 13 ++---- dev/kernel/src/Storage/ATADeviceInterface.cc | 12 ++--- dev/modules/CoreGfx/CoreWindow.h | 10 +++++ 12 files changed, 136 insertions(+), 33 deletions(-) create mode 100644 dev/kernel/GfxKit/Gfx.h create mode 100644 dev/kernel/src/Gfx/FBDeviceInterface.cc (limited to 'dev/kernel/src') diff --git a/dev/kernel/GfxKit/Gfx.h b/dev/kernel/GfxKit/Gfx.h new file mode 100644 index 00000000..ce5751dc --- /dev/null +++ b/dev/kernel/GfxKit/Gfx.h @@ -0,0 +1,51 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace Kernel +{ + class FBDeviceInterface; + struct FBDevicePacket; + + /// @brief Framebuffer device interface packet. + /// @details This structure is used to send and receive data from the framebuffer device. + /// @note The structure is packed to ensure that the data is aligned correctly for the device. + struct PACKED FBDevicePacket final + { + UInt32 fX; + UInt32 fY; + UInt32 fWidth; + UInt32 fHeight; + UInt32 fColor; + UInt32 fFlags; + }; + + /// @brief Framebuffer device interface. + /// @details This class is used to send and receive data from the framebuffer device. + /// @note The class is derived from the IDeviceObject class. + class FBDeviceInterface NE_DEVICE + { + public: + explicit FBDeviceInterface(void (*out)(IDeviceObject* self, FBDevicePacket* out), + void (*in)(IDeviceObject* self, FBDevicePacket* in)); + + virtual ~FBDeviceInterface() override; + + public: + FBDeviceInterface& operator=(const FBDeviceInterface&) = default; + FBDeviceInterface(const FBDeviceInterface&) = default; + + const Char* Name() const override; + + public: + FBDeviceInterface& operator<<(FBDevicePacket* Data) override; + FBDeviceInterface& operator>>(FBDevicePacket* Data) override; + }; +} // namespace Kernel diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 9c8f95bc..08fd02ab 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -479,8 +479,7 @@ namespace Kernel return ErrorOr(kErrorDisk); AHCIDeviceInterface device(Detail::sk_io_read_ahci, - Detail::sk_io_write_ahci, - nullptr); + Detail::sk_io_write_ahci); device.SetPortsImplemented(kSATAPortsImplemented); device.SetIndex(drv_index); diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index cc8c92d8..257dd5c8 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -252,8 +252,7 @@ namespace Kernel { /// here we don't check if we probed ATA, since we'd need to grab IO after that. ATADeviceInterface device(Detail::sk_io_read_pio, - Detail::sk_io_write_pio, - nullptr); + Detail::sk_io_write_pio); device.SetIndex(drv_index); diff --git a/dev/kernel/StorageKit/AHCI.h b/dev/kernel/StorageKit/AHCI.h index 7e2eaf68..68a42c46 100644 --- a/dev/kernel/StorageKit/AHCI.h +++ b/dev/kernel/StorageKit/AHCI.h @@ -12,12 +12,14 @@ namespace Kernel { + /// @brief AHCIDeviceInterface class + /// @details This class is used to send and receive data from the AHCI device. + /// @note The class is derived from the IDeviceObject class. class AHCIDeviceInterface NE_DEVICE { public: explicit AHCIDeviceInterface(void (*out)(IDeviceObject* self, MountpointInterface* out), - void (*in)(IDeviceObject* self, MountpointInterface* in), - void (*cleanup)(void)); + void (*in)(IDeviceObject* self, MountpointInterface* in)); virtual ~AHCIDeviceInterface() override; @@ -40,7 +42,6 @@ namespace Kernel AHCIDeviceInterface& operator>>(MountpointInterface* Data) override; private: - Void (*fCleanup)(Void) = {nullptr}; UInt16 fPortsImplemented{0U}; UInt32 fDriveIndex{0U}; }; diff --git a/dev/kernel/StorageKit/ATA.h b/dev/kernel/StorageKit/ATA.h index 917fa12b..04cf88d7 100644 --- a/dev/kernel/StorageKit/ATA.h +++ b/dev/kernel/StorageKit/ATA.h @@ -18,8 +18,7 @@ namespace Kernel { public: explicit ATADeviceInterface(void (*Out)(IDeviceObject*, MountpointInterface* outpacket), - void (*In)(IDeviceObject*, MountpointInterface* inpacket), - void (*Cleanup)(void)); + void (*In)(IDeviceObject*, MountpointInterface* inpacket)); virtual ~ATADeviceInterface(); @@ -43,7 +42,6 @@ namespace Kernel Void SetIndex(const UInt32& drv); private: - void (*fCleanup)(void) = {nullptr}; UInt32 fDriveIndex{0U}; UInt16 fIO, fMaster{0U}; }; diff --git a/dev/kernel/StorageKit/PRDT.h b/dev/kernel/StorageKit/PRDT.h index 729b6e96..dde9c208 100644 --- a/dev/kernel/StorageKit/PRDT.h +++ b/dev/kernel/StorageKit/PRDT.h @@ -15,7 +15,7 @@ namespace Kernel { /// @brief Tranfer information about PRD. - enum kPRDTTransfer + enum { kPRDTTransferInProgress, kPRDTTransferIsDone, @@ -23,7 +23,7 @@ namespace Kernel }; /// @brief Physical Region Descriptor Table. - struct PRDT + struct PRDT final { UInt32 fPhysAddress; UInt32 fSectorCount; diff --git a/dev/kernel/amd64-ci.make b/dev/kernel/amd64-ci.make index e9a4d4b0..7748fc7c 100644 --- a/dev/kernel/amd64-ci.make +++ b/dev/kernel/amd64-ci.make @@ -48,7 +48,7 @@ WINDRES=x86_64-w64-mingw32-windres .PHONY: nekernel-amd64-epm nekernel-amd64-epm: clean $(WINDRES) kernel_rsrc.rsrc -O coff -o kernel_rsrc.obj - $(CXX) $(CCFLAGS) $(DISK_DRV) $(DEBUG_MACRO) $(wildcard src/*.cc) $(wildcard HALKit/AMD64/PCI/*.cc) $(wildcard src/Network/*.cc) $(wildcard src/Storage/*.cc) $(wildcard src/FS/*.cc) $(wildcard HALKit/AMD64/Storage/*.cc) $(wildcard HALKit/AMD64/*.cc) $(wildcard src/Swap/*.cc) $(wildcard HALKit/AMD64/*.s) + $(CXX) $(CCFLAGS) $(DISK_DRV) $(DEBUG_MACRO) $(wildcard src/*.cc) $(wildcard src/Gfx/*.cc) $(wildcard HALKit/AMD64/PCI/*.cc) $(wildcard src/Network/*.cc) $(wildcard src/Storage/*.cc) $(wildcard src/FS/*.cc) $(wildcard HALKit/AMD64/Storage/*.cc) $(wildcard HALKit/AMD64/*.cc) $(wildcard src/Swap/*.cc) $(wildcard HALKit/AMD64/*.s) $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalCommonAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalBootHeader.asm diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index 02b0a3b4..9993796c 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -50,7 +50,7 @@ WINDRES=x86_64-w64-mingw32-windres .PHONY: nekernel-amd64-epm nekernel-amd64-epm: clean $(WINDRES) kernel_rsrc.rsrc -O coff -o kernel_rsrc.obj - $(CXX) $(CCFLAGS) $(DISK_DRV) $(DEBUG_MACRO) $(wildcard src/*.cc) $(wildcard HALKit/AMD64/PCI/*.cc) $(wildcard src/Network/*.cc) $(wildcard src/Storage/*.cc) $(wildcard src/FS/*.cc) $(wildcard HALKit/AMD64/Storage/*.cc) $(wildcard HALKit/AMD64/*.cc) $(wildcard src/Swap/*.cc) $(wildcard HALKit/AMD64/*.s) + $(CXX) $(CCFLAGS) $(DISK_DRV) $(DEBUG_MACRO) $(wildcard src/*.cc) $(wildcard src/Gfx/*.cc) $(wildcard HALKit/AMD64/PCI/*.cc) $(wildcard src/Network/*.cc) $(wildcard src/Storage/*.cc) $(wildcard src/FS/*.cc) $(wildcard HALKit/AMD64/Storage/*.cc) $(wildcard HALKit/AMD64/*.cc) $(wildcard src/Swap/*.cc) $(wildcard HALKit/AMD64/*.s) $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalCommonAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalBootHeader.asm diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc new file mode 100644 index 00000000..a9b2be29 --- /dev/null +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -0,0 +1,58 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include + +using namespace Kernel; + +/// @brief Class constructor +/// @param Out Drive output +/// @param In Drive input +/// @param Cleanup Drive cleanup. +FBDeviceInterface::FBDeviceInterface(void (*out)(IDeviceObject* self, FBDevicePacket* outpacket), + void (*in)(IDeviceObject* self, FBDevicePacket* inpacket)) + : IDeviceObject(out, in) +{ +} + +/// @brief Class desctructor +FBDeviceInterface::~FBDeviceInterface() = default; + +/// @brief Output operator. +/// @param mnt the disk mountpoint. +/// @return the class itself after operation. +FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) +{ + if (!pckt) + return *this; + + FBDrawInRegion(pckt->fColor, pckt->fHeight, pckt->fWidth, pckt->fY, pckt->fX); + + return *this; +} + +/// @brief Input operator. +/// @param mnt the disk mountpoint. +/// @return the class itself after operation. +FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) +{ + if (!pckt) + return *this; + + pckt->fColor = *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * + pckt->fX + + 4 * pckt->fY))); + + return *this; +} + +/// @brief Returns the name of the device interface. +/// @return it's name as a string. +const Char* FBDeviceInterface::Name() const +{ + return "/dev/fb{}"; +} \ No newline at end of file diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc index 1798e9a9..c5f43bf6 100644 --- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc +++ b/dev/kernel/src/Storage/AHCIDeviceInterface.cc @@ -13,20 +13,13 @@ using namespace Kernel; /// @param In Drive input /// @param Cleanup Drive cleanup. AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(IDeviceObject* self, MountpointInterface* outpacket), - void (*in)(IDeviceObject* self, MountpointInterface* inpacket), - void (*cleanup)(void)) - : IDeviceObject(out, in), fCleanup(cleanup) + void (*in)(IDeviceObject* self, MountpointInterface* inpacket)) + : IDeviceObject(out, in) { } /// @brief Class desctructor -AHCIDeviceInterface::~AHCIDeviceInterface() -{ - MUST_PASS(fCleanup); - - if (fCleanup) - fCleanup(); -} +AHCIDeviceInterface::~AHCIDeviceInterface() = default; /// @brief Returns the name of the device interface. /// @return it's name as a string. diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc index 2e7022a7..3fe331dd 100644 --- a/dev/kernel/src/Storage/ATADeviceInterface.cc +++ b/dev/kernel/src/Storage/ATADeviceInterface.cc @@ -14,19 +14,13 @@ using namespace Kernel; /// @param Cleanup Drive cleanup. ATADeviceInterface::ATADeviceInterface( void (*Out)(IDeviceObject*, MountpointInterface* outpacket), - void (*In)(IDeviceObject*, MountpointInterface* inpacket), - void (*Cleanup)(void)) - : IDeviceObject(Out, In), fCleanup(Cleanup) + void (*In)(IDeviceObject*, MountpointInterface* inpacket)) + : IDeviceObject(Out, In) { } /// @brief Class desctructor -ATADeviceInterface::~ATADeviceInterface() -{ - MUST_PASS(fCleanup); - if (fCleanup) - fCleanup(); -} +ATADeviceInterface::~ATADeviceInterface() = default; /// @brief Returns the name of the device interface. /// @return it's name as a string. diff --git a/dev/modules/CoreGfx/CoreWindow.h b/dev/modules/CoreGfx/CoreWindow.h index f925eecd..b1581f65 100644 --- a/dev/modules/CoreGfx/CoreWindow.h +++ b/dev/modules/CoreGfx/CoreWindow.h @@ -1,3 +1,13 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +/// @note this file is experimental and not used yet. +/// @file CoreWindow.h +/// @brief Core window drawing functions. + #pragma once #include -- cgit v1.2.3 From 6d99a232379317afed814a023fee464001f796ea Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 18 Apr 2025 18:34:33 +0200 Subject: kernel, GfxKit: FIX: Check boundaries to avoid page fault. Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/Gfx/FBDeviceInterface.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'dev/kernel/src') diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index a9b2be29..525f32b4 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -29,6 +29,13 @@ FBDeviceInterface& FBDeviceInterface::operator<<(FBDevicePacket* pckt) if (!pckt) return *this; + if (pckt->fHeight == 0 || pckt->fWidth == 0) + return *this; + + if (pckt->fX > kHandoverHeader->f_GOP.f_Width || + pckt->fY > kHandoverHeader->f_GOP.f_Height) + return *this; + FBDrawInRegion(pckt->fColor, pckt->fHeight, pckt->fWidth, pckt->fY, pckt->fX); return *this; @@ -42,6 +49,10 @@ FBDeviceInterface& FBDeviceInterface::operator>>(FBDevicePacket* pckt) if (!pckt) return *this; + if (pckt->fX > kHandoverHeader->f_GOP.f_Width || + pckt->fY > kHandoverHeader->f_GOP.f_Height) + return *this; + pckt->fColor = *(((Kernel::UInt32*)(kHandoverHeader->f_GOP.f_The + 4 * kHandoverHeader->f_GOP.f_PixelPerLine * pckt->fX + -- cgit v1.2.3 From 815a1d6538b6748393f6a631a64a1043e49bf3a1 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 18 Apr 2025 18:35:56 +0200 Subject: GfxKit: Gave the correct name for FB device. Signed-off-by: Amlal El Mahrouss --- dev/kernel/GfxKit/FB.h | 51 +++++++++++++++++++++++++++++++++ dev/kernel/GfxKit/Gfx.h | 51 --------------------------------- dev/kernel/src/Gfx/FBDeviceInterface.cc | 2 +- 3 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 dev/kernel/GfxKit/FB.h delete mode 100644 dev/kernel/GfxKit/Gfx.h (limited to 'dev/kernel/src') diff --git a/dev/kernel/GfxKit/FB.h b/dev/kernel/GfxKit/FB.h new file mode 100644 index 00000000..ce5751dc --- /dev/null +++ b/dev/kernel/GfxKit/FB.h @@ -0,0 +1,51 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include + +namespace Kernel +{ + class FBDeviceInterface; + struct FBDevicePacket; + + /// @brief Framebuffer device interface packet. + /// @details This structure is used to send and receive data from the framebuffer device. + /// @note The structure is packed to ensure that the data is aligned correctly for the device. + struct PACKED FBDevicePacket final + { + UInt32 fX; + UInt32 fY; + UInt32 fWidth; + UInt32 fHeight; + UInt32 fColor; + UInt32 fFlags; + }; + + /// @brief Framebuffer device interface. + /// @details This class is used to send and receive data from the framebuffer device. + /// @note The class is derived from the IDeviceObject class. + class FBDeviceInterface NE_DEVICE + { + public: + explicit FBDeviceInterface(void (*out)(IDeviceObject* self, FBDevicePacket* out), + void (*in)(IDeviceObject* self, FBDevicePacket* in)); + + virtual ~FBDeviceInterface() override; + + public: + FBDeviceInterface& operator=(const FBDeviceInterface&) = default; + FBDeviceInterface(const FBDeviceInterface&) = default; + + const Char* Name() const override; + + public: + FBDeviceInterface& operator<<(FBDevicePacket* Data) override; + FBDeviceInterface& operator>>(FBDevicePacket* Data) override; + }; +} // namespace Kernel diff --git a/dev/kernel/GfxKit/Gfx.h b/dev/kernel/GfxKit/Gfx.h deleted file mode 100644 index ce5751dc..00000000 --- a/dev/kernel/GfxKit/Gfx.h +++ /dev/null @@ -1,51 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#pragma once - -#include -#include - -namespace Kernel -{ - class FBDeviceInterface; - struct FBDevicePacket; - - /// @brief Framebuffer device interface packet. - /// @details This structure is used to send and receive data from the framebuffer device. - /// @note The structure is packed to ensure that the data is aligned correctly for the device. - struct PACKED FBDevicePacket final - { - UInt32 fX; - UInt32 fY; - UInt32 fWidth; - UInt32 fHeight; - UInt32 fColor; - UInt32 fFlags; - }; - - /// @brief Framebuffer device interface. - /// @details This class is used to send and receive data from the framebuffer device. - /// @note The class is derived from the IDeviceObject class. - class FBDeviceInterface NE_DEVICE - { - public: - explicit FBDeviceInterface(void (*out)(IDeviceObject* self, FBDevicePacket* out), - void (*in)(IDeviceObject* self, FBDevicePacket* in)); - - virtual ~FBDeviceInterface() override; - - public: - FBDeviceInterface& operator=(const FBDeviceInterface&) = default; - FBDeviceInterface(const FBDeviceInterface&) = default; - - const Char* Name() const override; - - public: - FBDeviceInterface& operator<<(FBDevicePacket* Data) override; - FBDeviceInterface& operator>>(FBDevicePacket* Data) override; - }; -} // namespace Kernel diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc index 525f32b4..c2eb2ca7 100644 --- a/dev/kernel/src/Gfx/FBDeviceInterface.cc +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include using namespace Kernel; -- cgit v1.2.3 From 1740a0dff822d7666b8c1f056b6c411ef6b0f9fd Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 19 Apr 2025 08:36:30 +0200 Subject: kernel, mod, boot: extend GPT support. Signed-off-by: Amlal El Mahrouss --- compile_flags.txt | 3 +- dev/boot/BootKit/BootKit.h | 79 +++++++++++++++++++++++++++-- dev/boot/modules/SysChk/SysChk.cc | 2 +- dev/boot/modules/SysChk/amd64-ahci-epm.json | 25 +++++++++ dev/boot/modules/SysChk/amd64-ahci-gpt.json | 25 +++++++++ dev/boot/modules/SysChk/amd64-ahci.json | 24 --------- dev/boot/modules/SysChk/amd64-pio-epm.json | 25 +++++++++ dev/boot/modules/SysChk/amd64-pio-gpt.json | 25 +++++++++ dev/boot/modules/SysChk/amd64-pio.json | 25 --------- dev/kernel/FirmwareKit/EFI.h | 1 + dev/kernel/FirmwareKit/GPT.h | 8 +-- dev/kernel/src/DriveMgr.cc | 36 +++++++++---- modules_ahci_x64.sh | 2 +- modules_pio_x64.sh | 2 +- 14 files changed, 212 insertions(+), 70 deletions(-) create mode 100644 dev/boot/modules/SysChk/amd64-ahci-epm.json create mode 100644 dev/boot/modules/SysChk/amd64-ahci-gpt.json delete mode 100644 dev/boot/modules/SysChk/amd64-ahci.json create mode 100644 dev/boot/modules/SysChk/amd64-pio-epm.json create mode 100644 dev/boot/modules/SysChk/amd64-pio-gpt.json delete mode 100644 dev/boot/modules/SysChk/amd64-pio.json (limited to 'dev/kernel/src') diff --git a/compile_flags.txt b/compile_flags.txt index 74b5c8ed..d6115831 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -21,4 +21,5 @@ -D__ATA_DMA__ -Wall -Wpedantic --Wextra \ No newline at end of file +-Wextra +-DBOOTZ_GPT_SUPPORT \ No newline at end of file diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index d7f4f4d5..c781876c 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -298,7 +298,7 @@ namespace Boot fDiskDev.Write((Char*)&catalogKind, sizeof(NEFS_CATALOG_STRUCT)); - writer.Write(L"BootZ: Wrote directory: ").Write(blob->fFileName).Write(L"\r"); + writer.Write(L"BootZ: wrote root directory: ").Write(blob->fFileName).Write(L"\r"); return true; } @@ -349,10 +349,12 @@ namespace Boot part.DiskSize = fDiskDev.GetDiskSize(); part.Flags = kNeFSPartitionTypeBoot | kNeFSPartitionTypeStandard; +#if defined(BOOTZ_EPM_SUPPORT) fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; fDiskDev.Leak().mSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); fDiskDev.Write((Char*)&part, sizeof(NEFS_ROOT_PARTITION_BLOCK)); +#endif // defined(BOOTZ_EPM_SUPPORT) BootTextWriter writer; @@ -363,14 +365,12 @@ namespace Boot writer << "BootZ: Free sectors: " << part.FreeSectors << "\r"; writer << "BootZ: Sector size: " << part.SectorSize << "\r"; -#ifdef BOOTZ_EPM_SUPPORT +#if defined(BOOTZ_EPM_SUPPORT) EPM_PART_BLOCK epm_boot{0}; const auto kFsName = "NeFS"; const auto kBlockName = "OS"; - CopyMem(epm_boot.Fs, reinterpret_cast(const_cast(kFsName)), StrLen(kFsName)); - epm_boot.FsVersion = kNeFSVersionInteger; epm_boot.LbaStart = kNeFSRootCatalogStartAddress; epm_boot.LbaEnd = fDiskDev.GetDiskSize(); @@ -378,6 +378,13 @@ namespace Boot epm_boot.Kind = kEPMNeKernel; epm_boot.NumBlocks = part.CatalogCount; + epm_boot.Guid.Data1 = 0x00000000; + epm_boot.Guid.Data2 = 0x0000; + epm_boot.Guid.Data3 = 0x0000; + + SetMem(epm_boot.Guid.Data4, 0, 8); + + CopyMem(epm_boot.Fs, reinterpret_cast(const_cast(kFsName)), StrLen(kFsName)); CopyMem(epm_boot.Name, reinterpret_cast(const_cast(kBlockName)), StrLen(kBlockName)); CopyMem(epm_boot.Magic, reinterpret_cast(const_cast(kEPMMagic)), StrLen(kEPMMagic)); @@ -386,7 +393,69 @@ namespace Boot fDiskDev.Write((Char*)&epm_boot, sizeof(EPM_PART_BLOCK)); - writer.Write(L"BootZ: Drive has been formatted Successfully.\r"); + writer.Write(L"BootZ: Drive is EPM formatted.\r"); +#elif defined(BOOTZ_GPT_SUPPORT) + const auto kBlockName = "NeFS_OS"; + + GPT_PARTITION_TABLE gpt_part{0}; + + CopyMem(gpt_part.Signature, reinterpret_cast(const_cast(kMagicGPT)), StrLen(kMagicGPT)); + + gpt_part.Revision = 0x00010000; + gpt_part.HeaderSize = sizeof(GPT_PARTITION_TABLE); + + gpt_part.CRC32 = 0x00000000; + + gpt_part.Reserved1 = 0x00000000; + gpt_part.LBAHeader = 0x00000000; + gpt_part.LBAAltHeader = 0x00000000; + gpt_part.FirstGPTEntry = 0x00000000; + gpt_part.LastGPTEntry = 0x00000000; + gpt_part.Guid.Data1 = 0x00000000; + gpt_part.Guid.Data2 = 0x0000; + gpt_part.Guid.Data3 = 0x0000; + + gpt_part.Revision = 0x00010000; + + SetMem(gpt_part.Guid.Data4, 0, 8); + + gpt_part.StartingLBA = 0x00000000; + gpt_part.NumPartitionEntries = 0x00000000; + gpt_part.SizeOfEntries = 0x00000000; + gpt_part.CRC32PartEntry = 0x00000000; + + SetMem(gpt_part.Reserved2, 0, kSectorAlignGPT_PartTbl); + + fDiskDev.Leak().mBase = kGPTPartitionTableLBA; // always always resies at zero block. + fDiskDev.Leak().mSize = sizeof(EPM_PART_BLOCK); + + fDiskDev.Write((Char*)&gpt_part, sizeof(GPT_PARTITION_TABLE)); + + GPT_PARTITION_ENTRY gpt_part_entry{0}; + + gpt_part_entry.StartLBA = kNeFSRootCatalogStartAddress; + gpt_part_entry.EndLBA = fDiskDev.GetDiskSize(); + gpt_part_entry.Attributes = 0x00000000; + + gpt_part_entry.PartitionTypeGUID.Data1 = 0x00000000; + gpt_part_entry.PartitionTypeGUID.Data2 = 0x0000; + gpt_part_entry.PartitionTypeGUID.Data3 = 0x0000; + + CopyMem(gpt_part_entry.Name, reinterpret_cast(const_cast(kBlockName)), StrLen(kBlockName)); + + SetMem(gpt_part_entry.PartitionTypeGUID.Data4, 0, 8); + + fDiskDev.Leak().mBase = kGPTPartitionTableLBA + sizeof(GPT_PARTITION_TABLE); + fDiskDev.Leak().mSize = sizeof(GPT_PARTITION_ENTRY); + fDiskDev.Write((Char*)&gpt_part_entry, sizeof(GPT_PARTITION_ENTRY)); + + fDiskDev.Leak().mBase = gpt_part_entry.StartLBA; + fDiskDev.Leak().mSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); + + fDiskDev.Write((Char*)&part, sizeof(NEFS_ROOT_PARTITION_BLOCK)); + + writer.Write(L"BootZ: Drive is GPT formatted.\r"); + #endif return YES; diff --git a/dev/boot/modules/SysChk/SysChk.cc b/dev/boot/modules/SysChk/SysChk.cc index dec4e11a..3979714d 100644 --- a/dev/boot/modules/SysChk/SysChk.cc +++ b/dev/boot/modules/SysChk/SysChk.cc @@ -30,7 +30,7 @@ EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover) { NE_UNUSED(handover); -#ifdef __ATA_PIO__ +#if defined(__ATA_PIO__) Boot::BDiskFormatFactory partition_factory; if (partition_factory.IsPartitionValid()) diff --git a/dev/boot/modules/SysChk/amd64-ahci-epm.json b/dev/boot/modules/SysChk/amd64-ahci-epm.json new file mode 100644 index 00000000..5cff74de --- /dev/null +++ b/dev/boot/modules/SysChk/amd64-ahci-epm.json @@ -0,0 +1,25 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], + "sources_path": ["*.cc", "*.S", "../../src/HEL/AMD64/*.cc", "../../src/HEL/AMD64/*.S", "../../src/*.cc"], + "output_name": "chk.efi", + "compiler_flags": [ + "-nostdlib", + "-std=c++20", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + ], + "cpp_macros": [ + "__NEOSKRNL__", + "__BOOTZ__", + "__BOOTZ_STANDALONE__", + "__NE_AMD64__", + "__AHCI__", + "BOOTZ_EPM_SUPPORT", + "kChkVersionHighest=0x0100", + "kChkVersionLowest=0x0100", + "kChkVersion=0x0100" + ] +} diff --git a/dev/boot/modules/SysChk/amd64-ahci-gpt.json b/dev/boot/modules/SysChk/amd64-ahci-gpt.json new file mode 100644 index 00000000..52864969 --- /dev/null +++ b/dev/boot/modules/SysChk/amd64-ahci-gpt.json @@ -0,0 +1,25 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], + "sources_path": ["*.cc", "*.S", "../../src/HEL/AMD64/*.cc", "../../src/HEL/AMD64/*.S", "../../src/*.cc"], + "output_name": "chk.efi", + "compiler_flags": [ + "-nostdlib", + "-std=c++20", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + ], + "cpp_macros": [ + "__NEOSKRNL__", + "__BOOTZ__", + "__BOOTZ_STANDALONE__", + "__NE_AMD64__", + "__AHCI__", + "BOOTZ_GPT_SUPPORT", + "kChkVersionHighest=0x0100", + "kChkVersionLowest=0x0100", + "kChkVersion=0x0100" + ] +} diff --git a/dev/boot/modules/SysChk/amd64-ahci.json b/dev/boot/modules/SysChk/amd64-ahci.json deleted file mode 100644 index d13e6c4a..00000000 --- a/dev/boot/modules/SysChk/amd64-ahci.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++", - "compiler_std": "c++20", - "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], - "sources_path": ["*.cc", "*.S", "../../src/HEL/AMD64/*.cc", "../../src/HEL/AMD64/*.S", "../../src/*.cc"], - "output_name": "chk.efi", - "compiler_flags": [ - "-nostdlib", - "-std=c++20", - "-fno-rtti", - "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" - ], - "cpp_macros": [ - "__NEOSKRNL__", - "__BOOTZ__", - "__BOOTZ_STANDALONE__", - "__NE_AMD64__", - "__AHCI__", - "kChkVersionHighest=0x0100", - "kChkVersionLowest=0x0100", - "kChkVersion=0x0100" - ] -} diff --git a/dev/boot/modules/SysChk/amd64-pio-epm.json b/dev/boot/modules/SysChk/amd64-pio-epm.json new file mode 100644 index 00000000..3848a611 --- /dev/null +++ b/dev/boot/modules/SysChk/amd64-pio-epm.json @@ -0,0 +1,25 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], + "sources_path": ["*.cc", "*.S", "../../src/HEL/AMD64/*.cc", "../../src/HEL/AMD64/*.S", "../../src/*.cc"], + "output_name": "chk.efi", + "compiler_flags": [ + "-nostdlib", + "-std=c++20", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + ], + "cpp_macros": [ + "__NEOSKRNL__", + "__BOOTZ__", + "__BOOTZ_STANDALONE__", + "__NE_AMD64__", + "__ATA_PIO__", + "BOOTZ_EPM_SUPPORT", + "kChkVersionHighest=0x0100", + "kChkVersionLowest=0x0100", + "kChkVersion=0x0100" + ] +} diff --git a/dev/boot/modules/SysChk/amd64-pio-gpt.json b/dev/boot/modules/SysChk/amd64-pio-gpt.json new file mode 100644 index 00000000..2a4c4efe --- /dev/null +++ b/dev/boot/modules/SysChk/amd64-pio-gpt.json @@ -0,0 +1,25 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], + "sources_path": ["*.cc", "*.S", "../../src/HEL/AMD64/*.cc", "../../src/HEL/AMD64/*.S", "../../src/*.cc"], + "output_name": "chk.efi", + "compiler_flags": [ + "-nostdlib", + "-std=c++20", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + ], + "cpp_macros": [ + "__NEOSKRNL__", + "__BOOTZ__", + "__BOOTZ_STANDALONE__", + "__NE_AMD64__", + "__ATA_PIO__", + "BOOTZ_GPT_SUPPORT", + "kChkVersionHighest=0x0100", + "kChkVersionLowest=0x0100", + "kChkVersion=0x0100" + ] +} diff --git a/dev/boot/modules/SysChk/amd64-pio.json b/dev/boot/modules/SysChk/amd64-pio.json deleted file mode 100644 index 3848a611..00000000 --- a/dev/boot/modules/SysChk/amd64-pio.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compiler_path": "x86_64-w64-mingw32-g++", - "compiler_std": "c++20", - "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], - "sources_path": ["*.cc", "*.S", "../../src/HEL/AMD64/*.cc", "../../src/HEL/AMD64/*.S", "../../src/*.cc"], - "output_name": "chk.efi", - "compiler_flags": [ - "-nostdlib", - "-std=c++20", - "-fno-rtti", - "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" - ], - "cpp_macros": [ - "__NEOSKRNL__", - "__BOOTZ__", - "__BOOTZ_STANDALONE__", - "__NE_AMD64__", - "__ATA_PIO__", - "BOOTZ_EPM_SUPPORT", - "kChkVersionHighest=0x0100", - "kChkVersionLowest=0x0100", - "kChkVersion=0x0100" - ] -} diff --git a/dev/kernel/FirmwareKit/EFI.h b/dev/kernel/FirmwareKit/EFI.h index e4e78720..ca4360b1 100644 --- a/dev/kernel/FirmwareKit/EFI.h +++ b/dev/kernel/FirmwareKit/EFI.h @@ -7,5 +7,6 @@ #pragma once #include +#include /// @note this header is used to reference the EFI/EFI.h diff --git a/dev/kernel/FirmwareKit/GPT.h b/dev/kernel/FirmwareKit/GPT.h index 7ee5d10e..dc2b5ce3 100644 --- a/dev/kernel/FirmwareKit/GPT.h +++ b/dev/kernel/FirmwareKit/GPT.h @@ -11,7 +11,9 @@ #define kSectorAlignGPT_PartTbl (420U) #define kSectorAlignGPT_PartEntry (72U) -#define kPartNameGPT (8U) +#define kMagicLenGPT (8U) +#define kMagicGPT ("EFI PART") // "EFI PART" +#define kGPTPartitionTableLBA (512U + sizeof(GPT_PARTITION_TABLE)) namespace Kernel { @@ -30,10 +32,10 @@ namespace Kernel struct PACKED GPT_PARTITION_TABLE final { - Char PartitionName[kPartNameGPT]; + Char Signature[kMagicLenGPT]; UInt32 Revision; UInt32 HeaderSize; - UInt32 ChecksumCRC32; + UInt32 CRC32; UInt32 Reserved1; UInt64 LBAHeader; UInt64 LBAAltHeader; diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc index a379ea43..f958a33f 100644 --- a/dev/kernel/src/DriveMgr.cc +++ b/dev/kernel/src/DriveMgr.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -170,12 +171,12 @@ namespace Kernel trait.fInput(trait.fPacket); - if (rt_string_cmp(((EPM_PART_BLOCK*)trait.fPacket.fPacketContent)->Magic, kEPMMagic, kEPMMagicLength) == 0) + if (rt_string_cmp(block_struct.Magic, kEPMMagic, kEPMMagicLength) == 0) { trait.fPacket.fPacketReadOnly = NO; trait.fKind = kMassStorageDrive | kEPMDrive; - kout << "Disk is EPM.\r"; + kout << "Disk is EPM formatted.\r"; trait.fSectorSz = block_struct.SectorSz; trait.fLbaEnd = block_struct.LbaEnd; @@ -183,17 +184,34 @@ namespace Kernel } else { - trait.fPacket.fPacketReadOnly = YES; - trait.fKind = kMassStorageDrive | kUnformattedDrive | kReadOnlyDrive; + GPT_PARTITION_TABLE gpt_struct; - if (block_struct.Name[0] == 0 || - !rt_is_alnum(block_struct.Name[0])) + trait.fPacket.fPacketLba = kEPMBootBlockLba; + trait.fPacket.fPacketSize = sizeof(GPT_PARTITION_TABLE); + trait.fPacket.fPacketContent = &gpt_struct; + + rt_copy_memory((VoidPtr) "fs/detect-packet", trait.fPacket.fPacketMime, + rt_string_len("fs/detect-packet")); + + trait.fInput(trait.fPacket); + + if (rt_string_cmp(gpt_struct.Signature, kMagicGPT, kMagicLenGPT) == 0) { - kout << "Disk partition is empty (Read Only)\r"; + trait.fPacket.fPacketReadOnly = NO; + trait.fKind = kMassStorageDrive | kGPTDrive; + + kout << "Disk is GPT formatted.\r"; + + trait.fSectorSz = gpt_struct.SizeOfEntries; + trait.fLbaEnd = gpt_struct.LastGPTEntry; + trait.fLbaStart = gpt_struct.FirstGPTEntry; } else { - (void)(kout << "Scheme Found: " << block_struct.Name << kendl); + kout << "Disk is unformatted.\r"; + + trait.fPacket.fPacketReadOnly = YES; + trait.fKind = kMassStorageDrive | kUnformattedDrive | kReadOnlyDrive; } } @@ -212,7 +230,7 @@ namespace Kernel { DriveTrait trait; - constexpr auto kMainDrive = "/media/sda/"; + constexpr auto kMainDrive = "/media/main/"; rt_copy_memory((VoidPtr)kMainDrive, trait.fName, rt_string_len(kMainDrive)); diff --git a/modules_ahci_x64.sh b/modules_ahci_x64.sh index 44e3ecf5..eadce549 100755 --- a/modules_ahci_x64.sh +++ b/modules_ahci_x64.sh @@ -5,7 +5,7 @@ # 04/05/25: Improve and fix script. cd dev/boot/modules/SysChk -btb amd64-ahci.json +btb amd64-ahci-epm.json cd ../ cd BootNet btb amd64.json \ No newline at end of file diff --git a/modules_pio_x64.sh b/modules_pio_x64.sh index 2b501047..b091704e 100755 --- a/modules_pio_x64.sh +++ b/modules_pio_x64.sh @@ -5,7 +5,7 @@ # 04/05/25: Improve and fix script. cd dev/boot/modules/SysChk -btb amd64-pio.json +btb amd64-pio-epm.json cd ../ cd BootNet btb amd64.json \ No newline at end of file -- cgit v1.2.3