diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-23 11:12:31 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-23 11:13:38 +0200 |
| commit | 54a0f4c49d9bfb955174c87dae2f442d7f5a8b25 (patch) | |
| tree | ad59d31c9444fcfc6d5f0da7b17c8843710e6014 | |
| parent | fc67c4af554189c941c811486a0b2b21aa3f54ea (diff) | |
feat!(Kernel): Improvements on the BitMapMgr, HTS, and UPS.
other:
- Add ZXD header file.
- Reworking AMD64 interrupts.
- Improved HTS's design implementation.
- Improved UPS's balancing implementation.
breaking changes:
- Rename MemoryMgr to HeapMgr.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
37 files changed, 334 insertions, 448 deletions
diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc deleted file mode 100644 index 903a650d..00000000 --- a/dev/boot/src/HEL/AMD64/BootATA.cc +++ /dev/null @@ -1,256 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -/** - * @file BootATA.cc - * @author Amlal El Mahrouss (amlal@nekernel.org) - * @brief ATA driver. - * @version 0.1 - * @date 2024-02-02 - * - * @copyright Copyright (c) Amlal El Mahrouss - * - */ - -#include <BootKit/BootKit.h> -#include <BootKit/HW/ATA.h> -#include <FirmwareKit/EFI.h> - -#define kATADataLen (256) - -/// bugs: 0 - -using namespace Boot; - -static Boolean kATADetected = false; -static UInt16 kATAData[kATADataLen] = {0}; - -Boolean boot_ata_detected(Void); - -STATIC Boolean boot_ata_wait_io(UInt16 IO) { - for (int i = 0; i < 400; i++) rt_in8(IO + ATA_REG_STATUS); - -ATAWaitForIO_Retry: - auto status_rdy = rt_in8(IO + ATA_REG_STATUS); - - if ((status_rdy & ATA_SR_BSY)) goto ATAWaitForIO_Retry; - -ATAWaitForIO_Retry2: - status_rdy = rt_in8(IO + ATA_REG_STATUS); - - if (status_rdy & ATA_SR_ERR) return false; - - if (!(status_rdy & ATA_SR_DRDY)) goto ATAWaitForIO_Retry2; - - return true; -} - -Void boot_ata_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 boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { - NE_UNUSED(Drive); - - if (boot_ata_detected()) return true; - - BootTextWriter writer; - - UInt16 IO = Bus; - - boot_ata_select(IO); - - // Bus init, NEIN bit. - rt_out8(IO + ATA_REG_NEIN, 1); - - // identify until it's good. -ATAInit_Retry: - auto status_rdy = rt_in8(IO + ATA_REG_STATUS); - - if (status_rdy & ATA_SR_ERR) { - writer.Write(L"BootZ: ATA: Not an IDE based drive.\r"); - - return false; - } - - if ((status_rdy & ATA_SR_BSY)) goto ATAInit_Retry; - - rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - - /// fetch serial info - /// model, speed, number of sectors... - - boot_ata_wait_io(IO); - - for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { - kATAData[indexData] = Kernel::HAL::rt_in16(IO + ATA_REG_DATA); - } - - OutBus = (Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary; - - OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - - // 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 - return NO; -} - -Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, SizeT SectorSz, - SizeT Size) { - Lba /= SectorSz; - - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - - boot_ata_wait_io(IO); - boot_ata_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); - - boot_ata_wait_io(IO); - - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { - boot_ata_wait_io(IO); - Buf[IndexOff] = Kernel::HAL::rt_in16(IO + ATA_REG_DATA); - boot_ata_wait_io(IO); - } -} - -Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, SizeT SectorSz, - SizeT Size) { - Lba /= SectorSz; - - UInt8 Command = ((!Master) ? 0xE0 : 0xF0); - - boot_ata_wait_io(IO); - boot_ata_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); - - boot_ata_wait_io(IO); - - for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { - boot_ata_wait_io(IO); - rt_out16(IO + ATA_REG_DATA, Buf[IndexOff]); - boot_ata_wait_io(IO); - } - - boot_ata_wait_io(IO); -} - -/// @check is ATA detected? -Boolean boot_ata_detected(Void) { - return kATADetected; -} - -/*** - * - * - * @brief ATA Device class. - * - * - */ - -/** - * @brief ATA Device constructor. - * @param void none. - */ -BootDeviceATA::BootDeviceATA() noexcept { - if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus, this->Leak().mMaster) || - boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, this->Leak().mMaster)) { - kATADetected = true; - } -} -/** - * @brief Is ATA detected? - */ -BootDeviceATA::operator bool() { - return boot_ata_detected(); -} - -/** - @brief Read Buf from disk - @param Sz Sector size - @param Buf buffer -*/ -BootDeviceATA& BootDeviceATA::Read(CharacterTypeASCII* Buf, SizeT SectorSz) { - if (!boot_ata_detected()) { - Leak().mErr = true; - return *this; - } - - this->Leak().mErr = false; - - if (!Buf || SectorSz < 1) return *this; - - boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, - this->Leak().mSize); - - return *this; -} - -/** - @brief Write Buf into disk - @param Sz Sector size - @param Buf buffer -*/ -BootDeviceATA& BootDeviceATA::Write(CharacterTypeASCII* Buf, SizeT SectorSz) { - if (!boot_ata_detected()) { - Leak().mErr = true; - return *this; - } - - Leak().mErr = false; - - if (!Buf || SectorSz < 1 || this->Leak().mSize < 1) { - Leak().mErr = true; - return *this; - } - - boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, - this->Leak().mSize); - - return *this; -} - -/** - * @brief ATA trait getter. - * @return BootDeviceATA::ATATrait& the drive config. - */ -BootDeviceATA::ATATrait& BootDeviceATA::Leak() { - return mTrait; -} - -/*** - @brief Getter, gets the number of sectors inside the drive. -*/ -SizeT BootDeviceATA::GetSectorsCount() noexcept { - return (kATAData[61] << 16) | kATAData[60]; -} - -SizeT BootDeviceATA::GetDiskSize() noexcept { - return this->GetSectorsCount() * BootDeviceATA::kSectorSize; -} diff --git a/dev/boot/src/HEL/AMD64/BootATA+Next.cc b/dev/boot/src/HEL/AMD64/BootATAcc index 547d4f99..4fd6dc16 100644 --- a/dev/boot/src/HEL/AMD64/BootATA+Next.cc +++ b/dev/boot/src/HEL/AMD64/BootATAcc @@ -15,8 +15,6 @@ * */ -#if 0 - #include <BootKit/BootKit.h> #include <BootKit/HW/ATA.h> #include <FirmwareKit/EFI.h> @@ -266,5 +264,3 @@ SizeT BootDeviceATA::GetSectorsCount() noexcept { SizeT BootDeviceATA::GetDiskSize() noexcept { return this->GetSectorsCount() * BootDeviceATA::kSectorSize; } - -#endif
\ No newline at end of file diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 1d46b731..84a4d295 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -196,16 +196,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa WideChar kernel_path[256U] = L"krnl.efi"; UInt32 kernel_path_sz = StrLen("krnl.efi"); - if (ST->RuntimeServices->GetVariable(L"/props/kernel_path", kEfiGlobalNamespaceVarGUID, nullptr, - &kernel_path_sz, kernel_path) != kEfiOk) { - /// access attributes (in order) - /// EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS - UInt32 attr = 0x00000001 | 0x00000002 | 0x00000004; - - ST->RuntimeServices->SetVariable(L"/props/kernel_path", kEfiGlobalNamespaceVarGUID, &attr, - &kernel_path_sz, kernel_path); - } - UInt32 sz_ver = sizeof(UInt64); UInt64 ver = KERNEL_VERSION_BCD; @@ -219,6 +209,16 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa &sz_ver, &ver); writer.Write("BootZ: Version has been updated: ").Write(ver).Write("\r"); + + if (ST->RuntimeServices->GetVariable(L"/props/kernel_path", kEfiGlobalNamespaceVarGUID, nullptr, + &kernel_path_sz, kernel_path) != kEfiOk) { + /// access attributes (in order) + /// EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS + UInt32 attr = 0x00000001 | 0x00000002 | 0x00000004; + + ST->RuntimeServices->SetVariable(L"/props/kernel_path", kEfiGlobalNamespaceVarGUID, &attr, + &kernel_path_sz, kernel_path); + } } else { writer.Write("BootZ: Version: ").Write(ver).Write("\r"); } diff --git a/dev/boot/src/docs/KERN_VER.md b/dev/boot/src/docs/KERN_VER.md index cabdb1d2..0659431b 100644 --- a/dev/boot/src/docs/KERN_VER.md +++ b/dev/boot/src/docs/KERN_VER.md @@ -1,6 +1,18 @@ -# The `/props/kern_ver` NVRAM variable +# `/props/kern_ver` โ NVRAM EFI Variable The `/props/kern_ver` variable is used to track NeKernel's current version in a BCD format. -- Use it to track the current's NeKernel version, in order to adapt your drivers to it. -- It is also useful to keep track of it, for other purposes (bug tracking, development of new features)
\ No newline at end of file +## ๐ Reason + +- It is also used for: + - Bug tracking and system patching. + - Version and compatibility checking. + +## ๐งช Usage + +N/A + +## ยฉ License + + Copyright (C) 2025, + Amlal El Mahrouss โ All rights reserved.
\ No newline at end of file diff --git a/dev/boot/src/docs/MKFS_HEFS.md b/dev/boot/src/docs/MKFS_HEFS.md new file mode 100644 index 00000000..c9aa0628 --- /dev/null +++ b/dev/boot/src/docs/MKFS_HEFS.md @@ -0,0 +1,106 @@ +# `mkfs.hefs` โ HeFS Filesystem Formatter + +`mkfs.hefs` is a command-line utility used to format a block device or disk image with the **High-throughput Extended File System (HeFS)** used by NeKernel. This tool initializes a HeFS volume by writing a boot node and configuring directory and inode index regions, block ranges, and volume metadata. + +--- + +## ๐ Features + +- Writes a valid `BootNode` to the specified output device or file. +- Sets disk size, sector size, and volume label. +- Supports user-defined ranges for: + - Index Node Directory (IND) + - Inodes (IN) + - Data blocks +- UTF-8 encoded volume label support. +- Fully compatible with NeKernel's VFS subsystem. + +--- + +## ๐งช Usage + + mkfs.hefs -L <label> -s <sector_size> \ + -b <ind_start> -e <ind_end> \ + -bs <block_start> -be <block_end> \ + -is <in_start> -ie <in_end> \ + -S <disk_size> -o <output_device> + +--- + +## ๐งพ Arguments + +| Option | Description | +|---------------|-------------------------------------------------------------------------| +| `-L` | Volume label (UTF-8, internally stored as UTF-16) | +| `-s` | Sector size (e.g., 512) | +| `-b` `-e` | Start and end addresses for the **Index Node Directory (IND)** region | +| `-bs` `-be` | Start and end addresses for the **Block** data region | +| `-is` `-ie` | Start and end addresses for the **Inode** region | +| `-S` | Disk size in **gigabytes** | +| `-o` | Path to the output device or image file | + +> All address-based inputs (`-b`, `-e`, etc.) must be specified in **hexadecimal** format. + +--- + +## ๐งท Notes + +- Default sector size is `512` bytes. +- Default volume name is `"HeFS_VOLUME"`, defined as `kHeFSDefaultVolumeName`. +- The tool writes a `BootNode` at the beginning of the index node range. +- A CRC-safe magic signature is embedded for boot and integrity validation. +- After writing the metadata, the tool flushes and closes the file stream. + +--- + +## ๐ป Example + + mkfs.hefs -L "MyHeFS" -s 512 \ + -b 0x1000 -e 0x8000 \ + -bs 0x8000 -be 0x800000 \ + -is 0x800000 -ie 0xA00000 \ + -S 128 -o hefs.img + +This will create a 128 GiB formatted HeFS image named `hefs.img` with specified region boundaries. + +--- + +## ๐ BootNode Structure + +The `BootNode` stores key filesystem metadata: + + struct BootNode { + char magic[8]; + char16_t volumeName[64]; + uint16_t version; + uint16_t diskKind; + uint16_t encoding; + uint64_t diskSize; + uint32_t sectorSize; + uint64_t startIND, endIND; + uint64_t startIN, endIN; + uint64_t startBlock, endBlock; + uint64_t indCount; + uint16_t diskStatus; + }; + +--- + +## โ ๏ธ Error Handling + +- Prints usage and exits on invalid/missing arguments. +- Exits with error if the output device cannot be opened or written to. +- Checks for zero sector size or disk size to prevent invalid formatting. + +--- + +## ๐ Source Location + +Part of the [HeFS Tooling module](https://github.com/nekernel-org/nekernel) and used during system setup or disk preparation for NeKernel. + +--- + +## ยฉ License + + Copyright (C) 2025, + Amlal El Mahrouss โ All rights reserved.
\ No newline at end of file diff --git a/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc b/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc index e2b89765..1d289db8 100644 --- a/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc +++ b/dev/kernel/HALKit/AMD64/HalACPIFactoryInterface.cc @@ -6,7 +6,7 @@ #include <ArchKit/ArchKit.h> #include <HALKit/AMD64/Processor.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> #include <NeKit/KString.h> #include <modules/ACPI/ACPIFactoryInterface.h> diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index 17d4690f..7926289f 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -121,8 +121,6 @@ EXTERN_C BOOL mp_register_task(HAL::StackFramePtr stack_frame, ProcessID thrdid) HardwareThreadScheduler::The()[thrdid].Leak()->Busy(NO); - sched_jump_to_task(stack_frame); - return YES; } diff --git a/dev/kernel/HALKit/AMD64/HalAPStartup.s b/dev/kernel/HALKit/AMD64/HalApplicationProcessorStartup.s index ec17bf7b..903038ea 100644 --- a/dev/kernel/HALKit/AMD64/HalAPStartup.s +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessorStartup.s @@ -1,4 +1,4 @@ -.data +.text .global hal_ap_blob_start .global hal_ap_blob_length @@ -8,5 +8,7 @@ hal_ap_blob_start: hlt jmp hal_ap_blob_start +.data + hal_ap_blob_length: .long 4 diff --git a/dev/kernel/HALKit/AMD64/HalCommonAPI.asm b/dev/kernel/HALKit/AMD64/HalCommonAPI.asm index d0ce2418..be150dde 100644 --- a/dev/kernel/HALKit/AMD64/HalCommonAPI.asm +++ b/dev/kernel/HALKit/AMD64/HalCommonAPI.asm @@ -116,9 +116,6 @@ sched_jump_to_task: global sched_idle_task sched_idle_task: - mov ax, cs - and ax, 3 - jmp $ ret diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc index 9da31800..23ca8d0e 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cc @@ -33,30 +33,23 @@ STATIC void hal_idt_send_eoi(UInt8 vector) { /// @brief Handle GPF fault. /// @param rsp EXTERN_C Kernel::Void idt_handle_gpf(Kernel::UIntPtr rsp) { - hal_idt_send_eoi(13); - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); - Kernel::kout << "Kernel: General Access Fault.\r"; + hal_idt_send_eoi(13); process.Leak().Signal.SignalArg = rsp; process.Leak().Signal.SignalID = SIGKILL; process.Leak().Signal.Status = process.Leak().Status; - - Kernel::kout << "Kernel: SIGKILL status.\r"; - - process.Leak().Crash(); } /// @brief Handle page fault. /// @param rsp EXTERN_C void idt_handle_pf(Kernel::UIntPtr rsp) { - hal_idt_send_eoi(14); - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); - Kernel::kout << "Kernel: Page Fault.\r"; - Kernel::kout << "Kernel: SIGKILL\r"; + hal_idt_send_eoi(14); process.Leak().Signal.SignalArg = rsp; process.Leak().Signal.SignalID = SIGKILL; @@ -87,26 +80,22 @@ EXTERN_C void idt_handle_math(Kernel::UIntPtr rsp) { auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); - Kernel::kout << "Kernel: Math error (division by zero?).\r"; - process.Leak().Signal.SignalArg = rsp; process.Leak().Signal.SignalID = SIGKILL; process.Leak().Signal.Status = process.Leak().Status; - Kernel::kout << "Kernel: SIGKILL status.\r"; - process.Leak().Crash(); } /// @brief Handle any generic fault. /// @param rsp EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { - hal_idt_send_eoi(30); - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); + + hal_idt_send_eoi(30); - (Void)(Kernel::kout << "Kernel: Process RSP: " << Kernel::hex_number(rsp) << Kernel::kendl); - Kernel::kout << "Kernel: Access Process Fault.\r"; + Kernel::kout << "Kernel: Generic Process Fault.\r"; process.Leak().Signal.SignalArg = rsp; process.Leak().Signal.SignalID = SIGKILL; @@ -118,46 +107,31 @@ EXTERN_C void idt_handle_generic(Kernel::UIntPtr rsp) { } EXTERN_C Kernel::Void idt_handle_breakpoint(Kernel::UIntPtr rip) { - hal_idt_send_eoi(3); - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); - (Void)(Kernel::kout << "Kernel: Process RIP: " << Kernel::hex_number(rip) << Kernel::kendl); - - Kernel::kout << "Kernel: SIGTRAP\r"; + hal_idt_send_eoi(3); process.Leak().Signal.SignalArg = rip; process.Leak().Signal.SignalID = SIGTRAP; process.Leak().Signal.Status = process.Leak().Status; - Kernel::kout << "Kernel: SIGTRAP status.\r"; - process.Leak().Status = Kernel::ProcessStatusKind::kFrozen; } /// @brief Handle #UD fault. /// @param rsp EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { - hal_idt_send_eoi(6); - - NE_UNUSED(rsp); - auto& process = Kernel::UserProcessScheduler::The().TheCurrentProcess(); + process.Leak().Crash(); - if (process.Leak().Signal.SignalID == SIGKILL || process.Leak().Signal.SignalID == SIGABRT || - process.Leak().Signal.SignalID == SIGTRAP) { - dbg_break_point(); - } - - Kernel::kout << "Kernel: Undefined Opcode.\r"; + hal_idt_send_eoi(6); process.Leak().Signal.SignalArg = rsp; process.Leak().Signal.SignalID = SIGKILL; process.Leak().Signal.Status = process.Leak().Status; - Kernel::kout << "Kernel: SIGKILL status.\r"; - process.Leak().Crash(); } @@ -169,19 +143,11 @@ EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx_syscall_index, hal_idt_send_eoi(50); if (rcx_syscall_index < kSysCalls.Count()) { - Kernel::kout << "syscall: Enter Syscall.\r"; - if (kSysCalls[rcx_syscall_index].fHooked) { if (kSysCalls[rcx_syscall_index].fProc) { (kSysCalls[rcx_syscall_index].fProc)((Kernel::VoidPtr) rdx_syscall_struct); - } else { - Kernel::kout << "syscall: syscall isn't valid at all! (is nullptr)\r"; } - } else { - Kernel::kout << "syscall: syscall isn't hooked at all! (is set to false)\r"; } - - Kernel::kout << "syscall: Exit Syscall.\r"; } } @@ -193,18 +159,10 @@ EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index, hal_idt_send_eoi(51); if (rcx_kerncall_index < kKernCalls.Count()) { - Kernel::kout << "kerncall: Enter Kernel Call List.\r"; - if (kKernCalls[rcx_kerncall_index].fHooked) { if (kKernCalls[rcx_kerncall_index].fProc) { (kKernCalls[rcx_kerncall_index].fProc)((Kernel::VoidPtr) rdx_kerncall_struct); - } else { - Kernel::kout << "kerncall: Kernel call isn't valid at all! (is nullptr)\r"; } - } else { - Kernel::kout << "kerncall: Kernel call isn't hooked at all! (is set to false)\r"; } - - Kernel::kout << "kerncall: Exit Kernel Call List.\r"; } } diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 5394645a..65b522a6 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -129,6 +129,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) { HardwareThreadScheduler::The()[index].Leak()->Kind() = ThreadKind::kAPStandard; + HardwareThreadScheduler::The()[index].Leak()->ID() = index; HardwareThreadScheduler::The()[index].Leak()->Busy(NO); } diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index dd6b9aea..99e1c619 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -15,8 +15,6 @@ * */ -#if 0 - #include <ArchKit/ArchKit.h> #include <KernelKit/DriveMgr.h> #include <StorageKit/ATA.h> @@ -85,8 +83,8 @@ ATAInit_Retry: rt_out8(OutBus + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); - + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) + ; /// fetch serial info /// model, speed, number of sectors... @@ -119,21 +117,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); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + 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] = in & 0xFF; Buf[IndexOff + 1] = (in >> 8) & 0xFF; } } @@ -150,22 +149,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); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + 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; + 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); } } @@ -275,6 +275,4 @@ 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/HalACPIFactoryInterface.cc b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc index 660110b2..dc883239 100644 --- a/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc +++ b/dev/kernel/HALKit/ARM64/HalACPIFactoryInterface.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <ArchKit/ArchKit.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> #include <NeKit/KString.h> #include <modules/ACPI/ACPIFactoryInterface.h> #include <modules/APM/APM.h> diff --git a/dev/kernel/HALKit/ARM64/HalApplicationProcessorStartup.s b/dev/kernel/HALKit/ARM64/HalApplicationProcessorStartup.s new file mode 100644 index 00000000..dca52571 --- /dev/null +++ b/dev/kernel/HALKit/ARM64/HalApplicationProcessorStartup.s @@ -0,0 +1,12 @@ +.text + +.global hal_ap_blob_start +.global hal_ap_blob_length + +hal_ap_blob_start: + ret + +.data + +hal_ap_blob_length: + .long 4 diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 6f3f3d12..20bd3d8a 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -12,7 +12,7 @@ #include <KernelKit/CodeMgr.h> #include <KernelKit/FileMgr.h> #include <KernelKit/HardwareThreadScheduler.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> #include <KernelKit/PEFCodeMgr.h> #include <KernelKit/ProcessScheduler.h> #include <NeKit/Json.h> diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 86354d7f..21b8b96e 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -28,8 +28,8 @@ #include <CompilerKit/CompilerKit.h> #include <KernelKit/DebugOutput.h> +#include <KernelKit/HeapMgr.h> #include <KernelKit/KPC.h> -#include <KernelKit/MemoryMgr.h> #include <NeKit/ErrorOr.h> #include <NeKit/Ref.h> #include <NeKit/Stream.h> @@ -324,7 +324,7 @@ class FileStream final { Char* MIME() noexcept { return const_cast<Char*>(fMime); } enum { - kFileMgrRestrictRead, + kFileMgrRestrictRead = 100, kFileMgrRestrictReadBinary, kFileMgrRestrictWrite, kFileMgrRestrictWriteBinary, @@ -338,7 +338,8 @@ class FileStream final { const Char* fMime{kFileMimeGeneric}; }; -using FileStreamUTF8 = FileStream<Char>; +using FileStreamASCII = FileStream<Char>; +using FileStreamUTF8 = FileStream<Utf8Char>; using FileStreamUTF16 = FileStream<WideChar>; typedef UInt64 CursorType; @@ -346,7 +347,7 @@ typedef UInt64 CursorType; inline static const auto kRestrictStrLen = 8U; /// @brief restrict information about the file descriptor. -struct FileRestrictKind final { +struct FILEMGR_RESTRICT final { Char fRestrict[kRestrictStrLen]; Int32 fMappedTo; }; @@ -356,7 +357,7 @@ template <typename Encoding, typename Class> inline FileStream<Encoding, Class>::FileStream(const Encoding* path, const Encoding* restrict_type) : fFile(Class::GetMounted()->Open(path, restrict_type)) { SizeT kRestrictCount = kRestrictMax; - const FileRestrictKind kRestrictList[] = {{ + const FILEMGR_RESTRICT kRestrictList[] = {{ .fRestrict = kRestrictR, .fMappedTo = kFileMgrRestrictRead, }, diff --git a/dev/kernel/KernelKit/HardwareThreadScheduler.h b/dev/kernel/KernelKit/HardwareThreadScheduler.h index a10d3a9e..76327a93 100644 --- a/dev/kernel/KernelKit/HardwareThreadScheduler.h +++ b/dev/kernel/KernelKit/HardwareThreadScheduler.h @@ -71,7 +71,6 @@ class HardwareThread final { HAL::StackFramePtr fStack{nullptr}; ThreadKind fKind{ThreadKind::kAPStandard}; ThreadID fID{0}; - ThreadID fPID{0}; Bool fWakeup{NO}; Bool fBusy{NO}; UInt64 fPTime{0}; diff --git a/dev/kernel/KernelKit/MemoryMgr.h b/dev/kernel/KernelKit/HeapMgr.h index 7ca7da90..3271dd03 100644 --- a/dev/kernel/KernelKit/MemoryMgr.h +++ b/dev/kernel/KernelKit/HeapMgr.h @@ -8,7 +8,7 @@ #define INC_KERNEL_HEAP_H /// @date 30/01/24 -/// @file: MemoryMgr.h +/// @file: HeapMgr.h /// @brief: Memory allocation support for the NeKernel. #include <KernelKit/KPC.h> @@ -51,28 +51,8 @@ Int32 mm_make_ptr_flags(VoidPtr heap_ptr, UInt64 flags); /// @brief Gets the flags of a heap header. /// @param heap_ptr the pointer to get. UInt64 mm_get_ptr_flags(VoidPtr heap_ptr); - -/// @brief Allocate C++ class. -/// @param cls The class to allocate. -/// @param args The args to pass. -template <typename T, typename... Args> -inline BOOL mm_new_class(_Input _Output T** cls, _Input Args&&... args) { - if (*cls) { - err_global_get() = Kernel::kErrorInvalidData; - return NO; - } - - *cls = new T(move(args)...); - return *cls; -} - -/// @brief Delete and nullify C++ class. -/// @param cls The class to delete. -template <typename T> -inline Void mm_delete_class(_Input _Output T** cls) { - delete *cls; - *cls = nullptr; -} } // namespace Kernel +#include <KernelKit/HeapMgr.inl> + #endif // !INC_KERNEL_HEAP_H diff --git a/dev/kernel/KernelKit/HeapMgr.inl b/dev/kernel/KernelKit/HeapMgr.inl new file mode 100644 index 00000000..6371012e --- /dev/null +++ b/dev/kernel/KernelKit/HeapMgr.inl @@ -0,0 +1,35 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#ifndef INC_KERNEL_HEAP_H +#include <KernelKit/HeapMgr.h> +#endif // !INC_KERNEL_HEAP_H + +namespace Kernel { +/// @brief Allocate C++ class. +/// @param cls The class to allocate. +/// @param args The args to pass. +template <typename T, typename... Args> +inline BOOL mm_new_class(_Input _Output T** cls, _Input Args&&... args) { + if (*cls) { + err_global_get() = Kernel::kErrorInvalidData; + return NO; + } + + *cls = new T(move(args)...); + return *cls; +} + +/// @brief Delete and nullify C++ class. +/// @param cls The class to delete. +template <typename T> +inline Void mm_delete_class(_Input _Output T** cls) { + delete *cls; + *cls = nullptr; +} +} // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/KernelKit/Zxd.h b/dev/kernel/KernelKit/Zxd.h new file mode 100644 index 00000000..d2456f51 --- /dev/null +++ b/dev/kernel/KernelKit/Zxd.h @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <NeKit/Defines.h> + +namespace ZXD { +using namespace Kernel; + +struct ZXD_EXEC_HEADER; +struct ZXD_STUB_HEADER; + +/// @brief ZXD executable header +/// @details This header is used to identify ZXD executable files. +struct ZXD_EXEC_HEADER { + UInt32 fMagic; + UInt32 fVersion; + UInt32 fFlags; + UInt32 fHdrSize; + UInt32 fCRC32; + UInt32 fAssigneeSignature; + UInt32 fIssuerSingature; +}; + +/// @brief ZXD stub header +/// @details This header is used to identify ZXD stub files. It contains the size of the stub, the +/// offset of the stub, and the CRC32 checksum of the stub. +struct ZXD_STUB_HEADER : public ZXD_EXEC_HEADER { + UInt32 fStubSize; + UInt32 fStubOffset; + UInt32 fStubCRC32; +}; +} // namespace ZXD
\ No newline at end of file diff --git a/dev/kernel/NeKit/Function.h b/dev/kernel/NeKit/Function.h index e5d56cee..cddcc215 100644 --- a/dev/kernel/NeKit/Function.h +++ b/dev/kernel/NeKit/Function.h @@ -4,7 +4,6 @@ ------------------------------------------- */ - #ifndef _INC_FUNCTION_H_ #define _INC_FUNCTION_H_ diff --git a/dev/kernel/NeKit/New.h b/dev/kernel/NeKit/New.h index de242141..8ddd88de 100644 --- a/dev/kernel/NeKit/New.h +++ b/dev/kernel/NeKit/New.h @@ -7,7 +7,7 @@ #pragma once -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> /// @note compatible with tk too. typedef __SIZE_TYPE__ size_t; diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h index 489c51de..80494ab8 100644 --- a/dev/kernel/NeKit/Ref.h +++ b/dev/kernel/NeKit/Ref.h @@ -8,7 +8,7 @@ #ifndef _NEWKIT_REF_H_ #define _NEWKIT_REF_H_ -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> #include <NeKit/Defines.h> #include <NeKit/KernelPanic.h> diff --git a/dev/kernel/src/ACPIFactoryInterface.cc b/dev/kernel/src/ACPIFactoryInterface.cc index def6f517..8cc11cad 100644 --- a/dev/kernel/src/ACPIFactoryInterface.cc +++ b/dev/kernel/src/ACPIFactoryInterface.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <ArchKit/ArchKit.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> #include <NeKit/KString.h> #include <modules/ACPI/ACPIFactoryInterface.h> diff --git a/dev/kernel/src/BitMapMgr.cc b/dev/kernel/src/BitMapMgr.cc index 994a2ba8..4301ce5b 100644 --- a/dev/kernel/src/BitMapMgr.cc +++ b/dev/kernel/src/BitMapMgr.cc @@ -136,7 +136,6 @@ namespace HAL { return; } -#ifdef __NE_VERBOSE_BITMAP__ (Void)(kout << "Magic: " << hex_number(ptr_bit_set[kBitMapMagIdx]) << kendl); (Void)(kout << "Is Allocated? " << (ptr_bit_set[kBitMapUsedIdx] ? "YES" : "NO") << kendl); (Void)(kout << "Size of BitMap (B): " << number(ptr_bit_set[kBitMapSizeIdx]) << kendl); @@ -149,7 +148,6 @@ namespace HAL { (Void)(kout << "Size of BitMap (TIB): " << number(TIB(ptr_bit_set[kBitMapSizeIdx])) << kendl); (Void)(kout << "BitMap Address: " << hex_number((UIntPtr) ptr_bit_set) << kendl); -#endif } }; } // namespace Detail @@ -172,7 +170,13 @@ namespace HAL { if (is_page) return nullptr; ptr_new = bitmp.FindBitMap(kKernelBitMpStart, size, wr, user, pad); - return (UIntPtr*) ptr_new; + + if (!ptr_new) { + ke_panic(RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM, "Out of memory bitmap"); + return nullptr; + } + + return ptr_new; } /***********************************************************************************/ diff --git a/dev/kernel/src/FS/Ext2+FileMgr.cc b/dev/kernel/src/FS/Ext2+FileMgr.cc index a55d917a..810e7e44 100644 --- a/dev/kernel/src/FS/Ext2+FileMgr.cc +++ b/dev/kernel/src/FS/Ext2+FileMgr.cc @@ -8,7 +8,7 @@ #ifdef __FSKIT_INCLUDES_EXT2__ #include <KernelKit/FileMgr.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.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 index e0b92a8d..e4985a3b 100644 --- a/dev/kernel/src/FS/HeFS+FileMgr.cc +++ b/dev/kernel/src/FS/HeFS+FileMgr.cc @@ -8,7 +8,7 @@ #ifdef __FSKIT_INCLUDES_HEFS__ #include <KernelKit/FileMgr.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.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 c92d6727..978a43a8 100644 --- a/dev/kernel/src/FS/NeFS+FileMgr.cc +++ b/dev/kernel/src/FS/NeFS+FileMgr.cc @@ -8,7 +8,7 @@ #ifdef __FSKIT_INCLUDES_NEFS__ #include <KernelKit/FileMgr.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> /// @brief NeFS File System Manager. /// BUGS: 0 diff --git a/dev/kernel/src/HardwareThreadScheduler.cc b/dev/kernel/src/HardwareThreadScheduler.cc index 23365af5..78bad9d6 100644 --- a/dev/kernel/src/HardwareThreadScheduler.cc +++ b/dev/kernel/src/HardwareThreadScheduler.cc @@ -92,11 +92,16 @@ Void HardwareThread::Wake(const bool wakeup) noexcept { /// @retval false stack is invalid, previous code is running. /***********************************************************************************/ Bool HardwareThread::Switch(HAL::StackFramePtr frame) { - this->fStack = frame; + if (!frame) { + return NO; + } - Bool ret = mp_register_task(fStack, this->fPID); + if (!hal_check_stack(frame)) { + return NO; + } - return ret; + this->fStack = frame; + return mp_register_task(fStack, this->fID); } /***********************************************************************************/ @@ -145,8 +150,6 @@ Ref<HardwareThread*> HardwareThreadScheduler::operator[](SizeT idx) { return {kFakeThread}; } - fThreadList[idx].fPID = idx; - return &fThreadList[idx]; } diff --git a/dev/kernel/src/MemoryMgr.cc b/dev/kernel/src/HeapMgr.cc index 2faa24df..6cd8fb24 100644 --- a/dev/kernel/src/MemoryMgr.cc +++ b/dev/kernel/src/HeapMgr.cc @@ -6,8 +6,8 @@ #include <ArchKit/ArchKit.h> #include <KernelKit/DebugOutput.h> +#include <KernelKit/HeapMgr.h> #include <KernelKit/KPC.h> -#include <KernelKit/MemoryMgr.h> #include <NeKit/Crc32.h> #include <NeKit/PageMgr.h> #include <NeKit/Utils.h> @@ -16,14 +16,14 @@ Revision History: 10/8/24: FIX: Fix useless long name, alongside a new WR (WriteRead) field. - 20/10/24: FIX: Fix mm_new_ and mm_delete_ APIs inside MemoryMgr.h header. (amlal) + 20/10/24: FIX: Fix mm_new_ and mm_delete_ APIs inside HeapMgr.h header. (amlal) 27/01/25: REFACTOR: Reworked code as the memory manager. - 25/03/25: REFACTOR: Refactor MemoryMgr code and log freed address location. + 25/03/25: REFACTOR: Refactor HeapMgr code and log freed address location. ------------------------------------------- */ -//! @file MemoryMgr.cc -//! @brief Heap algorithm that serves as the main memory manager. +//! @file HeapMgr.cc +//! @brief Heap system that serves as the main memory manager. #define kMemoryMgrMagic (0xD4D75) #define kMemoryMgrAlignSz (4U) @@ -126,7 +126,7 @@ _Output VoidPtr mm_new_ptr(SizeT sz, Bool wr, Bool user, SizeT pad_amount) { auto result = reinterpret_cast<VoidPtr>(heap_info_ptr->fOffset); - (Void)(kout << "MemoryMgr: Registered heap address: " + (Void)(kout << "HeapMgr: Registered heap address: " << hex_number(reinterpret_cast<UIntPtr>(heap_info_ptr)) << kendl); return result; @@ -146,7 +146,7 @@ _Output Int32 mm_make_page(VoidPtr heap_ptr) { heap_info_ptr->fPage = true; - (Void)(kout << "MemoryMgr: Registered page from heap address: " + (Void)(kout << "HeapMgr: Registered page from heap address: " << hex_number(reinterpret_cast<UIntPtr>(heap_info_ptr)) << kendl); return kErrorSuccess; @@ -205,7 +205,7 @@ _Output Int32 mm_delete_ptr(VoidPtr heap_ptr) { heap_info_ptr->fMagic = 0; heap_info_ptr->fPad = 0; - (Void)(kout << "MemoryMgr: Freed heap address: " + (Void)(kout << "HeapMgr: Freed heap address: " << hex_number(reinterpret_cast<UIntPtr>(heap_info_ptr)) << kendl); PTEWrapper page_wrapper( diff --git a/dev/kernel/src/KPC.cc b/dev/kernel/src/KPC.cc index f44b356b..1693fbd3 100644 --- a/dev/kernel/src/KPC.cc +++ b/dev/kernel/src/KPC.cc @@ -4,8 +4,8 @@ ------------------------------------------- */ +#include <KernelKit/HeapMgr.h> #include <KernelKit/KPC.h> -#include <KernelKit/MemoryMgr.h> #include <NeKit/KernelPanic.h> namespace Kernel { diff --git a/dev/kernel/src/New+Delete.cc b/dev/kernel/src/New+Delete.cc index 0125b7f7..29bbfbbf 100644 --- a/dev/kernel/src/New+Delete.cc +++ b/dev/kernel/src/New+Delete.cc @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> #include <NeKit/New.h> void* operator new[](size_t sz) { diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc index afc28ceb..9ea9b5b1 100644 --- a/dev/kernel/src/PEFCodeMgr.cc +++ b/dev/kernel/src/PEFCodeMgr.cc @@ -5,7 +5,7 @@ ------------------------------------------- */ #include <KernelKit/DebugOutput.h> -#include <KernelKit/MemoryMgr.h> +#include <KernelKit/HeapMgr.h> #include <KernelKit/PEFCodeMgr.h> #include <KernelKit/ProcessScheduler.h> #include <NeKit/Defines.h> diff --git a/dev/kernel/src/User.cc b/dev/kernel/src/User.cc index e8f30547..1859be12 100644 --- a/dev/kernel/src/User.cc +++ b/dev/kernel/src/User.cc @@ -11,8 +11,8 @@ */ #include <KernelKit/FileMgr.h> +#include <KernelKit/HeapMgr.h> #include <KernelKit/KPC.h> -#include <KernelKit/MemoryMgr.h> #include <KernelKit/User.h> #include <NeKit/KernelPanic.h> diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 0a26938a..3251e0dc 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -15,9 +15,9 @@ #include <ArchKit/ArchKit.h> #include <KernelKit/HardwareThreadScheduler.h> +#include <KernelKit/HeapMgr.h> #include <KernelKit/IPEFDylibObject.h> #include <KernelKit/KPC.h> -#include <KernelKit/MemoryMgr.h> #include <KernelKit/ProcessScheduler.h> #include <NeKit/KString.h> #include <SignalKit/Signals.h> @@ -487,13 +487,6 @@ SizeT UserProcessScheduler::Run() noexcept { return 0UL; } - auto& process = this->TheCurrentProcess().Leak(); - - //! Increase the usage time of the process. - if (process.UTime < process.PTime) { - ++process.UTime; - } - SizeT process_index = 0UL; //! we store this guy to tell the scheduler how many //! things we have scheduled. @@ -502,7 +495,12 @@ SizeT UserProcessScheduler::Run() noexcept { //! Check if the process needs to be run. if (UserProcessHelper::CanBeScheduled(process)) { - kout << process.Name << " will be scheduled...\r"; + kout << process.Name << " will be run...\r"; + + //! Increase the usage time of the process. + if (process.UTime < process.PTime) { + ++process.UTime; + } this->TheCurrentProcess() = process; @@ -622,6 +620,9 @@ Bool UserProcessHelper::Switch(HAL::StackFramePtr frame_ptr, PID new_pid) { continue; } + (Void)(kout << "AP_" << hex_number(index)); + kout << " is now trying to run a new task!\r"; + //////////////////////////////////////////////////////////// /// Prepare task switch. /// //////////////////////////////////////////////////////////// @@ -641,6 +642,9 @@ Bool UserProcessHelper::Switch(HAL::StackFramePtr frame_ptr, PID new_pid) { HardwareThreadScheduler::The()[index].Leak()->fPTime = UserProcessScheduler::The().TheCurrentTeam().AsArray()[new_pid].PTime; + (Void)(kout << "AP_" << hex_number(index)); + kout << " is now running a new task!\r"; + return YES; } diff --git a/docs/drawio/ZXD_DESIGN.drawio b/docs/drawio/ZXD_DESIGN.drawio index 7452d3f9..19fadabd 100644 --- a/docs/drawio/ZXD_DESIGN.drawio +++ b/docs/drawio/ZXD_DESIGN.drawio @@ -1,31 +1,31 @@ -<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" version="24.7.12"> - <diagram name="Page-1" id="PApGwmLcT2JRCILoETeI"> - <mxGraphModel dx="1368" dy="717" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"> - <root> - <mxCell id="0" /> - <mxCell id="1" parent="0" /> - <mxCell id="5xbXWvOdvmnQnRAweQaM-1" value="<h1 style="margin-top: 0px;">ZXD</h1><p>NeKernel eXtended Driver Format.</p><p>An Extended PE32+</p><p>With additional headers and such.</p>" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" parent="1" vertex="1"> - <mxGeometry x="40" y="40" width="210" height="130" as="geometry" /> - </mxCell> - <mxCell id="5xbXWvOdvmnQnRAweQaM-2" value="NeKernel HEADER" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> - <mxGeometry x="40" y="180" width="310" height="60" as="geometry" /> - </mxCell> - <mxCell id="5xbXWvOdvmnQnRAweQaM-3" value="PE32+ ZONE" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> - <mxGeometry x="40" y="260" width="310" height="60" as="geometry" /> - </mxCell> - <mxCell id="5xbXWvOdvmnQnRAweQaM-4" value="ZXD STUB [1..N]" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> - <mxGeometry x="40" y="340" width="310" height="60" as="geometry" /> - </mxCell> - <mxCell id="FgewEam9b60nFajCTQDb-1" value="StubHeapSz, StubStackSz, StubPageFlags..." style="text;html=1;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1"> - <mxGeometry x="380" y="355" width="290" height="30" as="geometry" /> - </mxCell> - <mxCell id="FgewEam9b60nFajCTQDb-2" value="Executable image type..." style="text;html=1;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1"> - <mxGeometry x="380" y="274" width="290" height="30" as="geometry" /> - </mxCell> - <mxCell id="FgewEam9b60nFajCTQDb-5" value="NeKernel executable header." style="text;html=1;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1"> - <mxGeometry x="380" y="194" width="290" height="30" as="geometry" /> - </mxCell> - </root> - </mxGraphModel> - </diagram> -</mxfile> +<mxfile host="65bd71144e"> + <diagram name="Page-1" id="PApGwmLcT2JRCILoETeI"> + <mxGraphModel dx="960" dy="709" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0"> + <root> + <mxCell id="0"/> + <mxCell id="1" parent="0"/> + <mxCell id="5xbXWvOdvmnQnRAweQaM-1" value="<h1 style="margin-top: 0px;">ZXD</h1><p>NeKernel eXtended Driver Format.</p><p>An Extended PE32+</p><p>With additional headers and such.</p>" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" parent="1" vertex="1"> + <mxGeometry x="40" y="40" width="210" height="130" as="geometry"/> + </mxCell> + <mxCell id="5xbXWvOdvmnQnRAweQaM-2" value="ZXD HEADER" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> + <mxGeometry x="40" y="180" width="310" height="60" as="geometry"/> + </mxCell> + <mxCell id="5xbXWvOdvmnQnRAweQaM-3" value="PE32+ ZONE" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> + <mxGeometry x="40" y="260" width="310" height="60" as="geometry"/> + </mxCell> + <mxCell id="5xbXWvOdvmnQnRAweQaM-4" value="ZXD STUB [1..N]" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1"> + <mxGeometry x="40" y="340" width="310" height="60" as="geometry"/> + </mxCell> + <mxCell id="FgewEam9b60nFajCTQDb-1" value="StubHeapSz, StubStackSz, StubPageFlags..." style="text;html=1;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"> + <mxGeometry x="380" y="355" width="290" height="30" as="geometry"/> + </mxCell> + <mxCell id="FgewEam9b60nFajCTQDb-2" value="Executable image of type PE32+&nbsp;" style="text;html=1;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"> + <mxGeometry x="380" y="274" width="290" height="30" as="geometry"/> + </mxCell> + <mxCell id="FgewEam9b60nFajCTQDb-5" value="ZXD header, contains issuer and assignee signature, checked at runtime." style="text;html=1;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1"> + <mxGeometry x="380" y="194" width="290" height="30" as="geometry"/> + </mxCell> + </root> + </mxGraphModel> + </diagram> +</mxfile>
\ No newline at end of file diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc index 3dcfd11b..fcb0c006 100644 --- a/tooling/mkfs.hefs.cc +++ b/tooling/mkfs.hefs.cc @@ -55,7 +55,7 @@ int main(int argc, char** argv) { kLabel = mkfs::get_option<char8_t>(args_wide, u8"-L"); if (!kSectorSize) { - mkfs::console_out() << "hefs: error: Sector size size is zero.\n"; + mkfs::console_out() << "hefs: error: Sector size size is set to zero.\n"; return EXIT_FAILURE; } @@ -65,7 +65,7 @@ int main(int argc, char** argv) { std::strtol(mkfs::get_option<char>(args, "-S").data(), nullptr, 10) * 1024 * 1024 * 1024; if (!kDiskSize) { - mkfs::console_out() << "hefs: error: Disk size is zero.\n"; + mkfs::console_out() << "hefs: error: Disk size is set to zero.\n"; return EXIT_FAILURE; } |
