From a01ba7acb4786a6354349408b3bcc4c2d007b274 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 14 Apr 2025 09:42:28 +0200 Subject: bootloader, netboot: integrate EFI_SIMPLE_NETWORK_PROTOCOL for HTTP-based kernel fetching - Added BootNet module to support network boot using EFI_SIMPLE_NETWORK_PROTOCOL - Replaced ModuleMain with BootloaderMain as unified entry point - Implemented EFI protocol discovery, startup, and logging for netboot - Updated linker scripts, GDB configs, and build targets accordingly - Laid groundwork for full HTTP/TCP/IP bootloader logic - Improved kernel handoff logic and memory allocation fallback handling Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/AMD64/BootEFI.cc | 25 +++++++------- dev/boot/src/HEL/ARM64/BootEFI.cc | 71 +++++++++++++++++++++++++++++---------- 2 files changed, 65 insertions(+), 31 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 4220c6cb..a818fcd6 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -73,19 +73,19 @@ STATIC Bool boot_init_fb() noexcept EfiGUID kEfiGlobalNamespaceVarGUID = { 0x8BE4DF61, 0x93CA, 0x11D2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C}}; -/// @brief ModuleMain EFI entrypoint. +/// @brief BootloaderMain EFI entrypoint. /// @param image_handle Handle of this image. /// @param sys_table The system table of it. /// @return nothing, never returns. -EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, - EfiSystemTable* sys_table) +EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, + EfiSystemTable* sys_table) { - InitEFI(sys_table); ///! Init the EFI library. + fw_init_efi(sys_table); ///! Init the EFI library. HEL::BootInfoHeader* handover_hdr = new HEL::BootInfoHeader(); - UInt32 map_key = 0; + UInt32 map_key = 0; #ifdef ZBA_USE_FB if (!boot_init_fb()) @@ -163,12 +163,10 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, Boot::BootTextWriter writer; - //-------------------------------------------------------------// - // Update handover file specific table and phyiscal start field. - //-------------------------------------------------------------// + handover_hdr->f_BitMapStart = nullptr; /* Start of bitmap. */ + handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ - handover_hdr->f_BitMapSize = gib_cast(4); /* Size of bitmap in bytes. */ - Int32 trials = 5 * 10000000; + Int32 trials = 5 * 10000000; while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) { @@ -180,7 +178,7 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, trials = 3 * 10000000; - handover_hdr->f_BitMapSize = gib_cast(2); /* Size of bitmap in bytes. */ + handover_hdr->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */ while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) { @@ -221,8 +219,6 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, FBDrawBitMapInRegion(zka_no_disk, NE_NO_DISK_WIDTH, NE_NO_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_NO_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_NO_DISK_HEIGHT) / 2); fb_clear(); - - Boot::Stop(); } } @@ -288,6 +284,7 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, kernel_thread->SetName("BootZ: Kernel"); handover_hdr->f_KernelImage = reader_kernel.Blob(); + handover_hdr->f_KernelSz = reader_kernel.Size(); } else { @@ -297,6 +294,8 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, Boot::Stop(); } + // Fallback to bootnet, if not PXE. + Boot::BootFileReader reader_netboot(L"net.efi", image_handle); reader_netboot.ReadAll(0); diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index b6f28351..72ac310b 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -18,11 +18,6 @@ #include #include -// Makes the compiler shut up. -#ifndef kMachineModel -#define kMachineModel "NeKernel" -#endif // !kMachineModel - #ifndef kExpectedWidth #define kExpectedWidth (1920) #endif @@ -74,14 +69,14 @@ STATIC Bool boot_init_fb() noexcept EXTERN EfiBootServices* BS; -/// @brief ModuleMain EFI entrypoint. +/// @brief BootloaderMain EFI entrypoint. /// @param image_handle Handle of this image. /// @param sys_table The system table of it. /// @return nothing, never returns. -EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, - EfiSystemTable* sys_table) +EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, + EfiSystemTable* sys_table) { - InitEFI(sys_table); ///! Init the EFI library. + fw_init_efi(sys_table); ///! Init the EFI library. HEL::BootInfoHeader* handover_hdr = new HEL::BootInfoHeader(); @@ -133,9 +128,9 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, EfiMpServicesProtocol* mp = nullptr; BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast(&mp)); - handover_hdr->f_HardwareTables.f_MpPtr = reinterpret_cast(mp); + // Assign to global 'kHandoverHeader'. kHandoverHeader = handover_hdr; fb_init(); @@ -160,18 +155,59 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, } //-------------------------------------------------------------// - // Update handover file specific table and phyiscal start field. + // Allocate heap. //-------------------------------------------------------------// + Boot::BootTextWriter writer; + handover_hdr->f_BitMapStart = nullptr; /* Start of bitmap. */ - handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap. */ + handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ + Int32 trials = 5 * 10000000; while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) { - if (handover_hdr->f_BitMapStart) + --trials; + + if (!trials) + { + writer.Write("BootZ: Unable to allocate sufficent memory, trying again with 2GB...\r"); + + trials = 3 * 10000000; + + handover_hdr->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */ + + while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) + { + --trials; + + if (!trials) + { + writer.Write("BootZ: Unable to allocate sufficent memory, aborting...\r"); + Boot::Stop(); + } + } + } + } + + Boot::BootFileReader reader_syschk(L"chk.efi", image_handle); + reader_syschk.ReadAll(0); + + Boot::BootThread* syschk_thread = nullptr; + + if (reader_syschk.Blob()) + { + syschk_thread = new Boot::BootThread(reader_syschk.Blob()); + syschk_thread->SetName("BootZ: System Check"); + + if (syschk_thread->Start(handover_hdr, NO) != kEfiOk) { - BS->FreePool(handover_hdr->f_BitMapStart); - handover_hdr->f_BitMapStart = nullptr; + fb_init(); + + FB::fb_clear_video(); + + FBDrawBitMapInRegion(zka_no_disk, NE_NO_DISK_WIDTH, NE_NO_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_NO_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_NO_DISK_HEIGHT) / 2); + + fb_clear(); } } @@ -194,8 +230,6 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); - // Assign to global 'kHandoverHeader'. - Boot::BootFileReader reader_kernel(L"vmkrnl.efi", image_handle); reader_kernel.ReadAll(0); @@ -207,9 +241,10 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle, if (reader_kernel.Blob()) { auto kernel_thread = Boot::BootThread(reader_kernel.Blob()); - kernel_thread.SetName("BootZ: MicroKernel."); + kernel_thread.SetName("BootZ: Kernel."); handover_hdr->f_KernelImage = reader_kernel.Blob(); + handover_hdr->f_KernelSz = reader_kernel.Size(); Boot::ExitBootServices(map_key, image_handle); -- cgit v1.2.3 From 011a2801505c01f433d399fa5cb077bee11f4bed Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 15 Apr 2025 07:30:32 +0200 Subject: ARM64, BootEFI.cc: Cleanup parts of unused code. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/ARM64/BootEFI.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index 72ac310b..8008d846 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -19,11 +19,11 @@ #include #ifndef kExpectedWidth -#define kExpectedWidth (1920) +#define kExpectedWidth (800) #endif #ifndef kExpectedHeight -#define kExpectedHeight (1080) +#define kExpectedHeight (600) #endif /** Graphics related. */ @@ -82,10 +82,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, new HEL::BootInfoHeader(); UInt32 map_key = 0; - UInt32 size_struct_ptr = sizeof(EfiMemoryDescriptor); - EfiMemoryDescriptor* struct_ptr = nullptr; - UInt32 sz_desc = sizeof(EfiMemoryDescriptor); - UInt32 rev_desc = 0; #ifdef ZBA_USE_FB if (!boot_init_fb()) -- cgit v1.2.3 From 4f7562afaee939467299efdb6b7fac159f6cbd27 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 15 Apr 2025 08:43:30 +0200 Subject: fix, kernel, boot, mod: Fixing issues regarding the boot flow and the kernel. Signed-off-by: Amlal El Mahrouss --- .github/workflows/kernel-ahci.yml | 2 +- .github/workflows/kernel-pio.yml | 2 +- README.md | 2 +- dev/boot/amd64-ci.make | 2 +- dev/boot/amd64-desktop.make | 4 +- dev/boot/modules/BootNet/BootNet.cc | 25 +++--- dev/boot/modules/BootNet/amd64.json | 1 - dev/boot/modules/SysChk/SysChk.cc | 2 + dev/boot/modules/SysChk/amd64-ahci.json | 1 - dev/boot/modules/SysChk/amd64-pio.json | 1 - dev/boot/src/BootThread.cc | 2 +- dev/boot/src/HEL/AMD64/BootEFI.cc | 88 +++++++++------------- dev/kernel/CompilerKit/Version.h | 4 +- dev/kernel/FirmwareKit/EFI/API.h | 2 +- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 3 +- dev/kernel/HALKit/AMD64/HalTimerAMD64.cc | 2 +- dev/kernel/KernelKit/Timer.h | 2 +- dev/kernel/amd64-desktop.make | 2 +- dev/user/user.json | 1 - modules_ahci_x64.sh | 11 +++ modules_pio_x64.sh | 11 +++ .../CoreFoundation.fwrk/CoreFoundation.json | 1 - public/frameworks/DiskImage.fwrk/DiskImage.json | 1 - public/frameworks/KernelTest.fwrk/KernelTest.json | 1 - setup_amd64.sh | 20 ----- setup_x64.sh | 14 ++++ 26 files changed, 99 insertions(+), 108 deletions(-) create mode 100755 modules_ahci_x64.sh create mode 100755 modules_pio_x64.sh delete mode 100755 setup_amd64.sh create mode 100755 setup_x64.sh (limited to 'dev/boot/src/HEL') diff --git a/.github/workflows/kernel-ahci.yml b/.github/workflows/kernel-ahci.yml index 51cb54a3..a76865c0 100644 --- a/.github/workflows/kernel-ahci.yml +++ b/.github/workflows/kernel-ahci.yml @@ -16,5 +16,5 @@ jobs: - name: Install Packages run: sudo apt update && sudo apt install mingw-w64 qemu-utils nasm - name: Build NeKernel (AHCI) - run: ./setup_amd64.sh && cd dev/kernel && export AHCI_SUPPORT=1 && make -f amd64-ci.make all + run: ./setup_x64.sh && cd dev/kernel && export AHCI_SUPPORT=1 && make -f amd64-ci.make all diff --git a/.github/workflows/kernel-pio.yml b/.github/workflows/kernel-pio.yml index 57f6faee..e6a205b3 100644 --- a/.github/workflows/kernel-pio.yml +++ b/.github/workflows/kernel-pio.yml @@ -16,5 +16,5 @@ jobs: - name: Install Packages run: sudo apt update && sudo apt install mingw-w64 qemu-utils nasm - name: Build NeKernel (ATA PIO) - run: ./setup_amd64.sh && cd dev/kernel && export ATA_PIO_SUPPORT=1 && make -f amd64-ci.make all + run: ./setup_x64.sh && cd dev/kernel && export ATA_PIO_SUPPORT=1 && make -f amd64-ci.make all diff --git a/README.md b/README.md index 041257c7..f26df2ba 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ A documentation regarding building, and developing for NeKernel is available her ```sh git clone git@github.com:amlel-el-mahrouss/nekernel.git cd nekernel -./setup_amd64.sh +./setup_x64.sh ./debug_ata_x64.sh # Generic ATA PIO target ``` diff --git a/dev/boot/amd64-ci.make b/dev/boot/amd64-ci.make index 9ee61eed..62ab9af1 100644 --- a/dev/boot/amd64-ci.make +++ b/dev/boot/amd64-ci.make @@ -88,7 +88,7 @@ all: compile-amd64 .PHONY: disk disk: - dd if=/dev/zero of=$(BOOT) bs=30M count=100 + dd if=/dev/zero of=$(BOOT) bs=7M count=100 mformat -i $(BOOT) -F -v "NeKernel" diff --git a/dev/boot/amd64-desktop.make b/dev/boot/amd64-desktop.make index 3ed2ba3f..21a99941 100644 --- a/dev/boot/amd64-desktop.make +++ b/dev/boot/amd64-desktop.make @@ -96,7 +96,7 @@ all: compile-amd64 .PHONY: disk disk: - dd if=/dev/zero of=$(BOOT) bs=30M count=100 + dd if=/dev/zero of=$(BOOT) bs=7M count=100 mformat -i $(BOOT) -F -v "NEKERNEL-ESP" @@ -128,7 +128,7 @@ run-efi-amd64-ata-dma: .PHONY: run-efi-amd64-ata run-efi-amd64-ata: run-efi-amd64-ata-dma -# img_2 is the rescue disk. img is the bootable disk, as provided by the Zeta specs. +# img_2 is the rescue disk. img is the bootable disk, as provided by the NeKernel specs. .PHONY: epm-img epm-img: qemu-img create -f raw $(IMG) 4G diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index 28d96cb2..050148c4 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -15,18 +15,19 @@ STATIC EfiGUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; -STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER&); +STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER); EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) { - fw_init_efi((EfiSystemTable*)handover->f_FirmwareCustomTables[0]); + Boot::BootTextWriter writer; + writer.Write("BootNet: Init EFI...\r"); - Boot::BootTextWriter writer; + fw_init_efi((EfiSystemTable*)handover->f_FirmwareCustomTables[1]); if (BS->LocateProtocol(&kEfiSimpleProtoGUID, nullptr, (VoidPtr*)&kEfiProtocol) != kEfiOk) { - writer.Write("[BOOT] BootNet: Not supported by firmware.\r"); + writer.Write("BootNet: Not supported by firmware.\r"); return kEfiFail; } @@ -34,13 +35,13 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) SetMem(&inet, 0, sizeof(BOOTNET_INTERNET_HEADER)); - writer.Write("[BOOT] BootNet: Downloading kernel...\r"); + writer.Write("BootNet: Downloading kernel...\r"); bootnet_read_ip_packet(inet); if (inet.Length < 1) { - writer.Write("[BOOT] BootNet: No executable attached to the packet, aborting.\r"); + writer.Write("BootNet: No executable attached to the packet, aborting.\r"); return kEfiFail; } @@ -50,7 +51,7 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) if (thread.IsValid()) { - writer.Write("[BOOT] BootNet: Running kernel...\r"); + writer.Write("BootNet: Running kernel...\r"); return thread.Start(handover, YES); } @@ -62,11 +63,11 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) if (inet.Length != kROMSize) { - writer.Write("[BOOT] BootNet: Not within 512K.\r"); + writer.Write("BootNet: Not within 512K.\r"); return kEfiFail; } - writer.Write("[BOOT] BootNet: Programming the flash is not available as of right now.\r"); + writer.Write("BootNet: Programming the flash is not available as of right now.\r"); /// TODO: Program new firmware to EEPROM (if crc and size matches) @@ -77,11 +78,7 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) return kEfiFail; } -STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER& inet) +STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet) { - kEfiProtocol->Start(kEfiProtocol); - NE_UNUSED(inet); - - kEfiProtocol->Stop(kEfiProtocol); } \ No newline at end of file diff --git a/dev/boot/modules/BootNet/amd64.json b/dev/boot/modules/BootNet/amd64.json index 7b87b533..7e5fd018 100644 --- a/dev/boot/modules/BootNet/amd64.json +++ b/dev/boot/modules/BootNet/amd64.json @@ -7,7 +7,6 @@ "compiler_flags": [ "-nostdlib", "-std=c++20", - "-fPIC", "-fno-rtti", "-fno-exceptions", "-Wl,--subsystem=17,--image-base,0x4000000,-e,BootNetModuleMain" diff --git a/dev/boot/modules/SysChk/SysChk.cc b/dev/boot/modules/SysChk/SysChk.cc index 3086cdc6..dec4e11a 100644 --- a/dev/boot/modules/SysChk/SysChk.cc +++ b/dev/boot/modules/SysChk/SysChk.cc @@ -28,6 +28,8 @@ EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover) { + NE_UNUSED(handover); + #ifdef __ATA_PIO__ Boot::BDiskFormatFactory partition_factory; diff --git a/dev/boot/modules/SysChk/amd64-ahci.json b/dev/boot/modules/SysChk/amd64-ahci.json index 98e570f4..1377c23b 100644 --- a/dev/boot/modules/SysChk/amd64-ahci.json +++ b/dev/boot/modules/SysChk/amd64-ahci.json @@ -7,7 +7,6 @@ "compiler_flags": [ "-nostdlib", "-std=c++20", - "-fPIC", "-fno-rtti", "-fno-exceptions", "-Wl,--subsystem=17,--image-base,0x4000000,-e,SysChkModuleMain" diff --git a/dev/boot/modules/SysChk/amd64-pio.json b/dev/boot/modules/SysChk/amd64-pio.json index 2b159e38..879f651f 100644 --- a/dev/boot/modules/SysChk/amd64-pio.json +++ b/dev/boot/modules/SysChk/amd64-pio.json @@ -7,7 +7,6 @@ "compiler_flags": [ "-nostdlib", "-std=c++20", - "-fPIC", "-fno-rtti", "-fno-exceptions", "-Wl,--subsystem=17,--image-base,0x4000000,-e,SysChkModuleMain" diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc index ce691f96..3f399d66 100644 --- a/dev/boot/src/BootThread.cc +++ b/dev/boot/src/BootThread.cc @@ -216,4 +216,4 @@ namespace Boot { return fStartAddress != nullptr; } -} // namespace Boot +} // namespace Boot \ 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 a818fcd6..795e43cf 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -82,18 +82,25 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, { fw_init_efi(sys_table); ///! Init the EFI library. + fb_init(); + HEL::BootInfoHeader* handover_hdr = new HEL::BootInfoHeader(); - UInt32 map_key = 0; + UInt32 map_key = 0; + UInt32 size_struct_ptr = sizeof(EfiMemoryDescriptor); + EfiMemoryDescriptor* struct_ptr = nullptr; + UInt32 sz_desc = sizeof(EfiMemoryDescriptor); + UInt32 rev_desc = 0; + + Boot::BootTextWriter writer; + + writer.Write("BootZ: NeKernel Loader.\r"); -#ifdef ZBA_USE_FB if (!boot_init_fb()) { - Boot::BootTextWriter writer; writer.Write("BootZ: Invalid Framebuffer, can't boot NeKernel.\r"); - - CANT_REACH(); + Boot::Stop(); } for (SizeT index_vt = 0; index_vt < sys_table->NumberOfTableEntries; @@ -123,7 +130,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, handover_hdr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine; handover_hdr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat; handover_hdr->f_GOP.f_Size = kGop->Mode->FrameBufferSize; -#endif // ZBA_USE_FB // ------------------------------------------- // // Grab MP services, extended to runtime. // @@ -138,14 +144,10 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, kHandoverHeader = handover_hdr; - fb_init(); - FB::fb_clear_video(); FBDrawBitMapInRegion(zka_disk, NE_DISK_WIDTH, NE_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_DISK_HEIGHT) / 2); - fb_clear(); - UInt32 cnt_enabled = 0; UInt32 cnt_disabled = 0; @@ -161,13 +163,13 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, // Fill handover header now. - Boot::BootTextWriter writer; - handover_hdr->f_BitMapStart = nullptr; /* Start of bitmap. */ handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ Int32 trials = 5 * 10000000; + writer.Write("BootZ: Allocating sufficent memory, trying with 4GB...\r"); + while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk) { --trials; @@ -212,22 +214,16 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, if (syschk_thread->Start(handover_hdr, NO) != kEfiOk) { - fb_init(); - FB::fb_clear_video(); - FBDrawBitMapInRegion(zka_no_disk, NE_NO_DISK_WIDTH, NE_NO_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_NO_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_NO_DISK_HEIGHT) / 2); - - fb_clear(); } } - // ------------------------------------------ // - // null these fields, to avoid being reused later. - // ------------------------------------------ // + BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); + + struct_ptr = new EfiMemoryDescriptor[sz_desc]; - handover_hdr->f_FirmwareCustomTables[0] = nullptr; - handover_hdr->f_FirmwareCustomTables[1] = nullptr; + BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); @@ -263,11 +259,13 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, ver = KERNEL_VERSION_BCD; ST->RuntimeServices->SetVariable(L"/props/kern_ver", kEfiGlobalNamespaceVarGUID, nullptr, &sz_ver, &ver); - writer.Write("BootZ: Kernel Version Updated: ").Write(ver).Write("\r"); + writer.Write("BootZ: Kernel Version has been updated: ").Write(ver).Write("\r"); } writer.Write("BootZ: Kernel Version: ").Write(ver).Write("\r"); + // Fallback to bootnet, if not PXE. + Boot::BootFileReader reader_kernel(kernel_path, image_handle); reader_kernel.ReadAll(0); @@ -280,46 +278,32 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, if (reader_kernel.Blob()) { + // ------------------------------------------ // + // null these fields, to avoid being reused later. + // ------------------------------------------ // + + handover_hdr->f_FirmwareCustomTables[0] = nullptr; + handover_hdr->f_FirmwareCustomTables[1] = nullptr; + kernel_thread = new Boot::BootThread(reader_kernel.Blob()); kernel_thread->SetName("BootZ: Kernel"); handover_hdr->f_KernelImage = reader_kernel.Blob(); handover_hdr->f_KernelSz = reader_kernel.Size(); - } - else - { - fb_init(); - FBDrawBitMapInRegion(zka_no_disk, NE_NO_DISK_WIDTH, NE_NO_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_NO_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_NO_DISK_HEIGHT) / 2); - Boot::Stop(); - } + Boot::ExitBootServices(map_key, image_handle); - // Fallback to bootnet, if not PXE. + return kernel_thread->Start(handover_hdr, NO); + } Boot::BootFileReader reader_netboot(L"net.efi", image_handle); reader_netboot.ReadAll(0); - Boot::BootThread* netboot_thread = nullptr; - - // ---------------------------------------------------- // - // Finally load the OS kernel. - // ---------------------------------------------------- // - - Boot::ExitBootServices(map_key, image_handle); - - if (kernel_thread->Start(handover_hdr, YES) != kEfiOk) - { - // ------------------------------------------ // - // If we fail into booting the kernel, then run BootNet. - // ------------------------------------------ // + if (!reader_netboot.Blob()) + return kEfiFail; - if (reader_netboot.Blob()) - { - netboot_thread = new Boot::BootThread(reader_netboot.Blob()); - netboot_thread->SetName("BootZ: BootNet"); - netboot_thread->Start(handover_hdr, YES); - } - } + Boot::BootThread* netboot_thread = new Boot::BootThread(reader_netboot.Blob()); + netboot_thread->SetName("BootZ: BootNet"); - CANT_REACH(); + return netboot_thread->Start(handover_hdr, NO); } diff --git a/dev/kernel/CompilerKit/Version.h b/dev/kernel/CompilerKit/Version.h index 0d53b5ed..0f4f863d 100644 --- a/dev/kernel/CompilerKit/Version.h +++ b/dev/kernel/CompilerKit/Version.h @@ -6,5 +6,5 @@ #define BOOTLOADER_VERSION "1104.2025.110" #define KERNEL_VERSION "1104.2025.110" -#define BOOTLOADER_VERSION_BCD 0x11042025110 -#define KERNEL_VERSION_BCD 0x11042025110 +#define BOOTLOADER_VERSION_BCD 0x20250415 +#define KERNEL_VERSION_BCD 0x20250415 diff --git a/dev/kernel/FirmwareKit/EFI/API.h b/dev/kernel/FirmwareKit/EFI/API.h index 9140d131..f3b03bb5 100644 --- a/dev/kernel/FirmwareKit/EFI/API.h +++ b/dev/kernel/FirmwareKit/EFI/API.h @@ -48,7 +48,7 @@ namespace Boot @brief Exit EFI API to let the OS load correctly. Bascially frees everything we have in the EFI side. */ - inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept + inline Void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept { if (!ST) return; diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 7ce1b0d8..9ede8ebd 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -13,6 +13,7 @@ #include #include #include +#include EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; EXTERN_C Kernel::VoidPtr mp_user_switch_proc; @@ -84,8 +85,6 @@ EXTERN_C void hal_init_platform( gdt_reg.Base = reinterpret_cast(kGDTArray); gdt_reg.Limit = (sizeof(Kernel::HAL::Detail::NE_GDT_ENTRY) * kGDTEntriesCount) - 1; - FB::fb_clear_video(); - //! GDT will load hal_read_init after it successfully loads the segments. Kernel::HAL::GDTLoader gdt_loader; gdt_loader.Load(gdt_reg); diff --git a/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc b/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc index 01be2be5..72de8eb0 100644 --- a/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalTimerAMD64.cc @@ -45,7 +45,7 @@ namespace Kernel::Detail using namespace Kernel; -HardwareTimer::HardwareTimer(Int64 ms) +HardwareTimer::HardwareTimer(UInt64 ms) : fWaitFor(ms) { auto power = PowerFactoryInterface(kHandoverHeader->f_HardwareTables.f_VendorPtr); diff --git a/dev/kernel/KernelKit/Timer.h b/dev/kernel/KernelKit/Timer.h index fa26bc66..b6d23e6b 100644 --- a/dev/kernel/KernelKit/Timer.h +++ b/dev/kernel/KernelKit/Timer.h @@ -50,7 +50,7 @@ namespace Kernel class HardwareTimer final : public TimerInterface { public: - explicit HardwareTimer(Int64 seconds); + explicit HardwareTimer(UInt64 seconds); ~HardwareTimer() override; public: diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index 8541d5a0..905a6c91 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -33,7 +33,7 @@ COPY = cp ASMFLAGS = -f win64 # Kernel subsystem is 17 and entrypoint is hal_init_platform -LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x10000000 +LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000 LDOBJ = obj/*.obj # This file is the Kernel, responsible of task, memory, driver, sci, disk and device management. diff --git a/dev/user/user.json b/dev/user/user.json index 481280f8..9581d4d4 100644 --- a/dev/user/user.json +++ b/dev/user/user.json @@ -5,7 +5,6 @@ "sources_path": ["src/*.cc", "src/*.o"], "output_name": "user.sys", "compiler_flags": [ - "-fPIC", "-ffreestanding", "-shared", "-fno-rtti", diff --git a/modules_ahci_x64.sh b/modules_ahci_x64.sh new file mode 100755 index 00000000..44e3ecf5 --- /dev/null +++ b/modules_ahci_x64.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# LOG HISTORY: +# 03/25/25: Add 'disk' build step. +# 04/05/25: Improve and fix script. + +cd dev/boot/modules/SysChk +btb amd64-ahci.json +cd ../ +cd BootNet +btb amd64.json \ No newline at end of file diff --git a/modules_pio_x64.sh b/modules_pio_x64.sh new file mode 100755 index 00000000..2b501047 --- /dev/null +++ b/modules_pio_x64.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# LOG HISTORY: +# 03/25/25: Add 'disk' build step. +# 04/05/25: Improve and fix script. + +cd dev/boot/modules/SysChk +btb amd64-pio.json +cd ../ +cd BootNet +btb amd64.json \ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json b/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json index e8ee3245..a208f57a 100644 --- a/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json +++ b/public/frameworks/CoreFoundation.fwrk/CoreFoundation.json @@ -5,7 +5,6 @@ "sources_path": ["src/*.cc"], "output_name": "./dist/libCoreFoundation.dylib", "compiler_flags": [ - "-fPIC", "-ffreestanding", "-shared", "-fno-rtti", diff --git a/public/frameworks/DiskImage.fwrk/DiskImage.json b/public/frameworks/DiskImage.fwrk/DiskImage.json index 0b97dafb..aaff409c 100644 --- a/public/frameworks/DiskImage.fwrk/DiskImage.json +++ b/public/frameworks/DiskImage.fwrk/DiskImage.json @@ -5,7 +5,6 @@ "sources_path": ["src/*.cc"], "output_name": "./dist/libDiskImage.dylib", "compiler_flags": [ - "-fPIC", "-ffreestanding", "-shared", "-fno-rtti", diff --git a/public/frameworks/KernelTest.fwrk/KernelTest.json b/public/frameworks/KernelTest.fwrk/KernelTest.json index 93207890..aa70db30 100644 --- a/public/frameworks/KernelTest.fwrk/KernelTest.json +++ b/public/frameworks/KernelTest.fwrk/KernelTest.json @@ -5,7 +5,6 @@ "sources_path": ["src/*.cc"], "output_name": "./dist/libKernelTest.dylib", "compiler_flags": [ - "-fPIC", "-ffreestanding", "-shared", "-fno-rtti", diff --git a/setup_amd64.sh b/setup_amd64.sh deleted file mode 100755 index 717f7840..00000000 --- a/setup_amd64.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# LOG HISTORY: -# 03/25/25: Add 'disk' build step. -# 04/05/25: Improve and fix script. - -cd dev/boot/modules/SysChk -btb amd64.json -cd ../ -cd BootNet -btb amd64.json -cd ../../../ -cd user -btb user.json -cd ../boot -make -f amd64-desktop.make efi -make -f amd64-desktop.make disk -make -f amd64-desktop.make epm-img -cd ../../dev/kernel/HALKit/AMD64 -./make_ap_blob.sh diff --git a/setup_x64.sh b/setup_x64.sh new file mode 100755 index 00000000..35111b88 --- /dev/null +++ b/setup_x64.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# LOG HISTORY: +# 03/25/25: Add 'disk' build step. +# 04/05/25: Improve and fix script. + +cd dev/user +btb user.json +cd ../boot +make -f amd64-desktop.make efi +make -f amd64-desktop.make disk +make -f amd64-desktop.make epm-img +cd ../../dev/kernel/HALKit/AMD64 +./make_ap_blob.sh -- cgit v1.2.3 From 58b3d776ab5435de352217b2a3a525aeb9316e99 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 16 Apr 2025 17:13:31 +0200 Subject: dev, kernel, boot: fix dumb early-init which caused the kernel to jump at IVT. Signed-off-by: Amlal El Mahrouss --- dev/boot/modules/BootNet/amd64.json | 2 +- dev/boot/modules/SysChk/amd64-ahci.json | 2 +- dev/boot/modules/SysChk/amd64-pio.json | 2 +- dev/boot/src/BootThread.cc | 26 ++------------- dev/boot/src/HEL/AMD64/BootAPI.S | 9 +++-- dev/boot/src/HEL/AMD64/BootEFI.cc | 32 +++++++----------- dev/kernel/FirmwareKit/Handover.h | 6 ++++ dev/kernel/HALKit/AMD64/HalDebugOutput.cc | 2 +- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 55 +++++++++++++------------------ dev/kernel/amd64-ci.make | 2 +- dev/kernel/amd64-desktop.make | 4 +-- 11 files changed, 55 insertions(+), 87 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/modules/BootNet/amd64.json b/dev/boot/modules/BootNet/amd64.json index 7e5fd018..912eeb0b 100644 --- a/dev/boot/modules/BootNet/amd64.json +++ b/dev/boot/modules/BootNet/amd64.json @@ -9,7 +9,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x4000000,-e,BootNetModuleMain" + "-Wl,--subsystem=17,--image-base,0x10000000,-e,BootNetModuleMain" ], "cpp_macros": [ "__NEOSKRNL__", diff --git a/dev/boot/modules/SysChk/amd64-ahci.json b/dev/boot/modules/SysChk/amd64-ahci.json index 1377c23b..d13e6c4a 100644 --- a/dev/boot/modules/SysChk/amd64-ahci.json +++ b/dev/boot/modules/SysChk/amd64-ahci.json @@ -9,7 +9,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x4000000,-e,SysChkModuleMain" + "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" ], "cpp_macros": [ "__NEOSKRNL__", diff --git a/dev/boot/modules/SysChk/amd64-pio.json b/dev/boot/modules/SysChk/amd64-pio.json index 879f651f..f15a8efd 100644 --- a/dev/boot/modules/SysChk/amd64-pio.json +++ b/dev/boot/modules/SysChk/amd64-pio.json @@ -9,7 +9,7 @@ "-std=c++20", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x4000000,-e,SysChkModuleMain" + "-Wl,--subsystem=17,--image-base,0x10000000,-e,SysChkModuleMain" ], "cpp_macros": [ "__NEOSKRNL__", diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc index 3f399d66..f1866a76 100644 --- a/dev/boot/src/BootThread.cc +++ b/dev/boot/src/BootThread.cc @@ -166,40 +166,18 @@ namespace Boot /// @note handover header has to be valid! Int32 BootThread::Start(HEL::BootInfoHeader* handover, Bool own_stack) { - HEL::HandoverProc err_fn = [](HEL::BootInfoHeader* rcx) -> Int32 { - NE_UNUSED(rcx); - - fb_render_string("BootZ: Invalid Boot Image...", 50, 10, RGB(0xFF, 0xFF, 0xFF)); - ::Boot::Stop(); - - return NO; - }; - - if (!fStartAddress) - { - err_fn(handover); - } - fHandover = handover; if (own_stack) { - UInt8* aligned_stack = &fStack[mib_cast(16) - 1]; - aligned_stack = (UInt8*)((UIntPtr)aligned_stack & ~0xF); - - rt_jump_to_address(fStartAddress, fHandover, aligned_stack); + return rt_jump_to_address(fStartAddress, fHandover, &fStack[mib_cast(16) - 1]); } else { - if (fStack) - delete[] fStack; - - fStack = nullptr; - return reinterpret_cast(fStartAddress)(fHandover); } - return kEfiOk; + return kEfiFail; } const Char* BootThread::GetName() diff --git a/dev/boot/src/HEL/AMD64/BootAPI.S b/dev/boot/src/HEL/AMD64/BootAPI.S index c4a7ad39..963ef46a 100644 --- a/dev/boot/src/HEL/AMD64/BootAPI.S +++ b/dev/boot/src/HEL/AMD64/BootAPI.S @@ -11,11 +11,16 @@ rt_jump_to_address: mov rbx, rcx mov rcx, rdx + push rbx + push rdx mov rsp, r8 - - cli + push rax jmp rbx + pop rdx + pop rbx + pop rax + ret rt_reset_hardware: diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 795e43cf..fa0cb74b 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -82,8 +82,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, { fw_init_efi(sys_table); ///! Init the EFI library. - fb_init(); - HEL::BootInfoHeader* handover_hdr = new HEL::BootInfoHeader(); @@ -146,7 +144,9 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, FB::fb_clear_video(); + fb_init(); FBDrawBitMapInRegion(zka_disk, NE_DISK_WIDTH, NE_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_DISK_HEIGHT) / 2); + fb_clear(); UInt32 cnt_enabled = 0; UInt32 cnt_disabled = 0; @@ -221,10 +221,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); - struct_ptr = new EfiMemoryDescriptor[sz_desc]; - - BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc); - handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); handover_hdr->f_Magic = kHandoverMagic; @@ -259,19 +255,17 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, ver = KERNEL_VERSION_BCD; ST->RuntimeServices->SetVariable(L"/props/kern_ver", kEfiGlobalNamespaceVarGUID, nullptr, &sz_ver, &ver); - writer.Write("BootZ: Kernel Version has been updated: ").Write(ver).Write("\r"); + writer.Write("BootZ: version has been updated: ").Write(ver).Write("\r"); } - writer.Write("BootZ: Kernel Version: ").Write(ver).Write("\r"); + writer.Write("BootZ: version: ").Write(ver).Write("\r"); - // Fallback to bootnet, if not PXE. + // boot to kernel, if not netboot this. Boot::BootFileReader reader_kernel(kernel_path, image_handle); reader_kernel.ReadAll(0); - Boot::BootThread* kernel_thread = nullptr; - // ------------------------------------------ // // If we succeed in reading the blob, then execute it. // ------------------------------------------ // @@ -282,18 +276,14 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, // null these fields, to avoid being reused later. // ------------------------------------------ // - handover_hdr->f_FirmwareCustomTables[0] = nullptr; - handover_hdr->f_FirmwareCustomTables[1] = nullptr; + auto kernel_thread = Boot::BootThread(reader_kernel.Blob()); - kernel_thread = new Boot::BootThread(reader_kernel.Blob()); - kernel_thread->SetName("BootZ: Kernel"); + kernel_thread.SetName("BootZ: Kernel"); handover_hdr->f_KernelImage = reader_kernel.Blob(); handover_hdr->f_KernelSz = reader_kernel.Size(); - Boot::ExitBootServices(map_key, image_handle); - - return kernel_thread->Start(handover_hdr, NO); + kernel_thread.Start(handover_hdr, YES); } Boot::BootFileReader reader_netboot(L"net.efi", image_handle); @@ -302,8 +292,8 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, if (!reader_netboot.Blob()) return kEfiFail; - Boot::BootThread* netboot_thread = new Boot::BootThread(reader_netboot.Blob()); - netboot_thread->SetName("BootZ: BootNet"); + auto netboot_thread = Boot::BootThread(reader_netboot.Blob()); + netboot_thread.SetName("BootZ: BootNet"); - return netboot_thread->Start(handover_hdr, NO); + return netboot_thread.Start(handover_hdr, NO); } diff --git a/dev/kernel/FirmwareKit/Handover.h b/dev/kernel/FirmwareKit/Handover.h index 22d96ca9..ecdaca64 100644 --- a/dev/kernel/FirmwareKit/Handover.h +++ b/dev/kernel/FirmwareKit/Handover.h @@ -17,6 +17,7 @@ #pragma once +#include "FirmwareKit/EFI/EFI.h" #include #define kHandoverMagic 0xBADCC @@ -70,6 +71,11 @@ namespace Kernel::HEL WideChar f_FirmwareVendorName[32]; SizeT f_FirmwareVendorLen; +#ifdef __NE_AMD64__ + UInt32 f_EFIImageKey; + EfiHandlePtr f_EFIImage; +#endif + VoidPtr f_FirmwareCustomTables[2]; // On EFI 0: BS 1: ST struct diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc index 0ee7eef0..b69614fd 100644 --- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc @@ -181,7 +181,7 @@ namespace Kernel TerminalDevice TerminalDevice::The() noexcept { - static TerminalDevice out(Kernel::ke_io_write, Kernel::ke_io_read); + TerminalDevice out(Kernel::ke_io_write, Kernel::ke_io_read); return out; } diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 9ede8ebd..60df6a12 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -4,6 +4,7 @@ ------------------------------------------- */ +#include "modules/CoreGfx/CoreGfx.h" #include #include #include @@ -15,6 +16,10 @@ #include #include +#include +#include + + EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; EXTERN_C Kernel::VoidPtr mp_user_switch_proc; EXTERN_C Kernel::Char mp_user_switch_proc_stack_begin[]; @@ -28,32 +33,25 @@ STATIC Kernel::Void hal_init_scheduler_team() } } -STATIC Kernel::UInt64 hal_rdtsc_fn() +/// @brief Kernel init procedure. +EXTERN_C Int32 hal_init_platform( + Kernel::HEL::BootInfoHeader* handover_hdr) { - Kernel::UInt32 lo = 0, hi = 0; - - asm volatile("rdtsc" - : "=a"(lo), "=d"(hi)); + if (handover_hdr->f_Magic != kHandoverMagic && + handover_hdr->f_Version != kHandoverVersion) + { + return kEfiFail; + } - return ((Kernel::UInt64)hi << 32) | lo; -} + FB::fb_clear_video(); -STATIC Kernel::UInt64 kStartTim, kEndTim; + (Void)(Kernel::kout << "Welcome to NeKernel.\r"); -/// @brief Kernel init procedure. -EXTERN_C void hal_init_platform( - Kernel::HEL::BootInfoHeader* handover_hdr) -{ - kStartTim = hal_rdtsc_fn(); + fw_init_efi((EfiSystemTable*)handover_hdr->f_FirmwareCustomTables[1]); + Boot::ExitBootServices(handover_hdr->f_EFIImageKey, handover_hdr->f_EFIImage); kHandoverHeader = handover_hdr; - if (kHandoverHeader->f_Magic != kHandoverMagic && - kHandoverHeader->f_Version != kHandoverVersion) - { - return; - } - hal_init_scheduler_team(); /************************************** */ @@ -85,33 +83,24 @@ EXTERN_C void hal_init_platform( gdt_reg.Base = reinterpret_cast(kGDTArray); gdt_reg.Limit = (sizeof(Kernel::HAL::Detail::NE_GDT_ENTRY) * kGDTEntriesCount) - 1; + Kernel::NeFS::fs_init_nefs(); + + Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); + //! GDT will load hal_read_init after it successfully loads the segments. Kernel::HAL::GDTLoader gdt_loader; gdt_loader.Load(gdt_reg); - Kernel::ke_panic(RUNTIME_CHECK_BOOTSTRAP); + return kEfiFail; } EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { - kEndTim = hal_rdtsc_fn(); - - (void)(Kernel::kout << "Boot Time: " << Kernel::number(kEndTim - kStartTim) << Kernel::kendl); - - Kernel::NeFS::fs_init_nefs(); - - Kernel::HAL::mp_get_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - Kernel::HAL::Register64 idt_reg; - idt_reg.Base = (Kernel::UIntPtr)kInterruptVectorTable; Kernel::HAL::IDTLoader idt_loader; - kEndTim = hal_rdtsc_fn(); - - (void)(Kernel::kout << "Init Time: " << Kernel::number(kEndTim - kStartTim) << Kernel::kendl); - idt_loader.Load(idt_reg); dbg_break_point(); diff --git a/dev/kernel/amd64-ci.make b/dev/kernel/amd64-ci.make index 9e881123..e9a4d4b0 100644 --- a/dev/kernel/amd64-ci.make +++ b/dev/kernel/amd64-ci.make @@ -5,7 +5,7 @@ CXX = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -Werror -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__NE_SUPPORT_NX__ -O0 -I../Vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../zba +CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -Werror -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot ASM = nasm diff --git a/dev/kernel/amd64-desktop.make b/dev/kernel/amd64-desktop.make index 905a6c91..02b0a3b4 100644 --- a/dev/kernel/amd64-desktop.make +++ b/dev/kernel/amd64-desktop.make @@ -5,7 +5,7 @@ CXX = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld -CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__NE_SUPPORT_NX__ -O0 -I../Vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../zba +CCFLAGS = -fshort-wchar -c -D__NE_AMD64__ -Wall -Wpedantic -Wextra -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__NE_SUPPORT_NX__ -O0 -I../vendor -D__FSKIT_INCLUDES_NEFS__ -D__NEOSKRNL__ -D__HAVE_NE_APIS__ -D__FREESTANDING__ -D__NE_VIRTUAL_MEMORY_SUPPORT__ -D__NE_AUTO_FORMAT__ -D__NE__ -I./ -I../ -I../boot ASM = nasm @@ -33,7 +33,7 @@ COPY = cp ASMFLAGS = -f win64 # Kernel subsystem is 17 and entrypoint is hal_init_platform -LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x4000000 +LDFLAGS = -e hal_init_platform --subsystem=17 --image-base 0x10000000 LDOBJ = obj/*.obj # This file is the Kernel, responsible of task, memory, driver, sci, disk and device management. -- cgit v1.2.3