diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-14 18:35:05 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-14 18:39:11 +0200 |
| commit | f8aaa274535b6541f376090958eedbbba3ba00ba (patch) | |
| tree | 420a4d41f339ac6e6f083099390dddcf59922cab /dev | |
| parent | 2b91067c894efde74e96fd9216598a5782699c7b (diff) | |
feat(kernel): Filesystem fixes, and others.
what?
- Add simple generic RTL8139 NIC driver, to be used within a NK device.
- Update IVT accordingly.
- Comment ARM's AP GIC init function, to tell what it's actually doing.
- Cleanup Kernel Main, removed the useless pre_init_scheduler function.
- Prepare new FileMgr with HeFileSystemMgr.
- Fallback to NeFS when trying to format a fileysstem.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/kernel/FSKit/HeFS.h | 13 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalAPICController.cc | 12 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalDebugPort.cc | 3 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalInterruptAPI.asm | 19 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalKernelMain.cc | 14 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc | 81 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/PIO+Generic+Next.cc | 280 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 42 | ||||
| -rw-r--r-- | dev/kernel/HALKit/ARM64/ApplicationProcessor.h | 3 | ||||
| -rw-r--r-- | dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/FileMgr.h | 48 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/PCI/DMA.h | 5 | ||||
| -rw-r--r-- | dev/kernel/NetworkKit/NetworkDevice.inl | 11 | ||||
| -rw-r--r-- | dev/kernel/amd64-desktop.make | 2 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS+FileSystemParser.cc | 10 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS+FileSystemParser.cc | 23 |
16 files changed, 216 insertions, 352 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 04a265f5..5f0dcddf 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -370,7 +370,7 @@ inline const Char* hefs_file_flags_to_string(UInt32 flags) noexcept { }
} // namespace Kernel::Detail
-namespace Kernel::HeFS {
+namespace Kernel {
/// @brief HeFS filesystem parser class.
/// @details This class is used to parse the HeFS filesystem.
class HeFileSystemParser final {
@@ -417,7 +417,10 @@ class HeFileSystemParser final { const Utf8Char* dir, const BOOL delete_or_create);
};
-/// @brief Initialize HeFS inside the main disk.
-/// @return Whether it successfuly formated it or not.
-Boolean fs_init_hefs(Void);
-} // namespace Kernel::HeFS
+namespace HeFS {
+
+ /// @brief Initialize HeFS inside the main disk.
+ /// @return Whether it successfuly formated it or not.
+ Boolean fs_init_hefs(Void) noexcept;
+} // namespace HeFS
+} // namespace Kernel
diff --git a/dev/kernel/HALKit/AMD64/HalAPICController.cc b/dev/kernel/HALKit/AMD64/HalAPICController.cc index 758e2f52..e547d982 100644 --- a/dev/kernel/HALKit/AMD64/HalAPICController.cc +++ b/dev/kernel/HALKit/AMD64/HalAPICController.cc @@ -7,8 +7,8 @@ #include <HALKit/AMD64/Processor.h> #include <modules/ACPI/ACPIFactoryInterface.h> -#define cIOAPICRegVal (4) -#define cIOAPICRegReg (0) +#define kIOAPICRegVal (4) +#define kIOAPICRegReg (0) namespace Kernel::HAL { APICController::APICController(VoidPtr base) : fApic(base) {} @@ -19,9 +19,9 @@ UInt32 APICController::Read(UInt32 reg) noexcept { MUST_PASS(this->fApic); UInt32 volatile* io_apic = (UInt32 volatile*) this->fApic; - io_apic[cIOAPICRegReg] = (reg & 0xFF); + io_apic[kIOAPICRegReg] = (reg & 0xFF); - return io_apic[cIOAPICRegVal]; + return io_apic[kIOAPICRegVal]; } /// @brief Write to APIC controller. @@ -32,7 +32,7 @@ Void APICController::Write(UInt32 reg, UInt32 value) noexcept { UInt32 volatile* io_apic = (UInt32 volatile*) this->fApic; - io_apic[cIOAPICRegReg] = (reg & 0xFF); - io_apic[cIOAPICRegVal] = value; + io_apic[kIOAPICRegReg] = (reg & 0xFF); + io_apic[kIOAPICRegVal] = value; } } // namespace Kernel::HAL diff --git a/dev/kernel/HALKit/AMD64/HalDebugPort.cc b/dev/kernel/HALKit/AMD64/HalDebugPort.cc index 105fcf47..4e0e2b7f 100644 --- a/dev/kernel/HALKit/AMD64/HalDebugPort.cc +++ b/dev/kernel/HALKit/AMD64/HalDebugPort.cc @@ -9,11 +9,12 @@ #include <ArchKit/ArchKit.h> #include <KernelKit/DebugOutput.h> +#include <NetworkKit/NetworkDevice.h> // after that we have start of additional data. namespace Kernel { -void rt_debug_listen(KernelDebugHeader* the_hdr) noexcept { +Void rt_debug_listen(KernelDebugHeader* the_hdr) noexcept { NE_UNUSED(the_hdr); } } // namespace Kernel diff --git a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm index cf2870c8..a6c6bbb5 100644 --- a/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm +++ b/dev/kernel/HALKit/AMD64/HalInterruptAPI.asm @@ -257,7 +257,24 @@ IntNormal 36 IntNormal 37 IntNormal 38 IntNormal 39 -IntNormal 40 + +[extern rtl_rtl8139_interrupt_handler] + +__NE_INT_40: + cld + + mov al, 0x20 + out 0xA0, al + out 0x20, al + + push rax + mov rcx, rsp + call rtl_rtl8139_interrupt_handler + pop rax + + std + + o64 iret IntNormal 41 diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 70b07193..2d213a9b 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -20,13 +20,6 @@ #ifndef __NE_MODULAR_KERNEL_COMPONENTS__ EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; -STATIC Kernel::Void hal_pre_init_scheduler() noexcept { - for (Kernel::SizeT i = 0U; - i < Kernel::UserProcessScheduler::The().CurrentTeam().AsArray().Count(); ++i) { - Kernel::UserProcessScheduler::The().CurrentTeam().AsArray()[i] = Kernel::USER_PROCESS(); - } -} - /// @brief Kernel init function. /// @param handover_hdr Handover boot header. EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { @@ -109,10 +102,11 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { } EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { - hal_pre_init_scheduler(); - #ifdef __FSKIT_INCLUDES_HEFS__ - Kernel::HeFS::fs_init_hefs(); + if (!Kernel::HeFS::fs_init_hefs()) { + // Fallback to NeFS, if HeFS doesn't work here. + Kernel::NeFS::fs_init_nefs(); + } #elif defined(__FSKIT_INCLUDES_NEFS__) Kernel::NeFS::fs_init_nefs(); #endif diff --git a/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc new file mode 100644 index 00000000..06c18d8b --- /dev/null +++ b/dev/kernel/HALKit/AMD64/Network/Generic+Basic+RTL8139.cc @@ -0,0 +1,81 @@ +/* ------------------------------------------- + +Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include <HALKit/AMD64/Processor.h> +#include <StorageKit/DmaPool.h> +#include <modules/ACPI/ACPIFactoryInterface.h> + +using namespace Kernel; +using namespace Kernel::HAL; + +STATIC UInt16 kIOBase = 0xFFFF; + +STATIC UInt32 kRXOffset = 0UL; +STATIC constexpr const UInt32 kRxBufferSize = 8192 + 16 + 1500; + +STATIC BOOL kTXEnabled = NO; + +STATIC UInt8* kRXUpperLayer = nullptr; +STATIC UInt8* kRxBuffer = nullptr; + +EXTERN_C Void rtl_init_nic_rtl8139(UInt16 io_base) noexcept { + if (kTXEnabled) return; + + kIOBase = io_base; + MUST_PASS(io_base); + + kRxBuffer = (UInt8*) rtl_dma_alloc(sizeof(UInt8) * kRxBufferSize, 0); + + MUST_PASS(kRxBuffer); + + /// Reset first. + + rt_out8(io_base + 0x37, 0x10); + + UInt16 timeout = 0U; + + while (rt_in8(io_base + 0x37) & 0x10) { + ++timeout; + if (timeout > 0x1000) break; + } + + MUST_PASS(timeout <= 0x1000); + + rt_out32(io_base + 0x30, (UInt32) (UIntPtr) kRxBuffer); + + rt_out8(io_base + 0x37, 0x0C); + + rt_out32(io_base + 0x44, 0xf | (1 << 7)); + + // Enable IRQ. + rt_out16(io_base + 0x3C, 0x0005); + + kTXEnabled = YES; +} + +EXTERN_C void rtl_rtl8139_interrupt_handler() { + if (kIOBase == 0xFFFF) return; + + UInt16 status = rt_in16(kIOBase + 0x3E); + rt_out16(kIOBase + 0x3E, status); + + if (status & 0x01) { + while ((rt_in8(kIOBase + 0x37) & 0x01) == 0) { + UInt32 offset = kRXOffset % kRxBufferSize; + volatile UInt8* packet = kRxBuffer + offset + 4; + UInt16 len = *(UInt16*) (kRxBuffer + offset + 2); + + kRXUpperLayer[offset + 4] = *packet; + + kRXOffset += len + 4; + rt_out16(kIOBase + 0x38, (UInt16) (kRXOffset - 16)); + } + } + + if (!(status & 0x04)) { + err_global_get() = kErrorNoNetwork; + } +}
\ No newline at end of file diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic+Next.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic+Next.cc deleted file mode 100644 index dd6b9aea..00000000 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic+Next.cc +++ /dev/null @@ -1,280 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -/** - * @file PIO+Generic.cc - * @author Amlal El Mahrouss (amlal@nekernel.org) - * @brief ATA driver (PIO mode). - * @version 0.1 - * @date 2024-02-02 - * - * @copyright Copyright (c) Amlal El Mahrouss - * - */ - -#if 0 - -#include <ArchKit/ArchKit.h> -#include <KernelKit/DriveMgr.h> -#include <StorageKit/ATA.h> -#include <modules/ATA/ATA.h> - -using namespace Kernel; -using namespace Kernel::HAL; - -/// BUGS: 0 - -#define kATADataLen 256 - -STATIC Boolean kATADetected = false; -STATIC UInt16 kATAIdentifyData[kATADataLen] = {0}; -STATIC Char kATADiskModel[50] = {"GENERIC PIO"}; - -static Boolean drv_pio_std_wait_io(UInt16 IO) { - for (int i = 0; i < 400; i++) rt_in8(IO + ATA_REG_STATUS); - -ATAWaitForIO_Retry: - auto stat_rdy = rt_in8(IO + ATA_REG_STATUS); - - if ((stat_rdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; - -ATAWaitForIO_Retry2: - stat_rdy = rt_in8(IO + ATA_REG_STATUS); - - if (stat_rdy & ATA_SR_ERR) return false; - - if (!(stat_rdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; - - return true; -} - -STATIC Void drv_pio_std_select(UInt16 Bus) { - if (Bus == ATA_PRIMARY_IO) - rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); - else - rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); -} - -Boolean drv_pio_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { - UInt16 IO = Bus; - - NE_UNUSED(Drive); - - drv_pio_std_select(IO); - - // Bus init, NEIN bit. - rt_out8(IO + ATA_REG_NEIN, 1); - - // identify until it's good. -ATAInit_Retry: - auto stat_rdy = rt_in8(IO + ATA_REG_STATUS); - - if (stat_rdy & ATA_SR_ERR) { - return false; - } - - if ((stat_rdy & ATA_SR_BSY)) goto ATAInit_Retry; - - OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; - OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - - drv_pio_std_select(IO); - - rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); - - - /// fetch serial info - /// model, speed, number of sectors... - - for (SizeT i = 0ul; i < kATADataLen; ++i) { - kATAIdentifyData[i] = rt_in16(OutBus + ATA_REG_DATA); - } - - for (Int32 i = 0; i < 20; i++) { - kATADiskModel[i * 2] = (kATAIdentifyData[27 + i] >> 8) & 0xFF; - kATADiskModel[i * 2 + 1] = kATAIdentifyData[27 + i] & 0xFF; - } - - kATADiskModel[40] = '\0'; - - (Void)(kout << "Drive Model: " << kATADiskModel << kendl); - - return true; -} - -Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { - Lba /= SectorSz; - - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - - drv_pio_std_wait_io(IO); - drv_pio_std_select(IO); - - rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - - rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - - rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); - rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); - rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); - rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); - - rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); - - for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { - drv_pio_std_wait_io(IO); - - auto in = rt_in16(IO + ATA_REG_DATA); - - Buf[IndexOff] = in & 0xFF; - Buf[IndexOff + 1] = (in >> 8) & 0xFF; - } -} - -Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { - Lba /= SectorSz; - - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - - drv_pio_std_wait_io(IO); - drv_pio_std_select(IO); - - rt_out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - - rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - - rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); - rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); - rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); - rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); - - rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); - - for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { - drv_pio_std_wait_io(IO); - - UInt8 low = (UInt8)Buf[IndexOff]; - UInt8 high = (IndexOff + 1 < Size) ? (UInt8)Buf[IndexOff + 1] : 0; - UInt16 packed = (high << 8) | low; - - rt_out16(IO + ATA_REG_DATA, packed); - } -} - -/// @brief is ATA detected? -Boolean drv_pio_std_detected(Void) { - return kATADetected; -} - -/*** - @brief Getter, gets the number of sectors inside the drive. - */ -SizeT drv_pio_get_sector_count() { - return (kATAIdentifyData[61] << 16) | kATAIdentifyData[60]; -} - -/// @brief Get the drive size. -SizeT drv_pio_get_size() { - return (drv_pio_get_sector_count()) * kATASectorSize; -} - -namespace Kernel { -/// @brief Initialize an PIO device (StorageKit function) -/// @param is_master is the current PIO master? -/// @return [io:master] for PIO device. -BOOL sk_init_ata_device(BOOL is_master, UInt16& io, UInt8& master) { - return drv_pio_std_init(ATA_SECONDARY_IO, is_master, io, master); -} - -/// @brief Implementation details namespace. -namespace Detail { - /// @brief Read PIO device. - /// @param self device - /// @param mnt mounted disk. - STATIC Void sk_io_read_pio(IDeviceObject<MountpointInterface*>* self, MountpointInterface* mnt) { - ATADeviceInterface* dev = (ATADeviceInterface*) self; - - err_global_get() = kErrorDisk; - - if (!dev) return; - - auto disk = mnt->GetAddressOf(dev->GetIndex()); - - if (!disk) return; - - err_global_get() = kErrorSuccess; - - drv_pio_std_read(disk->fPacket.fPacketLba, dev->GetIO(), dev->GetMaster(), - (Char*) disk->fPacket.fPacketContent, kATASectorSize, - disk->fPacket.fPacketSize); - } - - /// @brief Write PIO device. - /// @param self device - /// @param mnt mounted disk. - STATIC Void sk_io_write_pio(IDeviceObject<MountpointInterface*>* self, MountpointInterface* mnt) { - ATADeviceInterface* dev = (ATADeviceInterface*) self; - - err_global_get() = kErrorDisk; - - if (!dev) return; - - auto disk = mnt->GetAddressOf(dev->GetIndex()); - - if (!disk) return; - - err_global_get() = kErrorSuccess; - - drv_pio_std_write(disk->fPacket.fPacketLba, dev->GetIO(), dev->GetMaster(), - (Char*) disk->fPacket.fPacketContent, kATASectorSize, - disk->fPacket.fPacketSize); - } -} // namespace Detail - -/// @brief Acquires a new PIO device with drv_index in mind. -/// @param drv_index The drive index to assign. -/// @return A wrapped device interface if successful, or error code. -ErrorOr<ATADeviceInterface> sk_acquire_ata_device(Int32 drv_index) { - /// 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); - - device.SetIndex(drv_index); - - return ErrorOr<ATADeviceInterface>(device); -} -} // namespace Kernel - -#ifdef __ATA_PIO__ - -Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { - drv_pio_std_read(Lba, IO, Master, Buf, SectorSz, Size); -} - -Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorSz, SizeT Size) { - drv_pio_std_write(Lba, IO, Master, Buf, SectorSz, Size); -} - -SizeT drv_std_get_size() { - return drv_pio_get_size(); -} - -SizeT drv_std_get_sector_count() { - return drv_pio_get_sector_count(); -} - -Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { - return drv_pio_std_init(Bus, Drive, OutBus, OutMaster); -} - -#endif - -#endif
\ No newline at end of file diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index aec21ee4..dd6b9aea 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -15,6 +15,8 @@ * */ +#if 0 + #include <ArchKit/ArchKit.h> #include <KernelKit/DriveMgr.h> #include <StorageKit/ATA.h> @@ -49,7 +51,7 @@ ATAWaitForIO_Retry2: return true; } -static Void drv_pio_std_select(UInt16 Bus) { +STATIC Void drv_pio_std_select(UInt16 Bus) { if (Bus == ATA_PRIMARY_IO) rt_out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); else @@ -79,15 +81,18 @@ ATAInit_Retry: OutBus = (Bus == ATA_PRIMARY_IO) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO; OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; + drv_pio_std_select(IO); + rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - drv_pio_std_wait_io(IO); + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + /// fetch serial info /// model, speed, number of sectors... for (SizeT i = 0ul; i < kATADataLen; ++i) { - kATAIdentifyData[i] = HAL::rt_in16(OutBus + ATA_REG_DATA); + kATAIdentifyData[i] = rt_in16(OutBus + ATA_REG_DATA); } for (Int32 i = 0; i < 20; i++) { @@ -99,10 +104,6 @@ ATAInit_Retry: (Void)(kout << "Drive Model: " << kATADiskModel << kendl); - // Why? the current disk driver writes whole word instead of a single byte (expected btw) so i'm - // planning to finish +Next drivers for 0.0.3 - ke_panic(RUNTIME_CHECK_INVALID, "PIO driver is currently being reworked."); - return true; } @@ -118,16 +119,22 @@ Void drv_pio_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sect rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + + for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { drv_pio_std_wait_io(IO); - Buf[IndexOff] = HAL::rt_in16(IO + ATA_REG_DATA); + + auto in = rt_in16(IO + ATA_REG_DATA); + + Buf[IndexOff] = in & 0xFF; + Buf[IndexOff + 1] = (in >> 8) & 0xFF; } } @@ -143,16 +150,23 @@ Void drv_pio_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT Sec rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + + for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { drv_pio_std_wait_io(IO); - rt_out16(IO + ATA_REG_DATA, Buf[IndexOff]); + + UInt8 low = (UInt8)Buf[IndexOff]; + UInt8 high = (IndexOff + 1 < Size) ? (UInt8)Buf[IndexOff + 1] : 0; + UInt16 packed = (high << 8) | low; + + rt_out16(IO + ATA_REG_DATA, packed); } } @@ -261,4 +275,6 @@ Boolean drv_std_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) return drv_pio_std_init(Bus, Drive, OutBus, OutMaster); } +#endif + #endif
\ No newline at end of file diff --git a/dev/kernel/HALKit/ARM64/ApplicationProcessor.h b/dev/kernel/HALKit/ARM64/ApplicationProcessor.h index f48c1483..75f4eb07 100644 --- a/dev/kernel/HALKit/ARM64/ApplicationProcessor.h +++ b/dev/kernel/HALKit/ARM64/ApplicationProcessor.h @@ -10,7 +10,8 @@ #include <NewKit/Defines.h> /************************************************** */ -/* INITIALIZE THE GIC ON CPU. */ +/* INITIALIZE THE GIC ON THE CURRENT CORE. */ +/* WITH AN EXECUTION LEVEL IN MIND. */ /************************************************** */ namespace Kernel { diff --git a/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc b/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc index 7e55aa07..a89702ea 100644 --- a/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/ARM64/HalApplicationProcessor.cc @@ -122,6 +122,8 @@ EXTERN_C Bool mp_register_process(HAL::StackFramePtr stack_frame, ProcessID pid) return YES;
}
+/// @internal
+/// @brief Initialize the Global Interrupt Controller.
BOOL mp_initialize_gic(Void) {
if (!Detail::kGICEnabled) {
Detail::kGICEnabled = YES;
diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 2c4b2055..6751b0a8 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -36,7 +36,7 @@ #include <hint/CompilerHint.h> /// @brief Filesystem manager, abstraction over mounted filesystem. -/// Works like the VFS or IFS subsystem. +/// Works like an VFS (Virtual File System) or IFS subsystem on NT/OS 2. #define kRestrictR "r" #define kRestrictRB "rb" @@ -176,6 +176,52 @@ class NeFileSystemMgr final : public IFilesystemMgr { #endif // ifdef __FSKIT_INCLUDES_NEFS__ +#ifdef __FSKIT_INCLUDES_HEFS__ +/** + * @brief Based of IFilesystemMgr, takes care of managing NeFS + * disks. + */ +class HeFileSystemMgr final : public IFilesystemMgr { + public: + explicit HeFileSystemMgr(); + ~HeFileSystemMgr() override; + + public: + NE_COPY_DEFAULT(HeFileSystemMgr) + + public: + NodePtr Create(const Char* path) override; + NodePtr CreateAlias(const Char* path) override; + NodePtr CreateDirectory(const Char* path) override; + NodePtr CreateSwapFile(const Char* path) override; + + public: + bool Remove(_Input const Char* path) override; + NodePtr Open(_Input const Char* path, _Input const Char* r) override; + Void Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, + _Input SizeT sz) override; + VoidPtr Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT sz) override; + bool Seek(_Input NodePtr node, _Input SizeT off) override; + SizeT Tell(_Input NodePtr node) override; + bool Rewind(_Input NodePtr node) override; + + Void Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data, _Input Int32 flags, + _Input SizeT size) override; + + _Output VoidPtr Read(_Input const Char* name, _Input NodePtr node, _Input Int32 flags, + _Input SizeT sz) override; + + public: + /// @brief Get NeFS parser class. + /// @return The filesystem parser class. + HeFileSystemParser* GetParser() noexcept; + + private: + HeFileSystemParser* mParser{nullptr}; +}; + +#endif // ifdef __FSKIT_INCLUDES_HEFS__ + /** * FileStream class. * @tparam Encoding file encoding (char, wchar_t...) diff --git a/dev/kernel/KernelKit/PCI/DMA.h b/dev/kernel/KernelKit/PCI/DMA.h index 66d64f61..cad27a7a 100644 --- a/dev/kernel/KernelKit/PCI/DMA.h +++ b/dev/kernel/KernelKit/PCI/DMA.h @@ -14,11 +14,12 @@ namespace Kernel { enum class DmaKind { - PCI, // Bus mastering is required to be turned on. Basiaclly a request + PCI = 10, // Bus mastering is required to be turned on. Basiaclly a request // control system. 64-Bit access depends on the PAE bit and the device // (if Double Address Cycle is available) ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM. - Invalid, + Count = 2, + Invalid = 0, }; class DMAWrapper final { diff --git a/dev/kernel/NetworkKit/NetworkDevice.inl b/dev/kernel/NetworkKit/NetworkDevice.inl index 797b8adc..812c0248 100644 --- a/dev/kernel/NetworkKit/NetworkDevice.inl +++ b/dev/kernel/NetworkKit/NetworkDevice.inl @@ -9,17 +9,18 @@ */ namespace Kernel { -NetworkDevice::NetworkDevice(void (*out)(IDeviceObject<NetworkDeviceCommand>*, - NetworkDeviceCommand), - void (*in)(IDeviceObject<NetworkDeviceCommand>*, NetworkDeviceCommand), - void (*on_cleanup)(void)) +inline NetworkDevice::NetworkDevice(void (*out)(IDeviceObject<NetworkDeviceCommand>*, + NetworkDeviceCommand), + void (*in)(IDeviceObject<NetworkDeviceCommand>*, + NetworkDeviceCommand), + void (*on_cleanup)(void)) : IDeviceObject<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) { kout << "NetworkDevice initialized.\r"; MUST_PASS(out && in && on_cleanup); } -NetworkDevice::~NetworkDevice() { +inline NetworkDevice::~NetworkDevice() { MUST_PASS(fCleanup); kout << "NetworkDevice cleanup.\r"; diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index f13bc63a..0358bd0a 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 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) + $(CXX) $(CCFLAGS) $(DISK_DRV) $(DEBUG_MACRO) $(wildcard src/*.cc) $(wildcard src/Gfx/*.cc) $(wildcard HALKit/AMD64/Network/*.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/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 70a31154..d4aa1ee3 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -742,7 +742,7 @@ namespace Detail { /// real-time. /// @note This is certainly take longer to format a disk with it, but worth-it in the long run. -namespace Kernel::HeFS { +namespace Kernel { /// @brief Make a EPM+HeFS mnt out of the disk. /// @param mnt The mnt to write on. /// @return If it was sucessful, see err_local_get(). @@ -1142,7 +1142,7 @@ STATIC DriveTrait kMountPoint; /// @brief Initialize the HeFS filesystem. /// @return To check its status, see err_local_get(). -Boolean fs_init_hefs(Void) { +Boolean HeFS::fs_init_hefs(Void) noexcept { kout << "Creating HeFS disk...\r"; kMountPoint = io_construct_main_drive(); @@ -1152,10 +1152,8 @@ Boolean fs_init_hefs(Void) { HeFileSystemParser parser; - parser.Format(&kMountPoint, kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName); - - return YES; + return parser.Format(&kMountPoint, kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName); } -} // namespace Kernel::HeFS +} // namespace Kernel #endif // ifdef __FSKIT_INCLUDES_HEFS__ diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index 0b818bbb..49673b59 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -444,6 +444,8 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I NEFS_ROOT_PARTITION_BLOCK* part_block = (NEFS_ROOT_PARTITION_BLOCK*) fs_buf; + if (rt_string_cmp(kNeFSIdent, part_block->Ident, kNeFSIdentLen) == 0) return true; + const auto kNeFSUntitledHD = part_name; rt_copy_memory((VoidPtr) kNeFSIdent, (VoidPtr) part_block->Ident, kNeFSIdentLen); @@ -463,6 +465,7 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT) - 1; part_block->SectorCount = sectorCount; part_block->DiskSize = diskSize; + part_block->SectorSize = drive->fSectorSz; part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT) - 1; drive->fPacket.fPacketContent = fs_buf; @@ -479,26 +482,6 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I (Void)(kout << "Free sectors: " << hex_number(part_block->FreeSectors) << kendl); (Void)(kout << "Sector size: " << hex_number(part_block->SectorSize) << kendl); - NEFS_CATALOG_STRUCT root{}; - - rt_set_memory(&root, 0, sizeof(NEFS_CATALOG_STRUCT)); - - root.PrevSibling = part_block->StartCatalog; - root.NextSibling = 0UL; - - root.Kind = kNeFSCatalogKindDir; - root.Flags |= kNeFSFlagCreated; - root.CatalogFlags |= kNeFSStatusUnlocked; - - root.Name[0] = '/'; - root.Name[1] = 0; - - drive->fPacket.fPacketLba = part_block->StartCatalog; - drive->fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); - drive->fPacket.fPacketContent = &root; - - drive->fOutput(drive->fPacket); - return true; } |
