From 537cadbf78695a01ea1c00a0a5a4b6b70ddac8c3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 7 Sep 2025 18:12:25 +0200 Subject: feat: `ne_launch` and `LaunchHelpers.fwrk`: PID zero of NeKernel. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'dev/kernel/HALKit/ARM64/HalKernelMain.cc') diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index d7663f4e..096df49e 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -67,10 +67,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { ProcessStatusKind::kInvalid; } - rtl_create_user_process(sched_idle_task, "MgmtSrv"); //! Mgmt command server. - rtl_create_user_process(sched_idle_task, "LaunchSrv"); //! launchd - rtl_create_user_process(sched_idle_task, "SecSrv"); //! Login Server - Kernel::mp_init_cores(); while (YES) -- cgit v1.2.3 From d3f87b1b84d355ad72366ced5d7e5a43207226c0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 7 Sep 2025 23:29:48 +0200 Subject: feat: kernel: startup sequence fix, and new mgmt.hefs manual. wip: LaunchKit for the `ne_launch` program. Signed-off-by: Amlal El Mahrouss --- .gitignore | 2 +- dev/boot/amd64-desktop.make | 6 ++-- dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc | 13 ++++----- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 31 ++++++-------------- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 14 +-------- dev/kernel/src/UserProcessScheduler.cc | 2 +- dev/launch/LaunchKit/LaunchKit.h | 9 ++++++ dev/launch/src/LaunchSrv.cc | 15 ++++++++++ dev/libDDK/src/ddk_kernel_call.c | 4 +-- public/manuals/nekernel/mgmt.hefs.util.man | 34 ++++++++++++++++++++++ public/tools/mgmt.launch/.keep | 0 public/tools/mgmt.launch/dist/.keep | 0 public/tools/mgmt.launch/mgmt.launch.json | 19 ++++++++++++ public/tools/mgmt.launch/src/.keep | 0 public/tools/mgmt.launch/src/CommandLine.cc | 5 ++++ public/tools/mgmt.launch/vendor/.keep | 0 16 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 dev/launch/LaunchKit/LaunchKit.h create mode 100644 dev/launch/src/LaunchSrv.cc create mode 100644 public/manuals/nekernel/mgmt.hefs.util.man create mode 100644 public/tools/mgmt.launch/.keep create mode 100644 public/tools/mgmt.launch/dist/.keep create mode 100644 public/tools/mgmt.launch/mgmt.launch.json create mode 100644 public/tools/mgmt.launch/src/.keep create mode 100644 public/tools/mgmt.launch/src/CommandLine.cc create mode 100644 public/tools/mgmt.launch/vendor/.keep (limited to 'dev/kernel/HALKit/ARM64/HalKernelMain.cc') diff --git a/.gitignore b/.gitignore index 1058abb8..1144fd7a 100644 --- a/.gitignore +++ b/.gitignore @@ -135,7 +135,7 @@ local.properties .externalToolBuilders/ # Locally stored "Eclipse launch configurations" -*.launch +# *.launch # PyDev specific (Python IDE for Eclipse) *.pydevproject diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 443e5677..d8c3fd86 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -117,15 +117,15 @@ compile-amd64: .PHONY: run-efi-amd64-ahci run-efi-amd64-ahci: - $(EMU) $(EMU_FLAGS) -monitor stdio -hda $(IMG) -s -S -boot menu=on + $(EMU) $(EMU_FLAGS) -monitor stdio -hda $(IMG) -s -boot menu=on .PHONY: run-efi-amd64-ata-pio run-efi-amd64-ata-pio: - $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -d int -boot menu=on + $(EMU) $(EMU_FLAGS) -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -d int -boot menu=on .PHONY: run-efi-amd64-ata-dma run-efi-amd64-ata-dma: - $(EMU) $(EMU_FLAGS) -device piix4-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -S -boot menu=on + $(EMU) $(EMU_FLAGS) -device piix4-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -s -boot menu=on .PHONY: run-efi-amd64-ata run-efi-amd64-ata: run-efi-amd64-ata-pio diff --git a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc index df5386e4..e3e08830 100644 --- a/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc +++ b/dev/kernel/HALKit/AMD64/HalApplicationProcessor.cc @@ -88,7 +88,7 @@ struct LAPIC final { /// @param target /// @return /***********************************************************************************/ -Void hal_send_ipi_msg(UInt32 target, UInt32 apic_id, UInt8 vector) { +EXTERN_C Void hal_send_ipi_msg(UInt32 target, UInt32 apic_id, UInt8 vector) { Kernel::ke_dma_write(target, APIC_ICR_HIGH, apic_id << 24); Kernel::ke_dma_write(target, APIC_ICR_LOW, 0x00000600 | 0x00004000 | 0x00000000 | vector); @@ -200,10 +200,7 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept { UInt8 type = *entry_ptr; UInt8 length = *(entry_ptr + 1); - // Avoid infinite loop on bad APIC tables. - if (length < 2) break; - - if (type == 0) { + if (type == 0 && length == sizeof(struct LAPIC)) { volatile LAPIC* entry_struct = (volatile LAPIC*) entry_ptr; if (entry_struct->Flags & 0x1) { @@ -212,15 +209,15 @@ Void mp_init_cores(VoidPtr vendor_ptr) noexcept { ++kSMPCount; - kout << "Kind: LAPIC: ON\r"; + kout << "AP: kind: LAPIC: ON.\r"; // 0x7c00, as recommended by the Intel SDM. hal_send_ipi_msg(kApicBaseAddress, entry_struct->ProcessorID, 0x7c); } else { - kout << "Kind: LAPIC: OFF\r"; + kout << "AP: kind: LAPIC: OFF.\r"; } } else { - kout << "Kind: UNKNOWN: OFF\r"; + kout << "AP: kind: UNKNOWN: OFF.\r"; } entry_ptr += length; diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index cb5d4af8..95214353 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -32,8 +32,6 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { HAL::rt_sti(); - kHandoverHeader = handover_hdr; - FB::fb_clear_video(); fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); @@ -41,8 +39,9 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { Boot::ExitBootServices(handover_hdr->f_HardwareTables.f_ImageKey, handover_hdr->f_HardwareTables.f_ImageHandle); - kBitMapCursor = 0UL; - kKernelVM = kHandoverHeader->f_PageStart; + kHandoverHeader = handover_hdr; + + kKernelVM = kHandoverHeader->f_PageStart; if (!kKernelVM) { MUST_PASS(kKernelVM); @@ -55,6 +54,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { /* INITIALIZE BIT MAP. */ /************************************** */ + kBitMapCursor = 0UL; kKernelBitMpSize = kHandoverHeader->f_BitMapSize; kKernelBitMpStart = reinterpret_cast(reinterpret_cast(kHandoverHeader->f_BitMapStart)); @@ -133,20 +133,14 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { return kEfiFail; } -EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { +EXTERN_C Kernel::Void hal_real_init(Kernel::Void) { using namespace Kernel; - 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); - } + HAL::Register64 idt_reg; + idt_reg.Base = reinterpret_cast(kInterruptVectorTable); - for (SizeT index = 0UL; index < UserProcessScheduler::The().TheCurrentTeam().AsArray().Count(); - ++index) { - UserProcessScheduler::The().TheCurrentTeam().AsArray()[index].Status = - ProcessStatusKind::kInvalid; - } + HAL::IDTLoader idt_loader; + idt_loader.Load(idt_reg); HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); @@ -158,13 +152,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { NeFS::fs_init_nefs(); #endif - HAL::Register64 idt_reg; - idt_reg.Base = reinterpret_cast(kInterruptVectorTable); - - HAL::IDTLoader idt_loader; - - idt_loader.Load(idt_reg); - while (YES) ; } diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 096df49e..29541d48 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -37,8 +37,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { FB::fb_clear_video(); - kBitMapCursor = 0UL; - #ifdef __NE_ARM64_EFI__ fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); @@ -50,23 +48,13 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { /* INITIALIZE BIT MAP. */ /************************************** */ + kBitMapCursor = 0UL; kKernelBitMpSize = kHandoverHeader->f_BitMapSize; kKernelBitMpStart = reinterpret_cast( reinterpret_cast(kHandoverHeader->f_BitMapStart)); /// @note do initialize the interrupts after it. - for (SizeT index = 0UL; index < HardwareThreadScheduler::The().Capacity(); ++index) { - HardwareThreadScheduler::The()[index].Leak()->Kind() = ThreadKind::kAPStandard; - HardwareThreadScheduler::The()[index].Leak()->Busy(NO); - } - - for (SizeT index = 0UL; index < UserProcessScheduler::The().TheCurrentTeam().AsArray().Count(); - ++index) { - UserProcessScheduler::The().TheCurrentTeam().AsArray()[index].Status = - ProcessStatusKind::kInvalid; - } - Kernel::mp_init_cores(); while (YES) diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index 174862a4..07c4a572 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -438,7 +438,7 @@ ProcessID UserProcessScheduler::Spawn(const Char* name, VoidPtr code, VoidPtr im } (Void)(kout << "ProcessID: " << number(process.ProcessId) << kendl); - (Void)(kout << "Name: " << process.Name << kendl); + (Void)(kout << "ProcesName: " << process.Name << kendl); return pid; } diff --git a/dev/launch/LaunchKit/LaunchKit.h b/dev/launch/LaunchKit/LaunchKit.h new file mode 100644 index 00000000..95d91e09 --- /dev/null +++ b/dev/launch/LaunchKit/LaunchKit.h @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + ------------------------------------------- */ + +#pragma once + +#include diff --git a/dev/launch/src/LaunchSrv.cc b/dev/launch/src/LaunchSrv.cc new file mode 100644 index 00000000..8c302c6d --- /dev/null +++ b/dev/launch/src/LaunchSrv.cc @@ -0,0 +1,15 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + ------------------------------------------- */ + +#include + +SInt32 _NeMain(Void) { + PrintOut(nullptr, "%s", "NeKernel Launcher\n"); + + /// @todo Start LaunchServices.fwrk, make the launcher manageable too (via mgmt.launch) + + return kErrorSuccess; +} diff --git a/dev/libDDK/src/ddk_kernel_call.c b/dev/libDDK/src/ddk_kernel_call.c index 61742b7b..5976665b 100644 --- a/dev/libDDK/src/ddk_kernel_call.c +++ b/dev/libDDK/src/ddk_kernel_call.c @@ -12,8 +12,8 @@ #include /// @brief this is an internal call, do not use it. -DDK_EXTERN ATTRIBUTE(naked) ptr_t __ke_call_dispatch(const int32_t name, int32_t cnt, void* data, - size_t sz); +DDK_EXTERN ATTRIBUTE(naked) ptr_t + __ke_call_dispatch(const int32_t name, int32_t cnt, void* data, size_t sz); /// @brief This function hashes the path into a FNV symbol. /// @param path the path to hash. /// @retval 0 symbol wasn't hashed. diff --git a/public/manuals/nekernel/mgmt.hefs.util.man b/public/manuals/nekernel/mgmt.hefs.util.man new file mode 100644 index 00000000..3274f93a --- /dev/null +++ b/public/manuals/nekernel/mgmt.hefs.util.man @@ -0,0 +1,34 @@ +NAME + mgmt.hefs — HeFS Management utility command + +SYNOPSIS + mgmt.hefs [OPTIONS] + +DESCRIPTION + The `mgmt.hefs` command provides scheduling, execution, and remote orchestration + of a HeFS volume inside a System One environement. One might use this tool to + create, edit, and remove volumes from a disk. + + Usages include, but are not limited to: + - Schedule scripts or tasks for future execution. + - Verify device or filesystem integrity. + - Manage and automate remote NeKernel machines. + +OPTIONS + -v, --volume Device input + -c, --create Create HeFS volume + -x, --xml Pass PropertyList to volume creation tool. + -t, --time Time to run the script + -d, --day Day of the week (e.g., Mon, Tue, Wed) + -m, --month Month (e.g., Jan, Feb, Mar) + -y, --year Year to schedule task + -r, --remote
Remote machine to manage (optional) + -v, --verify Run integrity checks only + -h, --help Display this help message + +EXAMPLES + mgmt.hefs -v /devices/disks0p0 -t 2:30PM -d Wed -m Apr -y 2026 --xml /xml/hefs.pxml + Schedules `/xml/hefs.pxml` to run at 2:30PM on Wednesday, April 2026. + +RELEASE + v1.0.0 — NeKernel.org diff --git a/public/tools/mgmt.launch/.keep b/public/tools/mgmt.launch/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.launch/dist/.keep b/public/tools/mgmt.launch/dist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.launch/mgmt.launch.json b/public/tools/mgmt.launch/mgmt.launch.json new file mode 100644 index 00000000..a181d745 --- /dev/null +++ b/public/tools/mgmt.launch/mgmt.launch.json @@ -0,0 +1,19 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": [ + "./", + "../../../dev/kernel", + "../../../public/frameworks/", + "../../../dev/", + "./" + ], + "sources_path": [], + "output_name": "./dist/mgmt.launch", + "cpp_macros": [ + "kSampleFWVersion=0x0100", + "kSampleFWVersionHighest=0x0100", + "kSampleFWVersionLowest=0x0100", + "__NE_SDK__" + ] +} \ No newline at end of file diff --git a/public/tools/mgmt.launch/src/.keep b/public/tools/mgmt.launch/src/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/mgmt.launch/src/CommandLine.cc b/public/tools/mgmt.launch/src/CommandLine.cc new file mode 100644 index 00000000..6015988e --- /dev/null +++ b/public/tools/mgmt.launch/src/CommandLine.cc @@ -0,0 +1,5 @@ +#include + +SInt32 _NeMain(SInt32 argc, Char* argv[]) { + return EXIT_FAILURE; +} \ No newline at end of file diff --git a/public/tools/mgmt.launch/vendor/.keep b/public/tools/mgmt.launch/vendor/.keep new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3 From 42832ec1b72baf244a1290ccf747b79db0caa69f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Sep 2025 13:44:33 +0200 Subject: fix: hal: clear video memory once handoff is done. Signed-off-by: Amlal El Mahrouss --- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 4 ++-- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'dev/kernel/HALKit/ARM64/HalKernelMain.cc') diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 95214353..16670f5c 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -32,8 +32,6 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { HAL::rt_sti(); - FB::fb_clear_video(); - fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); Boot::ExitBootServices(handover_hdr->f_HardwareTables.f_ImageKey, @@ -120,6 +118,8 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { kGDTArray[4].fFlags = 0; kGDTArray[4].fBaseHigh = 0; + FB::fb_clear_video(); + // Load memory descriptors. HAL::Register64 gdt_reg; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 29541d48..240b3ac8 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -35,8 +35,6 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { return; } - FB::fb_clear_video(); - #ifdef __NE_ARM64_EFI__ fw_init_efi((EfiSystemTable*) handover_hdr->f_FirmwareCustomTables[1]); @@ -44,6 +42,8 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { handover_hdr->f_HardwareTables.f_ImageHandle); #endif + FB::fb_clear_video(); + /************************************** */ /* INITIALIZE BIT MAP. */ /************************************** */ -- cgit v1.2.3 From b1e3dac861c0d6c28bdb7768d7f96f19456e9ad0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Sep 2025 21:28:04 +0200 Subject: feat:! ddk/dki, ne_launch, ifs: Big architectural changes and improvements. Signed-off-by: Amlal El Mahrouss --- dev/kernel/FSKit/Ext2+IFS.h | 140 +++++++++++++++++++++++++++++ dev/kernel/FSKit/Ext2IFS.h | 135 ---------------------------- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 2 +- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 2 +- dev/kernel/src/FS/Ext2+FileSystemParser.cc | 2 +- dev/launch/LaunchKit/LaunchKit.h | 2 + dev/launch/ne_launch.json | 2 +- dev/launch/src/CRT0.S | 17 ++++ dev/launch/src/LaunchSrv.cc | 5 +- dev/libDDK/DriverKit/cpp/object.hpp | 16 ---- dev/libDDK/DriverKit/dki/contract.h | 32 +++++++ dev/libSystem/src/System.cc | 15 +++- 12 files changed, 210 insertions(+), 160 deletions(-) create mode 100644 dev/kernel/FSKit/Ext2+IFS.h delete mode 100644 dev/kernel/FSKit/Ext2IFS.h create mode 100644 dev/launch/src/CRT0.S delete mode 100644 dev/libDDK/DriverKit/cpp/object.hpp create mode 100644 dev/libDDK/DriverKit/dki/contract.h (limited to 'dev/kernel/HALKit/ARM64/HalKernelMain.cc') diff --git a/dev/kernel/FSKit/Ext2+IFS.h b/dev/kernel/FSKit/Ext2+IFS.h new file mode 100644 index 00000000..d73ae43c --- /dev/null +++ b/dev/kernel/FSKit/Ext2+IFS.h @@ -0,0 +1,140 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace Kernel::Ext2 { +/// @brief Context for an EXT2 filesystem on a given drive +struct Ext2Context { + Kernel::DriveTrait* drive{nullptr}; + EXT2_SUPER_BLOCK* superblock{nullptr}; + + /// @brief context with a drive + Ext2Context(Kernel::DriveTrait* drv) : drive(drv) {} + + /// @brief Clean up + ~Ext2Context() { + if (superblock) { + Kernel::mm_free_ptr(superblock); + superblock = nullptr; + } + } + + Ext2Context(const Ext2Context&) = delete; + Ext2Context& operator=(const Ext2Context&) = delete; + + Ext2Context(Ext2Context&& other) noexcept : drive(other.drive), superblock(other.superblock) { + other.drive = nullptr; + other.superblock = nullptr; + } + + Ext2Context& operator=(Ext2Context&& other) noexcept { + if (this != &other) { + if (superblock) { + Kernel::mm_free_ptr(superblock); + } + drive = other.drive; + superblock = other.superblock; + other.drive = nullptr; + other.superblock = nullptr; + } + return *this; + } + + Kernel::SizeT LeakBlockSize() const { + if (!superblock) return kExt2FSBlockSizeBase; + return kExt2FSBlockSizeBase << superblock->fLogBlockSize; + } + + BOOL operator bool() { return superblock != nullptr; } +}; + +/// ======================================================================= /// +/// IFS FUNCTIONS +/// ======================================================================= /// + +inline bool ext2_read_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, void* buffer, + Kernel::UInt32 size) { + if (!drv || !buffer) return false; + + Kernel::DriveTrait::DrivePacket pkt{}; + pkt.fPacketContent = buffer; + pkt.fPacketSize = size; + pkt.fPacketLba = lba; + drv->fInput(pkt); + + return pkt.fPacketGood; +} + +inline bool ext2_write_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, const void* buffer, + Kernel::UInt32 size) { + if (!drv || !buffer) return false; + + Kernel::DriveTrait::DrivePacket pkt{}; + pkt.fPacketContent = const_cast(buffer); + pkt.fPacketSize = size; + pkt.fPacketLba = lba; + drv->fOutput(pkt); + return pkt.fPacketGood; +} + +inline Kernel::ErrorOr ext2_load_superblock(Ext2Context* ctx) { + if (!ctx || !ctx->drive) return Kernel::ErrorOr(Kernel::kErrorInvalidData); + + auto buf = Kernel::mm_alloc_ptr(sizeof(EXT2_SUPER_BLOCK), true, false); + if (!buf) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); + + Kernel::UInt32 blockLba = kExt2FSSuperblockOffset / ctx->drive->fSectorSz; + + if (!ext2_read_block(ctx->drive, blockLba, buf, sizeof(EXT2_SUPER_BLOCK))) { + Kernel::mm_free_ptr(buf); + return Kernel::ErrorOr(Kernel::kErrorDisk); + } + + auto sb = reinterpret_cast(buf); + if (sb->fMagic != kExt2FSMagic) { + Kernel::mm_free_ptr(buf); + return Kernel::ErrorOr(Kernel::kErrorInvalidData); + } + + ctx->superblock = sb; + return Kernel::ErrorOr(sb); +} + +// Load inode +inline Kernel::ErrorOr ext2_load_inode(Ext2Context* ctx, Kernel::UInt32 inodeNumber) { + if (!ctx || !ctx->superblock) return Kernel::ErrorOr(Kernel::kErrorInvalidData); + + auto nodePtr = Kernel::mm_alloc_ptr(sizeof(Ext2Node), true, false); + if (!nodePtr) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); + + auto ext2Node = reinterpret_cast(nodePtr); + ext2Node->inodeNumber = inodeNumber; + + // Compute block group and index within group + Kernel::UInt32 inodesPerGroup = ctx->superblock->fInodesPerGroup; + Kernel::UInt32 group = (inodeNumber - 1) / inodesPerGroup; + Kernel::UInt32 index = (inodeNumber - 1) % inodesPerGroup; + + // dummy: just offset first inode + Kernel::UInt32 inodeTableBlock = ctx->superblock->fFirstInode + group; + + if (!ext2_read_block(ctx->drive, inodeTableBlock, &ext2Node->inode, sizeof(EXT2_INODE))) { + Kernel::mm_free_ptr(nodePtr); + return Kernel::ErrorOr(Kernel::kErrorDisk); + } + + ext2Node->cursor = 0; + return Kernel::ErrorOr(ext2Node); +} + +inline Kernel::UInt32 inode_offset(const Ext2Context* ctx, Kernel::UInt32 inodeNumber) { + if (!ctx || !ctx->superblock) return 0; + return ((inodeNumber - 1) % ctx->superblock->fInodesPerGroup) * ctx->superblock->fInodeSize; +} +} // namespace Kernel::Ext2 diff --git a/dev/kernel/FSKit/Ext2IFS.h b/dev/kernel/FSKit/Ext2IFS.h deleted file mode 100644 index 2550cfea..00000000 --- a/dev/kernel/FSKit/Ext2IFS.h +++ /dev/null @@ -1,135 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace Ext2 { - -/// @brief Context for an EXT2 filesystem on a given drive -struct Context { - Kernel::DriveTrait* drive{nullptr}; - EXT2_SUPER_BLOCK* superblock{nullptr}; - - /// @brief context with a drive - explicit Context(Kernel::DriveTrait* drv) : drive(drv) {} - - /// @brief Clean up - ~Context() { - if (superblock) { - Kernel::mm_free_ptr(superblock); - superblock = nullptr; - } - } - - Context(const Context&) = delete; - Context& operator=(const Context&) = delete; - - Context(Context&& other) noexcept : drive(other.drive), superblock(other.superblock) { - other.drive = nullptr; - other.superblock = nullptr; - } - - Context& operator=(Context&& other) noexcept { - if (this != &other) { - if (superblock) { - Kernel::mm_free_ptr(superblock); - } - drive = other.drive; - superblock = other.superblock; - other.drive = nullptr; - other.superblock = nullptr; - } - return *this; - } - - inline Kernel::UInt32 BlockSize() const { - if (!superblock) return kExt2FSBlockSizeBase; - return kExt2FSBlockSizeBase << superblock->fLogBlockSize; - } -}; - -inline bool ext2_read_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, void* buffer, - Kernel::UInt32 size) { - if (!drv || !buffer) return false; - - Kernel::DriveTrait::DrivePacket pkt{}; - pkt.fPacketContent = buffer; - pkt.fPacketSize = size; - pkt.fPacketLba = lba; - drv->fInput(pkt); - return pkt.fPacketGood; -} - -inline bool ext2_write_block(Kernel::DriveTrait* drv, Kernel::UInt32 lba, const void* buffer, - Kernel::UInt32 size) { - if (!drv || !buffer) return false; - - Kernel::DriveTrait::DrivePacket pkt{}; - pkt.fPacketContent = const_cast(buffer); - pkt.fPacketSize = size; - pkt.fPacketLba = lba; - drv->fOutput(pkt); - return pkt.fPacketGood; -} - -// Load superblock -inline Kernel::ErrorOr ext2_load_superblock(Context* ctx) { - if (!ctx || !ctx->drive) return Kernel::ErrorOr(Kernel::kErrorInvalidData); - - auto buf = Kernel::mm_alloc_ptr(sizeof(EXT2_SUPER_BLOCK), true, false); - if (!buf) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); - - Kernel::UInt32 blockLba = kExt2FSSuperblockOffset / ctx->drive->fSectorSz; - if (!ext2_read_block(ctx->drive, blockLba, buf, sizeof(EXT2_SUPER_BLOCK))) { - Kernel::mm_free_ptr(buf); - return Kernel::ErrorOr(Kernel::kErrorDisk); - } - - auto sb = reinterpret_cast(buf); - if (sb->fMagic != kExt2FSMagic) { - Kernel::mm_free_ptr(buf); - return Kernel::ErrorOr(Kernel::kErrorInvalidData); - } - - ctx->superblock = sb; - return Kernel::ErrorOr(sb); -} - -// Load inode -inline Kernel::ErrorOr ext2_load_inode(Context* ctx, Kernel::UInt32 inodeNumber) { - if (!ctx || !ctx->superblock) return Kernel::ErrorOr(Kernel::kErrorInvalidData); - - auto nodePtr = Kernel::mm_alloc_ptr(sizeof(Ext2Node), true, false); - if (!nodePtr) return Kernel::ErrorOr(Kernel::kErrorHeapOutOfMemory); - - auto ext2Node = reinterpret_cast(nodePtr); - ext2Node->inodeNumber = inodeNumber; - - // Compute block group and index within group - Kernel::UInt32 inodesPerGroup = ctx->superblock->fInodesPerGroup; - Kernel::UInt32 group = (inodeNumber - 1) / inodesPerGroup; - Kernel::UInt32 index = (inodeNumber - 1) % inodesPerGroup; - - // dummy: just offset first inode - Kernel::UInt32 inodeTableBlock = ctx->superblock->fFirstInode + group; - - if (!ext2_read_block(ctx->drive, inodeTableBlock, &ext2Node->inode, sizeof(EXT2_INODE))) { - Kernel::mm_free_ptr(nodePtr); - return Kernel::ErrorOr(Kernel::kErrorDisk); - } - - ext2Node->cursor = 0; - return Kernel::ErrorOr(ext2Node); -} - -inline Kernel::UInt32 inode_offset(const Context* ctx, Kernel::UInt32 inodeNumber) { - if (!ctx || !ctx->superblock) return 0; - return ((inodeNumber - 1) % ctx->superblock->fInodesPerGroup) * ctx->superblock->fInodeSize; -} - -} // namespace Ext2 diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 16670f5c..6f4d7e0a 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -119,7 +119,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { kGDTArray[4].fBaseHigh = 0; FB::fb_clear_video(); - + // Load memory descriptors. HAL::Register64 gdt_reg; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index 240b3ac8..b711b833 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -48,7 +48,7 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { /* INITIALIZE BIT MAP. */ /************************************** */ - kBitMapCursor = 0UL; + kBitMapCursor = 0UL; kKernelBitMpSize = kHandoverHeader->f_BitMapSize; kKernelBitMpStart = reinterpret_cast( reinterpret_cast(kHandoverHeader->f_BitMapStart)); diff --git a/dev/kernel/src/FS/Ext2+FileSystemParser.cc b/dev/kernel/src/FS/Ext2+FileSystemParser.cc index 80449ed9..318f83d6 100644 --- a/dev/kernel/src/FS/Ext2+FileSystemParser.cc +++ b/dev/kernel/src/FS/Ext2+FileSystemParser.cc @@ -6,7 +6,7 @@ #ifdef __FSKIT_INCLUDES_EXT2__ -#include +#include #include #include #include diff --git a/dev/launch/LaunchKit/LaunchKit.h b/dev/launch/LaunchKit/LaunchKit.h index 1a134e8f..2fa9607b 100644 --- a/dev/launch/LaunchKit/LaunchKit.h +++ b/dev/launch/LaunchKit/LaunchKit.h @@ -14,5 +14,7 @@ #define NELAUNCH_INFO(MSG) PrintOut(nullptr, "INFO: [LAUNCH] %s\n", MSG) #define NELAUNCH_WARN(MSG) PrintOut(nullptr, "WARN: [LAUNCH] %s\n", MSG) +namespace Launch { using LaunchHandle = VoidPtr; using KernelStatus = SInt32; +} // namespace Launch diff --git a/dev/launch/ne_launch.json b/dev/launch/ne_launch.json index 38379de9..e3d26a46 100644 --- a/dev/launch/ne_launch.json +++ b/dev/launch/ne_launch.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["../", "./"], - "sources_path": ["src/*.cc"], + "sources_path": ["src/*.cc", "src/*.S"], "output_name": "ne_launch", "compiler_flags": [ "-ffreestanding", diff --git a/dev/launch/src/CRT0.S b/dev/launch/src/CRT0.S new file mode 100644 index 00000000..ffc7398a --- /dev/null +++ b/dev/launch/src/CRT0.S @@ -0,0 +1,17 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + ------------------------------------------- */ + + .text + +.extern nelaunch_startup_fn + +_NeMain: + push %rbp + movq %rsp, %rbp + callq nelaunch_startup_fn + popq %rbp + + retq diff --git a/dev/launch/src/LaunchSrv.cc b/dev/launch/src/LaunchSrv.cc index 40027f65..f5c9ee3c 100644 --- a/dev/launch/src/LaunchSrv.cc +++ b/dev/launch/src/LaunchSrv.cc @@ -7,10 +7,11 @@ #include #include -SInt32 _NeMain(Void) { +/// @note This called by _NeMain from its own runtime. +extern "C" SInt32 nelaunch_startup_fn(Void) { /// @todo Start LaunchServices.fwrk services, make the launcher manageable too (via mgmt.launch) - NELAUNCH_INFO("Starting services..."); + NELAUNCH_INFO("Starting NeKernel services..."); return kErrorSuccess; } diff --git a/dev/libDDK/DriverKit/cpp/object.hpp b/dev/libDDK/DriverKit/cpp/object.hpp deleted file mode 100644 index 3bf52657..00000000 --- a/dev/libDDK/DriverKit/cpp/object.hpp +++ /dev/null @@ -1,16 +0,0 @@ -/* ------------------------------------------- - - Copyright Amlal El Mahrouss 2025, all rights reserved. - - FILE: ddk.h - PURPOSE: DDK Driver model base header. - - ------------------------------------------- */ - -#pragma once - -#include - -#define DK_INTERFACE_IMPL : public ::DKInterface - -class DKInterface; diff --git a/dev/libDDK/DriverKit/dki/contract.h b/dev/libDDK/DriverKit/dki/contract.h new file mode 100644 index 00000000..23884e02 --- /dev/null +++ b/dev/libDDK/DriverKit/dki/contract.h @@ -0,0 +1,32 @@ +/* ------------------------------------------- + + Copyright Amlal El Mahrouss 2025, all rights reserved. + + FILE: ddk.h + PURPOSE: Driver Kernel Interface Model base header. + + ------------------------------------------- */ + +#pragma once + +#include +#include + +#define DKI_CONTRACT_IMPL : public ::Kernel::DKIContract + +/// @author Amlal El Mahrouss + +namespace Kernel::DKI { +class DKIContract { + public: + explicit DKIContract() = default; + virtual ~DKIContract() = default; + + NE_COPY_DEFAULT(DKIContract); + + virtual BOOL IsCastable() { return false; } + virtual BOOL IsActive() { return false; } + virtual VoidPtr Leak() { return nullptr; } + virtual Int32 Type() { return 0; } +}; +} // namespace Kernel::DKI diff --git a/dev/libSystem/src/System.cc b/dev/libSystem/src/System.cc index ba848a18..2215c4d8 100644 --- a/dev/libSystem/src/System.cc +++ b/dev/libSystem/src/System.cc @@ -40,6 +40,12 @@ IMPORT_C UInt64 libsys_hash_64(const Char* path) { return hash; } +IMPORT_C Char* StrFmt(const Char* fmt, ...) { + if (!fmt || *fmt == 0) return const_cast("(null)"); + + return const_cast(""); +} + // memmove-style copy IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) { // handles overlap, prefers 64-bit word copies when aligned @@ -58,8 +64,9 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si // try 64-bit aligned backward copy if (len >= sizeof(UInt64) && (reinterpret_cast(rs) % sizeof(UInt64) == 0) && (reinterpret_cast(rd) % sizeof(UInt64) == 0)) { - auto rsw = reinterpret_cast(rs); - auto rdw = reinterpret_cast(rd); + auto rsw = reinterpret_cast(rs); + auto rdw = reinterpret_cast(rd); + SizeT words = len / sizeof(UInt64); for (SizeT i = 0; i < words; ++i) { @@ -105,9 +112,11 @@ IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input Si IMPORT_C SInt64 MmStrLen(const Char* in) { // strlen via pointer walk - if (!in) return 0; + if (!in) return -kErrorInvalidData; + const Char* p = in; while (*p) ++p; + return static_cast(p - in); } -- cgit v1.2.3