diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-04-19 08:40:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-19 08:40:12 +0200 |
| commit | f87797692777540eede1d4739199b444bd15340a (patch) | |
| tree | 646ae3f61ebcd3f83c888912c5f72efc0a8c25b0 /dev/kernel | |
| parent | ee1edba85ea13627871e1ed005931bd502b86ab8 (diff) | |
| parent | 1740a0dff822d7666b8c1f056b6c411ef6b0f9fd (diff) | |
NeKernel: 0.0.10.0.1-release
# NeKernel: 0.0.1
## Features (not all included):
- New extended File System.
- Kernel and Bootloader (NeKernel and BootZ)
- Process Scheduler.
- NeKernel's Preferred Executable Format.
- SysChk.
- Explicit Partition Map scheme.
#### NOTE: The GPT scheme is in WiP! Please run NeKernel on QEMU!
Diffstat (limited to 'dev/kernel')
28 files changed, 432 insertions, 137 deletions
diff --git a/dev/kernel/FSKit/Ext2.h b/dev/kernel/FSKit/Ext2.h index 81b6853e..856654d6 100644 --- a/dev/kernel/FSKit/Ext2.h +++ b/dev/kernel/FSKit/Ext2.h @@ -6,31 +6,35 @@ #pragma once +#include <CompilerKit/CompilerKit.h> +#include <hint/CompilerHint.h> +#include <KernelKit/DriveMgr.h> #include <NewKit/Defines.h> +#include <NewKit/KString.h> /// @file Ext2.h /// @brief EXT2 filesystem structures and constants. -#define kExt2FSMagic (0xEF53) -#define kExt2FSMaxFileNameLen (255U) -#define kExt2FSSuperblockOffset (1024) -#define kExt2FSRootInodeNumber (2) +#define kExt2FSMagic (0xEF53) +#define kExt2FSMaxFileNameLen (255U) +#define kExt2FSSuperblockOffset (1024) +#define kExt2FSRootInodeNumber (2) -#define kExt2FSInodeSize (128U) -#define kExt2FSBlockSizeBase (1024U) +#define kExt2FSInodeSize (128U) +#define kExt2FSBlockSizeBase (1024U) -#define kExt2FSRev0 (0) -#define kExt2FSRev1 (1) +#define kExt2FSRev0 (0) +#define kExt2FSRev1 (1) enum { - kExt2FileTypeUnknown = 0, - kExt2FileTypeRegular = 1, - kExt2FileTypeDirectory = 2, - kExt2FileTypeCharDevice = 3, - kExt2FileTypeBlockDevice = 4, - kExt2FileTypeFIFO = 5, - kExt2FileTypeSocket = 6, + kExt2FileTypeUnknown = 0, + kExt2FileTypeRegular = 1, + kExt2FileTypeDirectory = 2, + kExt2FileTypeCharDevice = 3, + kExt2FileTypeBlockDevice = 4, + kExt2FileTypeFIFO = 5, + kExt2FileTypeSocket = 6, kExt2FileTypeSymbolicLink = 7 }; @@ -91,7 +95,7 @@ struct PACKED EXT2_SUPER_BLOCK final Kernel::UInt32 fDefaultMountOpts; Kernel::UInt32 fFirstMetaBlockGroup; - Kernel::UInt8 fReserved[760]; // Padding to make 1024 bytes + Kernel::UInt8 fReserved[760]; // Padding to make 1024 bytes }; struct PACKED EXT2_INODE final @@ -113,10 +117,10 @@ struct PACKED EXT2_INODE final Kernel::UInt32 fGeneration; Kernel::UInt32 fFileACL; - Kernel::UInt32 fDirACL; // Only for revision 1+ + Kernel::UInt32 fDirACL; // Only for revision 1+ Kernel::UInt32 fFragmentAddr; - Kernel::UInt8 fOSD2[12]; + Kernel::UInt8 fOSD2[12]; }; struct PACKED EXT2_DIR_ENTRY final diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index cf1bebfc..8fdf933e 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -6,7 +6,13 @@ #pragma once
+#include <CompilerKit/CompilerKit.h>
+#include <hint/CompilerHint.h>
+#include <KernelKit/DriveMgr.h>
#include <NewKit/Defines.h>
+#include <NewKit/KString.h>
+#include <KernelKit/User.h>
+#include <NewKit/Crc32.h>
/// @file HeFS.h
/// @brief HeFS filesystem support.
@@ -16,11 +22,13 @@ #define kHeFSMagicLen (8)
#define kHeFSFileNameLen (256U)
-#define kHeFSPartNameLen (256U)
+#define kHeFSPartNameLen (128U)
-#define kHeFSMinimumDiskSize (mib_cast(256))
+#define kHeFSMinimumDiskSize (gib_cast(4))
struct HeFS_BOOT_NODE;
+struct HeFS_INDEX_NODE;
+struct HeFS_INDEX_NODE_DIRECTORY;
enum
{
@@ -43,28 +51,163 @@ enum kHeFSStatusCount,
};
+enum
+{
+ kHeFSEncodingUTF8 = 0x00,
+ kHeFSEncodingUTF16,
+ kHeFSEncodingUTF32,
+ kHeFSEncodingUTF16BE,
+ kHeFSEncodingUTF16LE,
+ kHeFSEncodingUTF32BE,
+ kHeFSEncodingUTF32LE,
+ kHeFSEncodingUTF8BE,
+ kHeFSEncodingUTF8LE,
+ kHeFSEncodingCount,
+};
+
+inline constexpr UInt16 kHeFSFileKindRegular = 0x00;
+inline constexpr UInt16 kHeFSFileKindDirectory = 0x01;
+inline constexpr UInt16 kHeFSFileKindBlock = 0x02;
+inline constexpr UInt16 kHeFSFileKindCharacter = 0x03;
+inline constexpr UInt16 kHeFSFileKindFIFO = 0x04;
+inline constexpr UInt16 kHeFSFileKindSocket = 0x05;
+inline constexpr UInt16 kHeFSFileKindSymbolicLink = 0x06;
+inline constexpr UInt16 kHeFSFileKindUnknown = 0x07;
+inline constexpr UInt16 kHeFSFileKindCount = 0x08;
+
+/// @brief HeFS blocks are array containing sparse blocks of data.
+/// @details The blocks are used to store the data of a file. Each block is a pointer to a block of data on the disk.
+inline constexpr UInt16 kHeFSBlockCount = 0x10;
+
struct PACKED HeFS_BOOT_NODE final
{
- Kernel::Char fMagic[kHeFSMagicLen];
- Kernel::Char fPartName[kHeFSPartNameLen];
- Kernel::UInt32 fVersion;
- Kernel::UInt64 fBadSectors;
- Kernel::UInt64 fSectorCount;
- Kernel::UInt64 fSectorSize;
- Kernel::UInt32 fChecksum;
- Kernel::UInt8 fDriveKind;
- Kernel::UInt8 fTextEncoding;
- Kernel::UInt64 fRootINode;
- Kernel::UInt64 fRecoveryINode;
+ Kernel::Char fMagic[kHeFSMagicLen];
+ Kernel::Utf16Char fVolName[kHeFSPartNameLen];
+ Kernel::UInt32 fVersion;
+ Kernel::UInt64 fBadSectors;
+ Kernel::UInt64 fSectorCount;
+ Kernel::UInt64 fSectorSize;
+ Kernel::UInt32 fChecksum;
+ Kernel::UInt8 fDriveKind;
+ Kernel::UInt8 fEncoding;
+ Kernel::UInt64 fStartIND;
+ Kernel::UInt64 fEndIND;
+ Kernel::UInt64 fINodeCount;
+ Kernel::UInt64 fDiskSize;
+ Kernel::UInt16 fDiskStatus;
+ Kernel::UInt16 fDiskFlags;
+ Kernel::UInt16 fVID; // virtual identification number within an EPM disk.
+};
+
+/// @brief Access time type.
+/// @details Used to keep track of the INode, INodeDir allocation status.
+typedef Kernel::UInt64 ATime;
+
+inline constexpr ATime kHeFSTimeInvalid = 0x0000000000000000;
+inline constexpr ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF;
+
+/// @brief HeFS index node.
+/// @details This structure is used to store the file information of a file.
+/// @note The index node is a special type of INode that contains the file information.
+/// @note The index node is used to store the file information of a file.
+struct PACKED HeFS_INDEX_NODE final
+{
+ Kernel::Utf16Char fName[kHeFSFileNameLen];
+ Kernel::UInt32 fFlags;
+ Kernel::UInt16 fKind;
+ Kernel::UInt32 fSize;
+ Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, fLinkChecksum;
+
+ ATime fCreated, fAccessed, fModified, fDeleted;
+ Kernel::UInt32 fUID, fGID;
+ Kernel::UInt32 fMode;
+
+ Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount];
+ Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount];
+
+ Kernel::UInt64 fBlockStart[kHeFSBlockCount];
+ Kernel::UInt64 fBlockEnd[kHeFSBlockCount];
+
+ Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount];
+ Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount];
+
+ /// @brief Red-black tree pointers.
+ Kernel::Lba fNext, fPrev, fChild, fParent;
};
-struct PACKED HeFS_INDEX_NODE
+/// @brief HeFS directory node.
+/// @details This structure is used to store the directory information of a file.
+/// @note The directory node is a special type of INode that contains the directory entries.
+struct PACKED HeFS_INDEX_NODE_DIRECTORY final
{
- Kernel::Char fName[kHeFSFileNameLen];
+ Kernel::Utf16Char fName[kHeFSFileNameLen];
+
Kernel::UInt32 fFlags;
Kernel::UInt16 fKind;
Kernel::UInt32 fSize;
- Kernel::Lba fFirstINode;
- Kernel::Lba fLastINode;
- Kernel::UInt32 fChecksum;
-};
\ No newline at end of file + Kernel::UInt32 fChecksum, fIndexNodeChecksum;
+
+ ATime fCreated, fAccessed, fModified, fDeleted;
+ Kernel::UInt32 fUID, fGID;
+ Kernel::UInt32 fMode;
+
+ Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount];
+ Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount];
+
+ /// @brief Red-black tree pointers.
+ Kernel::Lba fNext, fPrev, fChild, fParent;
+};
+
+namespace Kernel::Detail
+{
+ /// @brief HeFS get year from ATime.
+ /// @param raw_atime the raw ATime value.
+ /// @return the year value.
+ /// @note The year is stored in the upper 32 bits of the ATime value.
+ inline UInt32 hefs_year_get(ATime raw_atime) noexcept
+ {
+ return (raw_atime & 0x00000000FFFFFFFF) >> 32;
+ }
+
+ /// @brief HeFS get month from ATime.
+ /// @param raw_atime the raw ATime value.
+ /// @return the month value.
+ /// @note The month is stored in the upper 24 bits of the ATime value.
+ inline UInt32 hefs_month_get(ATime raw_atime) noexcept
+ {
+ return (raw_atime & 0x00000000FFFFFFFF) >> 24;
+ }
+
+ /// @brief HeFS get day from ATime.
+ /// @param raw_atime the raw ATime value.
+ /// @return the day value.
+ /// @note The day is stored in the upper 16 bits of the ATime value.
+ inline UInt32 hefs_day_get(ATime raw_atime) noexcept
+ {
+ return (raw_atime & 0x00000000FFFFFFFF) >> 16;
+ }
+
+ /// @brief HeFS get hour from ATime.
+ /// @param raw_atime the raw ATime value.
+ /// @return the hour value.
+ /// @note The hour is stored in the upper 8 bits of the ATime value.
+ inline UInt32 hefs_hour_get(ATime raw_atime) noexcept
+ {
+ return (raw_atime & 0x00000000FFFFFFFF) >> 8;
+ }
+
+ /// @brief HeFS get minute from ATime.
+ /// @param raw_atime the raw ATime value.
+ /// @return the minute value.
+ /// @note The minute is stored in the lower 8 bits of the ATime value.
+ inline UInt32 hefs_minute_get(ATime raw_atime) noexcept
+ {
+ return (raw_atime & 0x00000000FFFFFFFF);
+ }
+
+ inline constexpr UInt32 kHeFSBaseYear = 1970;
+ inline constexpr UInt32 kHeFSBaseMonth = 1;
+ inline constexpr UInt32 kHeFSBaseDay = 1;
+ inline constexpr UInt32 kHeFSBaseHour = 0;
+ inline constexpr UInt32 kHeFSBaseMinute = 0;
+} // namespace Kernel::Detail
\ No newline at end of file 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 <FirmwareKit/EFI/EFI.h> +#include <FirmwareKit/GPT.h> /// @note this header is used to reference the EFI/EFI.h diff --git a/dev/kernel/FirmwareKit/EFI/EFI.h b/dev/kernel/FirmwareKit/EFI/EFI.h index 24f474d1..2772582b 100644 --- a/dev/kernel/FirmwareKit/EFI/EFI.h +++ b/dev/kernel/FirmwareKit/EFI/EFI.h @@ -380,25 +380,25 @@ typedef UInt8 EfiMacAddress[32]; typedef struct { - UInt32 State; - UInt32 HwAddressSize; - UInt32 MediaHeaderSize; - UInt32 MaxPacketSize; - UInt32 NvRamSize; - UInt32 NvRamAccessSize; - UInt32 ReceiveFilterMask; - UInt32 ReceiveFilterSetting; - UInt32 MaxMCastFilterCount; - UInt32 MCastFilterCount; + UInt32 State; + UInt32 HwAddressSize; + UInt32 MediaHeaderSize; + UInt32 MaxPacketSize; + UInt32 NvRamSize; + UInt32 NvRamAccessSize; + UInt32 ReceiveFilterMask; + UInt32 ReceiveFilterSetting; + UInt32 MaxMCastFilterCount; + UInt32 MCastFilterCount; EfiMacAddress MCastFilter[MAX_MCAST_FILTER_CNT]; EfiMacAddress CurrentAddress; EfiMacAddress BroadcastAddress; EfiMacAddress PermanentAddress; - UInt8 IfType; - BOOL MacAddressChangeable; - BOOL MultipleTxSupported; - BOOL MediaPresentSupported; - BOOL MediaPresent; + UInt8 IfType; + BOOL MacAddressChangeable; + BOOL MultipleTxSupported; + BOOL MediaPresentSupported; + BOOL MediaPresent; } EFI_SIMPLE_NETWORK_MODE; typedef EFI_STATUS(EFIAPI* EFI_SIMPLE_NETWORK_TRANSMIT)( diff --git a/dev/kernel/FirmwareKit/GPT.h b/dev/kernel/FirmwareKit/GPT.h index 0515af8a..dc2b5ce3 100644 --- a/dev/kernel/FirmwareKit/GPT.h +++ b/dev/kernel/FirmwareKit/GPT.h @@ -9,9 +9,11 @@ #include <NewKit/Defines.h> #include <FirmwareKit/EFI/EFI.h> -#define kSectorAlignGPT_PartTbl (420U) +#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/FirmwareKit/Handover.h b/dev/kernel/FirmwareKit/Handover.h index 4ff04e6d..3a5e9e19 100644 --- a/dev/kernel/FirmwareKit/Handover.h +++ b/dev/kernel/FirmwareKit/Handover.h @@ -75,11 +75,11 @@ namespace Kernel::HEL struct { - VoidPtr f_SmBios; - VoidPtr f_VendorPtr; - VoidPtr f_MpPtr; - Bool f_MultiProcessingEnabled; - UInt32 f_ImageKey; + VoidPtr f_SmBios; + VoidPtr f_VendorPtr; + VoidPtr f_MpPtr; + Bool f_MultiProcessingEnabled; + UInt32 f_ImageKey; EfiHandlePtr f_ImageHandle; } f_HardwareTables; @@ -98,9 +98,9 @@ namespace Kernel::HEL enum { - kHandoverSpecificKind, - kHandoverSpecificAttrib, - kHandoverSpecificMemoryEfi, + kHandoverTableBS, + kHandoverTableST, + kHandoverTableCount, }; /// @brief Alias of bootloader main type. 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 <modules/CoreGfx/CoreGfx.h> +#include <modules/CoreGfx/TextGfx.h> + +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<FBDevicePacket*> + { + 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/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index b716279d..7f3d4137 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -4,7 +4,6 @@ ------------------------------------------- */ -#include "modules/CoreGfx/CoreGfx.h" #include <StorageKit/AHCI.h> #include <ArchKit/ArchKit.h> #include <KernelKit/ProcessScheduler.h> @@ -15,16 +14,15 @@ #include <CFKit/Property.h> #include <modules/CoreGfx/TextGfx.h> #include <KernelKit/Timer.h> - +#include <modules/CoreGfx/CoreWindow.h> #include <FirmwareKit/EFI/API.h> #include <FirmwareKit/EFI/EFI.h> - EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; EXTERN_C Kernel::VoidPtr mp_user_switch_proc; EXTERN_C Kernel::Char mp_user_switch_proc_stack_begin[]; -STATIC Kernel::Void hal_init_scheduler_team() +STATIC Kernel::Void hal_pre_init_scheduler() { for (Kernel::SizeT i = 0U; i < Kernel::UserProcessScheduler::The().CurrentTeam().AsArray().Count(); ++i) { @@ -47,13 +45,9 @@ EXTERN_C Int32 hal_init_platform( FB::fb_clear_video(); - (Void)(Kernel::kout << "Welcome to NeKernel.\r"); - fw_init_efi((EfiSystemTable*)handover_hdr->f_FirmwareCustomTables[1]); Boot::ExitBootServices(handover_hdr->f_HardwareTables.f_ImageKey, handover_hdr->f_HardwareTables.f_ImageHandle); - hal_init_scheduler_team(); - /************************************** */ /* INITIALIZE BIT MAP. */ /************************************** */ @@ -92,6 +86,8 @@ EXTERN_C Int32 hal_init_platform( EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { + hal_pre_init_scheduler(); + Kernel::NeFS::fs_init_nefs(); Kernel::HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); @@ -103,5 +99,8 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept idt_loader.Load(idt_reg); - dbg_break_point(); + while (YES) + { + ; + } } diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index b813e1d9..f2e9c2ea 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -68,13 +68,13 @@ namespace Kernel::HAL /// @brief Memory Manager mapping flags. enum { - kMMFlagsInvalid = 1 << 0, - kMMFlagsPresent = 1 << 1, - kMMFlagsWr = 1 << 2, - kMMFlagsUser = 1 << 3, - kMMFlagsNX = 1 << 4, - kMMFlagsPCD = 1 << 5, - kMMFlagsCount = 4, + kMMFlagsInvalid = 1 << 0, + kMMFlagsPresent = 1 << 1, + kMMFlagsWr = 1 << 2, + kMMFlagsUser = 1 << 3, + kMMFlagsNX = 1 << 4, + kMMFlagsPCD = 1 << 5, + kMMFlagsCount = 4, }; struct PACKED Register64 final 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<AHCIDeviceInterface>(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/HALKit/ARM64/Processor.h b/dev/kernel/HALKit/ARM64/Processor.h index 4cead7ea..3a04bed1 100644 --- a/dev/kernel/HALKit/ARM64/Processor.h +++ b/dev/kernel/HALKit/ARM64/Processor.h @@ -28,7 +28,7 @@ namespace Kernel::HAL kMMFlagsWr = 1 << 1, kMMFlagsUser = 1 << 2, kMMFlagsNX = 1 << 3, - kMMFlagsPCD = 1 << 4, + kMMFlagsPCD = 1 << 4, kMMFlagsCount = 4, }; diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 03e74ee8..e5f67080 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -21,13 +21,9 @@ #ifndef INC_FILEMGR_H #define INC_FILEMGR_H -#ifdef __FSKIT_INCLUDES_NEFS__ -#include <FSKit/NeFS.h> -#endif // __FSKIT_INCLUDES_NEFS__ - -#ifdef __FSKIT_INCLUDES_HeFS__ +#include <FSKit/Ext2.h> #include <FSKit/HeFS.h> -#endif // __FSKIT_INCLUDES_HeFS__ +#include <FSKit/NeFS.h> #include <CompilerKit/CompilerKit.h> #include <hint/CompilerHint.h> @@ -55,7 +51,7 @@ @note Refer to first enum. */ #define kFileOpsCount (4U) -#define kFileMimeGeneric "n-application-kind/all" +#define kFileMimeGeneric "ne-application-kind/all" /** @brief invalid position. (n-pos) */ #define kNPos (SizeT)(-1); diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index a99fc45b..881f3957 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -7,8 +7,8 @@ #ifndef INC_PROCESS_SCHEDULER_H #define INC_PROCESS_SCHEDULER_H -/// @file ProcessScheduler.h -/// @brief Process scheduler code and definitions. +/// @file UserProcessScheduler.h +/// @brief User Process scheduler code and definitions. /// @author Amlal El Mahrouss (amlal@nekernel.org) #include <ArchKit/ArchKit.h> diff --git a/dev/kernel/KernelKit/UserProcessScheduler.inl b/dev/kernel/KernelKit/UserProcessScheduler.inl index d89d9aa1..ea57cf65 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.inl +++ b/dev/kernel/KernelKit/UserProcessScheduler.inl @@ -2,7 +2,7 @@ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - FILE: ProcessScheduler.inl + FILE: UserProcessScheduler.inl PURPOSE: Low level/Ring-3 Process scheduler. ------------------------------------------- */ diff --git a/dev/kernel/NewKit/Macros.h b/dev/kernel/NewKit/Macros.h index eda454f9..83dbc7b5 100644 --- a/dev/kernel/NewKit/Macros.h +++ b/dev/kernel/NewKit/Macros.h @@ -122,7 +122,7 @@ #define NE_UNUSED(X) ((Kernel::Void)X) #ifndef RGB -#define RGB(R, G, B) (Kernel::UInt32)(R | G << 0x8 | B << 0x10) +#define RGB(R, G, B) ((Kernel::UInt32)((0xFF << 24) | ((R) << 16) | ((G) << 8) | (B))) #endif // !RGB #ifdef __NE_AMD64__ 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<MountpointInterface*> { 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/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 <KernelKit/DriveMgr.h> #include <NewKit/Utils.h> #include <FirmwareKit/EPM.h> +#include <FirmwareKit/GPT.h> #include <modules/ATA/ATA.h> #include <modules/AHCI/AHCI.h> #include <modules/NVME/NVME.h> @@ -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/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 <KernelKit/FileMgr.h> +#include <KernelKit/MemoryMgr.h> + +#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 <KernelKit/FileMgr.h> +#include <KernelKit/MemoryMgr.h> + +#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 <KernelKit/FileMgr.h> -#include <KernelKit/MemoryMgr.h> - #ifndef __NE_MINIMAL_OS__ #ifdef __FSKIT_INCLUDES_NEFS__ +#include <KernelKit/FileMgr.h> +#include <KernelKit/MemoryMgr.h> + /// @brief NeFS File manager. /// BUGS: 0 diff --git a/dev/kernel/src/Gfx/FBDeviceInterface.cc b/dev/kernel/src/Gfx/FBDeviceInterface.cc new file mode 100644 index 00000000..c2eb2ca7 --- /dev/null +++ b/dev/kernel/src/Gfx/FBDeviceInterface.cc @@ -0,0 +1,69 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include <GfxKit/FB.h> + +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; + + 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; +} + +/// @brief Input operator. +/// @param mnt the disk mountpoint. +/// @return the class itself after operation. +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 + + 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. |
