diff options
| -rwxr-xr-x | scripts/modules_ahci_x64.sh | 3 | ||||
| -rw-r--r-- | src/boot/amd64-desktop.make | 10 | ||||
| -rw-r--r-- | src/boot/modules/BootNet/amd64.json | 2 | ||||
| -rw-r--r-- | src/boot/modules/BootNet/arm64.json | 2 | ||||
| -rw-r--r-- | src/boot/modules/MemoryTest/MemoryTest.cpp | 30 | ||||
| -rw-r--r-- | src/boot/modules/MemoryTest/MemoryTestStartup.S | 24 | ||||
| -rw-r--r-- | src/boot/modules/MemoryTest/README.md | 3 | ||||
| -rw-r--r-- | src/boot/modules/MemoryTest/amd64.json | 35 | ||||
| -rw-r--r-- | src/boot/modules/MemoryTest/arm64.json | 35 | ||||
| -rw-r--r-- | src/boot/modules/SysChk/amd64-ahci-epm.json | 2 | ||||
| -rw-r--r-- | src/boot/modules/SysChk/amd64-ahci-gpt.json | 2 | ||||
| -rw-r--r-- | src/boot/modules/SysChk/amd64-pio-epm.json | 2 | ||||
| -rw-r--r-- | src/boot/modules/SysChk/amd64-pio-gpt.json | 2 | ||||
| -rw-r--r-- | src/boot/src/BootThread.cpp | 40 | ||||
| -rw-r--r-- | src/boot/src/HEL/AMD64/BootAPI.S | 7 | ||||
| -rw-r--r-- | src/boot/src/HEL/AMD64/BootEFI.cpp | 36 | ||||
| -rw-r--r-- | src/launch/.keep | 0 | ||||
| -rw-r--r-- | src/launch/src/RuntimeMain.cpp | 2 | ||||
| -rwxr-xr-x | tools/kconf.py | 13 | ||||
| -rwxr-xr-x | tools/kernel | 12 |
20 files changed, 190 insertions, 72 deletions
diff --git a/scripts/modules_ahci_x64.sh b/scripts/modules_ahci_x64.sh index a5c08ef8..ff58780d 100755 --- a/scripts/modules_ahci_x64.sh +++ b/scripts/modules_ahci_x64.sh @@ -9,3 +9,6 @@ nebuild amd64-ahci-epm.json cd ../ cd BootNet nebuild amd64.json +cd ../ +cd MemoryTest +nebuild amd64.json diff --git a/src/boot/amd64-desktop.make b/src/boot/amd64-desktop.make index 9379dc60..35904c89 100644 --- a/src/boot/amd64-desktop.make +++ b/src/boot/amd64-desktop.make @@ -49,12 +49,12 @@ DEBUG_MACRO = -D__DEBUG__ endif ifeq ($(KVM_SUPPORT),) -EMU_FLAGS=-M q35 -smp 8 -m 8G \ +EMU_FLAGS=-M q35 -smp 6 -m 8G \ -bios $(BIOS) -cdrom $(BOOT) -boot d endif ifneq ($(KVM_SUPPORT),) -EMU_FLAGS=-M q35 -smp 8 -m 8G \ +EMU_FLAGS=-M q35 -smp 6 -m 8G \ -bios $(BIOS) -M q35 -cdrom $(BOOT) -boot d -accel kvm endif @@ -75,8 +75,11 @@ BOOTLOADER=ne_bootz KERNEL=ne_kernel SYSCHK=chk.efi BOOTNET=net.efi +MEMTEST=memtest.efi SCIKIT=libSystem.dll DDK=libDDK.dll +POSIXWRAPPER=libPOSIXWrapper.dll +PTHREAD=libPThread.dll .PHONY: invalid-recipe invalid-recipe: @@ -92,7 +95,10 @@ all: compile-amd64 $(COPY) ../kernel/$(KERNEL) src/root/$(KERNEL) $(COPY) ./modules/SysChk/$(SYSCHK) src/root/$(SYSCHK) $(COPY) ./modules/BootNet/$(BOOTNET) src/root/$(BOOTNET) + $(COPY) ./modules/MemoryTest/$(MEMTEST) src/root/$(MEMTEST) $(COPY) ../libSystem/$(SCIKIT) src/root/$(SCIKIT) + $(COPY) ../libPOSIXWrapper/$(POSIXWRAPPER) src/root/$(POSIXWRAPPER) + # $(COPY) ../libPThread/$(PTHREAD) src/root/$(PTHREAD) $(COPY) src/$(BOOTLOADER) src/root/$(BOOTLOADER) $(COPY) ../libDDK/$(DDK) src/root/$(DDK) diff --git a/src/boot/modules/BootNet/amd64.json b/src/boot/modules/BootNet/amd64.json index 41ce26e1..e654b77c 100644 --- a/src/boot/modules/BootNet/amd64.json +++ b/src/boot/modules/BootNet/amd64.json @@ -21,7 +21,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,BootNetModuleMain" + "-Wl,--subsystem=17,--image-base,0x20000000,-e,BootNetModuleMain" ], "cpp_macros": [ "__BOOTZ__", diff --git a/src/boot/modules/BootNet/arm64.json b/src/boot/modules/BootNet/arm64.json index f939083e..bed477a4 100644 --- a/src/boot/modules/BootNet/arm64.json +++ b/src/boot/modules/BootNet/arm64.json @@ -21,7 +21,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,BootNetModuleMain" + "-Wl,--subsystem=17,--image-base,0x20000000,-e,BootNetModuleMain" ], "cpp_macros": [ "__BOOTZ__", diff --git a/src/boot/modules/MemoryTest/MemoryTest.cpp b/src/boot/modules/MemoryTest/MemoryTest.cpp new file mode 100644 index 00000000..49f28dcb --- /dev/null +++ b/src/boot/modules/MemoryTest/MemoryTest.cpp @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/ne-foss-org/nekernel + +#include <BootKit/BootKit.h> +#include <BootKit/BootThread.h> +#include <FirmwareKit/EFI/API.h> + +EXTERN_C Int32 MemoryTestModuleMain(Kernel::HEL::BootInfoHeader* handover) { + fw_init_efi((EfiSystemTable*) handover->f_FirmwareCustomTables[Kernel::HEL::kHandoverTableST]); + + Boot::BootTextWriter writer; + writer.Write("MemoryTest: Testing Memory...\r"); + + constexpr auto kTestValue = 0x20000000L; + + Int32* mem = (Int32*) kTestValue; + if (!mem) return kEfiFail; + + auto prev = *mem; + *mem = 42; + if (*mem != 42) { + return kEfiFail; + } + + *mem = prev; + + return kEfiOk; +} diff --git a/src/boot/modules/MemoryTest/MemoryTestStartup.S b/src/boot/modules/MemoryTest/MemoryTestStartup.S new file mode 100644 index 00000000..a5832ee6 --- /dev/null +++ b/src/boot/modules/MemoryTest/MemoryTestStartup.S @@ -0,0 +1,24 @@ +;; /* +;; * ======================================================== +;; * +;; * BootZ +;; * Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. +;; * +;; * ======================================================== +;; */ + +#ifdef __NE_AMD64__ +.code64 +.intel_syntax noprefix +#endif + +#define kTypeDriver 101 +#define kArchAmd64 122 +#define kHandoverMagic 0xBADCC + +.section .ldr + +.quad kHandoverMagic +.word kTypeDriver +.word 0 +.word kArchAmd64
\ No newline at end of file diff --git a/src/boot/modules/MemoryTest/README.md b/src/boot/modules/MemoryTest/README.md new file mode 100644 index 00000000..fac97400 --- /dev/null +++ b/src/boot/modules/MemoryTest/README.md @@ -0,0 +1,3 @@ +# MemoryTest: + +This module tests the memory of a x64 machine by allocating to it. diff --git a/src/boot/modules/MemoryTest/amd64.json b/src/boot/modules/MemoryTest/amd64.json new file mode 100644 index 00000000..8d1f8bd3 --- /dev/null +++ b/src/boot/modules/MemoryTest/amd64.json @@ -0,0 +1,35 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": [ + "../", + "../../", + "../../../kernel", + "../../../", + "./" + ], + "sources_path": [ + "*.cpp", + "*.S", + "../../src/HEL/AMD64/*.cpp", + "../../src/HEL/AMD64/*.S", + "../../src/*.cpp" + ], + "output_name": "memtest.efi", + "compiler_flags": [ + "-nostdlib", + "-std=c++20", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17,--image-base,0x20000000,-e,MemoryTestModuleMain" + ], + "cpp_macros": [ + "__BOOTZ__", + "__BOOTZ_STANDALONE__", + "__NE_AMD64__", + "__nekernel_max_cores=8 ", + "kMemTestVersionHighest=0x0100", + "kMemTestVersionLowest=0x0100", + "kMemTestEFIVersion=0x0100" + ] +} diff --git a/src/boot/modules/MemoryTest/arm64.json b/src/boot/modules/MemoryTest/arm64.json new file mode 100644 index 00000000..41590bb4 --- /dev/null +++ b/src/boot/modules/MemoryTest/arm64.json @@ -0,0 +1,35 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": [ + "../", + "../../", + "../../../kernel", + "../../../", + "./" + ], + "sources_path": [ + "*.cpp", + "*.S", + "../../src/HEL/ARM64/*.cpp", + "../../src/HEL/ARM64/*.S", + "../../src/*.cpp" + ], + "output_name": "memtest.efi", + "compiler_flags": [ + "-nostdlib", + "-std=c++20", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17,--image-base,0x20000000,-e,MemoryTestModuleMain" + ], + "cpp_macros": [ + "__BOOTZ__", + "__BOOTZ_STANDALONE__", + "__NE_ARM64__", + "__nekernel_max_cores=8 ", + "kMemTestVersionHighest=0x0100", + "kMemTestVersionLowest=0x0100", + "kMemTestEFIVersion=0x0100" + ] +} diff --git a/src/boot/modules/SysChk/amd64-ahci-epm.json b/src/boot/modules/SysChk/amd64-ahci-epm.json index 1fa10f60..99037618 100644 --- a/src/boot/modules/SysChk/amd64-ahci-epm.json +++ b/src/boot/modules/SysChk/amd64-ahci-epm.json @@ -26,7 +26,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + "-Wl,--subsystem=17,--image-base,0x20000000,-e,SysChkModuleMain" ], "cpp_macros": [ "__NEOSKRNL__", diff --git a/src/boot/modules/SysChk/amd64-ahci-gpt.json b/src/boot/modules/SysChk/amd64-ahci-gpt.json index 4baf1393..d9160952 100644 --- a/src/boot/modules/SysChk/amd64-ahci-gpt.json +++ b/src/boot/modules/SysChk/amd64-ahci-gpt.json @@ -26,7 +26,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + "-Wl,--subsystem=17,--image-base,0x20000000,-e,SysChkModuleMain" ], "cpp_macros": [ "__NEOSKRNL__", diff --git a/src/boot/modules/SysChk/amd64-pio-epm.json b/src/boot/modules/SysChk/amd64-pio-epm.json index 7e4b1d4e..ffcca945 100644 --- a/src/boot/modules/SysChk/amd64-pio-epm.json +++ b/src/boot/modules/SysChk/amd64-pio-epm.json @@ -31,7 +31,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + "-Wl,--subsystem=17,--image-base,0x20000000,-e,SysChkModuleMain" ], "cpp_macros": [ "__NEOSKRNL__", diff --git a/src/boot/modules/SysChk/amd64-pio-gpt.json b/src/boot/modules/SysChk/amd64-pio-gpt.json index d954daed..5457f8a9 100644 --- a/src/boot/modules/SysChk/amd64-pio-gpt.json +++ b/src/boot/modules/SysChk/amd64-pio-gpt.json @@ -24,7 +24,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" + "-Wl,--subsystem=17,--image-base,0x20000000,-e,SysChkModuleMain" ], "cpp_macros": [ "__NEOSKRNL__", diff --git a/src/boot/src/BootThread.cpp b/src/boot/src/BootThread.cpp index 16e368c3..19d7e8f8 100644 --- a/src/boot/src/BootThread.cpp +++ b/src/boot/src/BootThread.cpp @@ -13,9 +13,10 @@ #include <KernelKit/PE.h> #include <KernelKit/PEF.h> #include <modules/CoreGfx/TextGfx.h> +#include "FirmwareKit/Handover.h" // \brief This macro defines the maximum size of a image's stack. -#define kBootThreadSz mib_cast(16) +#define kBootThreadSz kib_cast(8) /// @brief External boot services symbol. EXTERN EfiBootServices* BS; @@ -78,13 +79,6 @@ BootThread::BootThread(VoidPtr blob) : fStartAddress(nullptr), fBlob(blob) { writer.Write("BootZ: Image-Base: ").Write(loadStartAddress).Write("\r"); - fStack = new UInt8[kBootThreadSz]; - - if (!fStack) { - writer.Write("BootZ: Unable to allocate the stack for the thread.\r"); - return; - } - LDR_SECTION_HEADER_PTR sectPtr = (LDR_SECTION_HEADER_PTR) (((Char*) opt_header_ptr) + header_ptr->SizeOfOptionalHeader); @@ -179,36 +173,16 @@ Int32 BootThread::Start(HEL::BootInfoHeader* handover, Bool own_stack) { return kEfiFail; } + NE_UNUSED(own_stack); + fHandover = handover; BootTextWriter writer; + writer.Write("BootThread: ").Write(fBlobName).Write("\r"); - writer.Write("BootZ: Starting: ").Write(fBlobName).Write("\r"); - writer.Write("BootZ: Handover address: ").Write((UIntPtr) fHandover).Write("\r"); - - if (own_stack) { - writer.Write("BootZ: Using it's own stack.\r"); - writer.Write("BootZ: Stack address: ").Write((UIntPtr) &fStack[kBootThreadSz - 1]).Write("\r"); - writer.Write("BootZ: Stack size: ").Write(kBootThreadSz).Write("\r"); - - fHandover->f_StackTop = &fStack[kBootThreadSz - 1]; - fHandover->f_StackSz = kBootThreadSz; - - auto ret = rt_jump_to_address(fStartAddress, fHandover, &fStack[kBootThreadSz - 1]); - - // we don't need the stack anymore. - - delete[] fStack; - fStack = nullptr; - - return ret; - } else { - writer.Write("BootZ: Using the bootloader's stack.\r"); - - return reinterpret_cast<HEL::HandoverProc>(fStartAddress)(fHandover); - } + auto ret = ((HEL::HandoverProc)fStartAddress)(fHandover); - return kEfiFail; + return ret; } const Char* BootThread::GetName() { diff --git a/src/boot/src/HEL/AMD64/BootAPI.S b/src/boot/src/HEL/AMD64/BootAPI.S index 33c1f5d3..a3c37c78 100644 --- a/src/boot/src/HEL/AMD64/BootAPI.S +++ b/src/boot/src/HEL/AMD64/BootAPI.S @@ -28,16 +28,9 @@ sched_jump_to_task: rt_jump_to_address: mov rbx, rcx mov rcx, rdx - push rbx - push rdx mov rsp, r8 - push rax jmp rbx - pop rdx - pop rbx - pop rax - ret rt_reset_hardware: diff --git a/src/boot/src/HEL/AMD64/BootEFI.cpp b/src/boot/src/HEL/AMD64/BootEFI.cpp index 70f440b3..d552e325 100644 --- a/src/boot/src/HEL/AMD64/BootEFI.cpp +++ b/src/boot/src/HEL/AMD64/BootEFI.cpp @@ -74,7 +74,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa Boot::Stop(); } - writer.Write("BootZ: The NeKernel Bootloader. Copyright 2024-2026, Amlal El Mahrouss and al.\r"); + writer.Write("BootZ: The NeKernel Loader. Copyright 2024-2026, Amlal El Mahrouss and al.\r"); for (SizeT index_vt = 0; index_vt < sys_table->NumberOfTableEntries; ++index_vt) { Char* vendor_table = @@ -120,10 +120,10 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa if (mp) { mp->GetNumberOfProcessors(mp, &cnt_disabled, &cnt_enabled); - kHandoverHeader->f_NumberOfProcessors = cnt_enabled; + kHandoverHeader->f_NumberOfProcessors = cnt_enabled; handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1; } else { - handover_hdr->f_NumberOfProcessors = 1; + handover_hdr->f_NumberOfProcessors = 1; handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = NO; } @@ -180,6 +180,18 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa syschk_thread->Start(handover_hdr, NO); } + Boot::BootFileReader reader_memtest(L"memtest.efi", image_handle); + reader_memtest.ReadAll(0); + + if (reader_memtest.Blob()) { + auto memtest_thread = new Boot::BootThread(reader_memtest.Blob()); + + if (memtest_thread) { + memtest_thread->SetName("MemoryTest"); + memtest_thread->Start(handover_hdr, NO); + } + } + handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); handover_hdr->f_Magic = kHandoverMagic; @@ -245,16 +257,20 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa handover_hdr->f_KernelImage = reader_kernel.Blob(); handover_hdr->f_KernelSz = reader_kernel.Size(); - kernel_thread.Start(handover_hdr, YES); + return kernel_thread.Start(handover_hdr, YES); } - Boot::BootFileReader reader_netboot(L"net.efi", image_handle); - reader_netboot.ReadAll(0); + Boot::BootFileReader reader_net(L"memtest.efi", image_handle); + reader_net.ReadAll(0); - if (!reader_netboot.Blob()) return kEfiFail; + if (reader_net.Blob()) { + auto net_thread = new Boot::BootThread(reader_net.Blob()); - auto netboot_thread = Boot::BootThread(reader_netboot.Blob()); - netboot_thread.SetName("BootNet"); + if (net_thread) { + net_thread->SetName("BootNet"); + net_thread->Start(handover_hdr, NO); + } + } - return netboot_thread.Start(handover_hdr, NO); + return kEfiFail; } diff --git a/src/launch/.keep b/src/launch/.keep deleted file mode 100644 index e69de29b..00000000 --- a/src/launch/.keep +++ /dev/null diff --git a/src/launch/src/RuntimeMain.cpp b/src/launch/src/RuntimeMain.cpp index dc379d54..1a08ece6 100644 --- a/src/launch/src/RuntimeMain.cpp +++ b/src/launch/src/RuntimeMain.cpp @@ -9,7 +9,7 @@ /// @note This called by _NeMain from its own runtime. IMPORT_C SInt32 launch_startup_fn(Void) { - /// Start LaunchHelpers.fwrk services, and make the launcher manageable too (via mgmt.launch) + /// start the LaunchHelpers.fwrk service, and make the launcher scheduable too (via mgmt.launch) UInt32* ret = static_cast<UInt32*>(libsys_syscall_arg_1( libsys_hash_64("__launch_register_service"))); // Register service based on program data. diff --git a/tools/kconf.py b/tools/kconf.py deleted file mode 100755 index a54d6244..00000000 --- a/tools/kconf.py +++ /dev/null @@ -1,13 +0,0 @@ -#! /usr/bin/env python3 -# -*- coding: utf-8 -*- - -import os, json, sys - -if __name__ == '__main__': - print("kconf: running kernel as standalone...") - os.system("../scripts/debug_ahci_x64.sh") - sys.exit(0) - - - - diff --git a/tools/kernel b/tools/kernel new file mode 100755 index 00000000..733e81f7 --- /dev/null +++ b/tools/kernel @@ -0,0 +1,12 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os, sys + +KERNEL_SCRIPT="./scripts/debug_ahci_x64.sh" + +if __name__ == '__main__': + print("kconf: Running kernel...") + os.system(KERNEL_SCRIPT) + sys.exit(0) + |
