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 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