From e4c4041182480e96d52d289204d7f5363e6be3e4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 4 Jun 2025 14:41:29 +0200 Subject: meta: Ran `./format.sh` Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/AMD64/BootATA.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/src/HEL/AMD64/BootATA.cc b/dev/boot/src/HEL/AMD64/BootATA.cc index e5e0d8c2..25810222 100644 --- a/dev/boot/src/HEL/AMD64/BootATA.cc +++ b/dev/boot/src/HEL/AMD64/BootATA.cc @@ -88,7 +88,8 @@ ATAInit_Retry: /// fetch serial info /// model, speed, number of sectors... - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) + ; for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { kATAData[indexData] = rt_in16(IO + ATA_REG_DATA); @@ -114,14 +115,15 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf, rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) + ; for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); @@ -147,14 +149,15 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeASCII* Buf rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) &0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); rt_out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)); + while (!(rt_in8(IO + ATA_REG_STATUS) & ATA_SR_DRQ)) + ; for (SizeT IndexOff = 0; IndexOff < Size; IndexOff += 2) { boot_ata_wait_io(IO); -- cgit v1.2.3 From 1f41e2bf786864ea59fd6944325094cc3becd26a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Jun 2025 18:19:48 +0200 Subject: fix: aarch64: Don't exit Boot Services, when the kernel already does it. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/ARM64/BootEFI.cc | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 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 66f91352..c420530d 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -116,16 +116,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // Assign to global 'kHandoverHeader'. 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; @@ -169,28 +159,6 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa } } - 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) { - 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. // ------------------------------------------ // @@ -220,13 +188,11 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa if (reader_kernel.Blob()) { auto kernel_thread = Boot::BootThread(reader_kernel.Blob()); - kernel_thread.SetName("BootZ: Kernel."); + kernel_thread.SetName("Kernel Task"); handover_hdr->f_KernelImage = reader_kernel.Blob(); handover_hdr->f_KernelSz = reader_kernel.Size(); - Boot::ExitBootServices(map_key, image_handle); - kernel_thread.Start(handover_hdr, YES); } -- cgit v1.2.3 From bdf7d346db02e9c20602128e086c6db32930176d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Jun 2025 20:54:03 +0200 Subject: feat: Update thread name for `ne_kernel`'s aarch64 version in BootZ. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/ARM64/BootEFI.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 c420530d..0421d1cf 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -188,7 +188,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa if (reader_kernel.Blob()) { auto kernel_thread = Boot::BootThread(reader_kernel.Blob()); - kernel_thread.SetName("Kernel Task"); + kernel_thread.SetName("NeKernel"); handover_hdr->f_KernelImage = reader_kernel.Blob(); handover_hdr->f_KernelSz = reader_kernel.Size(); -- cgit v1.2.3 From 8288ab6da7c536de303fdd3fb2e282d75ec0fa48 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 8 Jun 2025 09:40:01 +0200 Subject: fix: boot/arm64: fix `rt_jump_to_address` why? - It wasn't a conform procedure here, made it ABI compliant on clang. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/ARM64/BootAPI.S | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/src/HEL/ARM64/BootAPI.S b/dev/boot/src/HEL/ARM64/BootAPI.S index a60ad218..6896ed0c 100644 --- a/dev/boot/src/HEL/ARM64/BootAPI.S +++ b/dev/boot/src/HEL/ARM64/BootAPI.S @@ -6,7 +6,7 @@ @brief this function setups a stack and then jumps to a function */ rt_jump_to_address: - mov x19, x0 - mov sp, x2 - blr x19 + mov sp, x10 + br x9 + ret -- cgit v1.2.3 From 731a1400a00e4203f2409163156a5ec38cca4224 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 8 Jun 2025 09:58:46 +0200 Subject: fix: Fix argument registers usage inside jump proc. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/ARM64/BootAPI.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/src/HEL/ARM64/BootAPI.S b/dev/boot/src/HEL/ARM64/BootAPI.S index 6896ed0c..55183abf 100644 --- a/dev/boot/src/HEL/ARM64/BootAPI.S +++ b/dev/boot/src/HEL/ARM64/BootAPI.S @@ -6,7 +6,7 @@ @brief this function setups a stack and then jumps to a function */ rt_jump_to_address: - mov sp, x10 - br x9 + mov sp, x1 + br x0 ret -- cgit v1.2.3 From 98b47e78991d4cc7712e98e6dc1496aa0f0fcf38 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 10 Jun 2025 09:08:35 +0200 Subject: feat: boot: Better checks in BootThread, and cleanup BootEFI's init on AArch64. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/BootThread.cc | 6 ++-- dev/boot/src/HEL/ARM64/BootEFI.cc | 65 ++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 38 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc index 5566e3e0..c477d659 100644 --- a/dev/boot/src/BootThread.cc +++ b/dev/boot/src/BootThread.cc @@ -156,16 +156,16 @@ BootThread::BootThread(VoidPtr blob) : fStartAddress(nullptr), fBlob(blob) { /// @note handover header has to be valid! Int32 BootThread::Start(HEL::BootInfoHeader* handover, Bool own_stack) { - fHandover = handover; - if (!fStartAddress) { return kEfiFail; } - if (!fHandover) { + if (!handover) { return kEfiFail; } + fHandover = handover; + BootTextWriter writer; writer.Write("BootZ: Starting: ").Write(fBlobName).Write("\r"); diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index 0421d1cf..44c6a778 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -71,12 +71,10 @@ EXTERN EfiBootServices* BS; EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTable* sys_table) { fw_init_efi(sys_table); ///! Init the EFI library. - HEL::BootInfoHeader* handover_hdr = new HEL::BootInfoHeader(); - - UInt32 map_key = 0; + kHandoverHeader = new HEL::BootInfoHeader(); #ifdef ZBA_USE_FB - if (!boot_init_fb()) return 1; ///! Init the GOP. + if (!boot_init_fb()) return kEfiFail; ///! Init the GOP. for (SizeT index_vt = 0; index_vt < sys_table->NumberOfTableEntries; ++index_vt) { Char* vendor_table = @@ -86,7 +84,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa if (vendor_table[0] == 'R' && vendor_table[1] == 'S' && vendor_table[2] == 'D' && vendor_table[3] == ' ' && vendor_table[4] == 'P' && vendor_table[5] == 'T' && vendor_table[6] == 'R' && vendor_table[7] == ' ') { - handover_hdr->f_HardwareTables.f_VendorPtr = (VoidPtr) vendor_table; + kHandoverHeader->f_HardwareTables.f_VendorPtr = (VoidPtr) vendor_table; break; } } @@ -95,12 +93,12 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // draw background color. // ------------------------------------------ // - handover_hdr->f_GOP.f_The = kGop->Mode->FrameBufferBase; - handover_hdr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution; - handover_hdr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution; - 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; + kHandoverHeader->f_GOP.f_The = kGop->Mode->FrameBufferBase; + kHandoverHeader->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution; + kHandoverHeader->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution; + kHandoverHeader->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine; + kHandoverHeader->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat; + kHandoverHeader->f_GOP.f_Size = kGop->Mode->FrameBufferSize; #endif // ZBA_USE_FB // ------------------------------------------- // @@ -111,19 +109,16 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa 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; + kHandoverHeader->f_HardwareTables.f_MpPtr = reinterpret_cast(mp); UInt32 cnt_enabled = 0; UInt32 cnt_disabled = 0; if (mp) { mp->GetNumberOfProcessors(mp, &cnt_disabled, &cnt_enabled); - handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1; + kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1; } else { - handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = NO; + kHandoverHeader->f_HardwareTables.f_MultiProcessingEnabled = NO; } //-------------------------------------------------------------// @@ -132,12 +127,12 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa Boot::BootTextWriter writer; - handover_hdr->f_BitMapStart = nullptr; /* Start of bitmap. */ - handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ + kHandoverHeader->f_BitMapStart = nullptr; /* Start of bitmap. */ + kHandoverHeader->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) { + while (BS->AllocatePool(EfiLoaderData, kHandoverHeader->f_BitMapSize, + &kHandoverHeader->f_BitMapStart) != kEfiOk) { --trials; if (!trials) { @@ -145,10 +140,10 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa trials = 3 * 10000000; - handover_hdr->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */ + kHandoverHeader->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */ - while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, - &handover_hdr->f_BitMapStart) != kEfiOk) { + while (BS->AllocatePool(EfiLoaderData, kHandoverHeader->f_BitMapSize, + &kHandoverHeader->f_BitMapStart) != kEfiOk) { --trials; if (!trials) { @@ -163,20 +158,20 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // null these fields, to avoid being reused later. // ------------------------------------------ // - handover_hdr->f_FirmwareCustomTables[0] = nullptr; - handover_hdr->f_FirmwareCustomTables[1] = nullptr; + kHandoverHeader->f_FirmwareCustomTables[0] = nullptr; + kHandoverHeader->f_FirmwareCustomTables[1] = nullptr; - handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); + kHandoverHeader->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); - handover_hdr->f_Magic = kHandoverMagic; - handover_hdr->f_Version = kHandoverVersion; + kHandoverHeader->f_Magic = kHandoverMagic; + kHandoverHeader->f_Version = kHandoverVersion; // Provide fimware vendor name. - Boot::BCopyMem(handover_hdr->f_FirmwareVendorName, sys_table->FirmwareVendor, - handover_hdr->f_FirmwareVendorLen); + Boot::BCopyMem(kHandoverHeader->f_FirmwareVendorName, sys_table->FirmwareVendor, + kHandoverHeader->f_FirmwareVendorLen); - handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); + kHandoverHeader->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor); Boot::BootFileReader reader_kernel(L"ne_kernel", image_handle); @@ -190,10 +185,10 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa auto kernel_thread = Boot::BootThread(reader_kernel.Blob()); kernel_thread.SetName("NeKernel"); - handover_hdr->f_KernelImage = reader_kernel.Blob(); - handover_hdr->f_KernelSz = reader_kernel.Size(); + kHandoverHeader->f_KernelImage = reader_kernel.Blob(); + kHandoverHeader->f_KernelSz = reader_kernel.Size(); - kernel_thread.Start(handover_hdr, YES); + kernel_thread.Start(kHandoverHeader, YES); } CANT_REACH(); -- cgit v1.2.3 From f0f5c992ff0216e2e33f84751d5a389ebfb017b8 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 10 Jun 2025 09:15:04 +0200 Subject: fix: better allocation system in BootZ (aarch, amd64) Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/AMD64/BootEFI.cc | 20 ++++++++++---------- dev/boot/src/HEL/ARM64/BootEFI.cc | 9 +++++---- 2 files changed, 15 insertions(+), 14 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 166e0169..24bee2dd 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -128,28 +128,28 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa handover_hdr->f_BitMapStart = nullptr; /* Start of bitmap. */ handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ - Int32 trials = 5 * 10000000; + kHandoverHeader->f_BitMapStart = nullptr; /* Start of bitmap. */ + kHandoverHeader->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ - writer.Write("BootZ: Welcome to BootZ.\r"); - writer.Write("BootZ: Allocating sufficient memory, trying 4GB...\r"); + UInt16 trials = 5; - while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, - &handover_hdr->f_BitMapStart) != kEfiOk) { + while (BS->AllocatePool(EfiLoaderData, kHandoverHeader->f_BitMapSize, + &kHandoverHeader->f_BitMapStart) != kEfiOk) { --trials; if (!trials) { writer.Write("BootZ: Unable to allocate sufficient memory, trying again with 2GB...\r"); - trials = 3 * 10000000; + trials = 3; - handover_hdr->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */ + kHandoverHeader->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */ - while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, - &handover_hdr->f_BitMapStart) != kEfiOk) { + while (BS->AllocatePool(EfiLoaderData, kHandoverHeader->f_BitMapSize, + &kHandoverHeader->f_BitMapStart) != kEfiOk) { --trials; if (!trials) { - writer.Write("BootZ: Unable to allocate sufficent memory, aborting...\r"); + writer.Write("BootZ: Unable to allocate sufficient memory, aborting...\r"); Boot::Stop(); } } diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index 44c6a778..12ace024 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -129,16 +129,17 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa kHandoverHeader->f_BitMapStart = nullptr; /* Start of bitmap. */ kHandoverHeader->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ - Int32 trials = 5 * 10000000; + + UInt16 trials = 5; while (BS->AllocatePool(EfiLoaderData, kHandoverHeader->f_BitMapSize, &kHandoverHeader->f_BitMapStart) != kEfiOk) { --trials; if (!trials) { - writer.Write("BootZ: Unable to allocate sufficent memory, trying again with 2GB...\r"); + writer.Write("BootZ: Unable to allocate sufficient memory, trying again with 2GB...\r"); - trials = 3 * 10000000; + trials = 3; kHandoverHeader->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */ @@ -147,7 +148,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa --trials; if (!trials) { - writer.Write("BootZ: Unable to allocate sufficent memory, aborting...\r"); + writer.Write("BootZ: Unable to allocate sufficient memory, aborting...\r"); Boot::Stop(); } } -- cgit v1.2.3 From a5851dfaa65d15f44f52b2aed1aa0179291b46fc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 12 Jun 2025 02:54:29 +0200 Subject: feat: libSystem, kernel: finalizing the hash and routing system of libSystem's handlers. feat: Rework TTY, and CD-ROM API too. Signed-off-by: Amlal El Mahrouss --- dev/boot/modules/BootNet/BootNet.cc | 2 +- dev/boot/src/HEL/ARM64/BootEFI.cc | 4 ++-- dev/kernel/ArchKit/ArchKit.h | 2 +- dev/kernel/FirmwareKit/CoreBoot/BootNet.h | 10 ++++---- dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc | 28 +++++++++++----------- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 5 +++- dev/libSystem/SystemKit/System.h | 10 +++++--- 7 files changed, 34 insertions(+), 27 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index d4f8c1fc..8236dd0d 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -48,7 +48,7 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) { writer.Write("BootNet: The version clashes, not good.\r"); return kEfiFail; } - + if (!inet_out->ImpliesProgram) { Boot::BootThread thread(inet_out->Data); diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index 12ace024..467cae23 100644 --- a/dev/boot/src/HEL/ARM64/BootEFI.cc +++ b/dev/boot/src/HEL/ARM64/BootEFI.cc @@ -129,8 +129,8 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa kHandoverHeader->f_BitMapStart = nullptr; /* Start of bitmap. */ kHandoverHeader->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ - - UInt16 trials = 5; + + UInt16 trials = 5; while (BS->AllocatePool(EfiLoaderData, kHandoverHeader->f_BitMapSize, &kHandoverHeader->f_BitMapStart) != kEfiOk) { diff --git a/dev/kernel/ArchKit/ArchKit.h b/dev/kernel/ArchKit/ArchKit.h index 09839d98..a9dca240 100644 --- a/dev/kernel/ArchKit/ArchKit.h +++ b/dev/kernel/ArchKit/ArchKit.h @@ -70,7 +70,7 @@ namespace HAL { typedef Kernel::Void (*rt_syscall_proc)(Kernel::VoidPtr); struct HAL_DISPATCH_ENTRY final { - Kernel::Int64 fHash; + Kernel::UInt64 fHash; Kernel::Bool fHooked; rt_syscall_proc fProc; diff --git a/dev/kernel/FirmwareKit/CoreBoot/BootNet.h b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h index c42c98db..3ed11363 100644 --- a/dev/kernel/FirmwareKit/CoreBoot/BootNet.h +++ b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h @@ -18,11 +18,11 @@ /// sent (if m_preflight = 0) /// @note Can be used to patch ROMs too (if ImpliesProgram = 1) typedef struct BOOTNET_INTERNET_HEADER { - Kernel::Char NB1; /// magic char 1 'O' - Kernel::Char NB2; /// magic char 2 'N' - Kernel::Char NB3; /// magic char 3 'E' - Kernel::Char NB4; /// magic char 4 'T' - Kernel::UInt16 Version; + Kernel::Char NB1; /// magic char 1 'O' + Kernel::Char NB2; /// magic char 2 'N' + Kernel::Char NB3; /// magic char 3 'E' + Kernel::Char NB4; /// magic char 4 'T' + Kernel::UInt16 Version; Kernel::Char Name[kBootNetNameLen]; /// example: Modjo Kernel::Int32 Length; /// the patch length. Kernel::Char Target[kBootNetNameLen]; /// the target file. diff --git a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc index 98e1ed61..be6d0af5 100644 --- a/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc +++ b/dev/kernel/HALKit/AMD64/HalCoreInterruptHandler.cc @@ -127,39 +127,39 @@ EXTERN_C void idt_handle_ud(Kernel::UIntPtr rsp) { process.Leak().Signal.Status = process.Leak().Status; } -/// @brief Enter syscall from assembly. +/// @brief Enter syscall from assembly (libSystem only) /// @param stack the stack pushed from assembly routine. /// @return nothing. -EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx_syscall_index, - Kernel::UIntPtr rdx_syscall_struct) { +EXTERN_C Kernel::Void hal_system_call_enter(Kernel::UIntPtr rcx_hash, + Kernel::UIntPtr rdx_syscall_arg) { hal_idt_send_eoi(50); if (!Kernel::kCurrentUser) return; - if (rcx_syscall_index < kSysCalls.Count()) { - if (kSysCalls[rcx_syscall_index].fHooked) { - if (kSysCalls[rcx_syscall_index].fProc) { - (kSysCalls[rcx_syscall_index].fProc)((Kernel::VoidPtr) rdx_syscall_struct); + for (SizeT i = 0UL; i < kMaxDispatchCallCount; ++i) { + if (kSysCalls[i].fHooked && rcx_hash == kSysCalls[i].fHash) { + if (kSysCalls[i].fProc) { + (kSysCalls[i].fProc)((Kernel::VoidPtr) rdx_syscall_arg); } } } } -/// @brief Enter Kernel call from assembly (DDK only). +/// @brief Enter Kernel call from assembly (libDDK only). /// @param stack the stack pushed from assembly routine. /// @return nothing. -EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_kerncall_index, - Kernel::UIntPtr rdx_kerncall_struct) { +EXTERN_C Kernel::Void hal_kernel_call_enter(Kernel::UIntPtr rcx_hash, + Kernel::UIntPtr rdx_kerncall_arg) { hal_idt_send_eoi(51); if (!Kernel::kRootUser) return; if (Kernel::kCurrentUser != Kernel::kRootUser) return; if (!Kernel::kCurrentUser->IsSuperUser()) return; - if (rcx_kerncall_index < kKernCalls.Count()) { - if (kKernCalls[rcx_kerncall_index].fHooked) { - if (kKernCalls[rcx_kerncall_index].fProc) { - (kKernCalls[rcx_kerncall_index].fProc)((Kernel::VoidPtr) rdx_kerncall_struct); + for (SizeT i = 0UL; i < kMaxDispatchCallCount; ++i) { + if (kKernCalls[i].fHooked && rcx_hash == kKernCalls[rcx_hash].fHash) { + if (kKernCalls[i].fProc) { + (kKernCalls[i].fProc)((Kernel::VoidPtr) rdx_kerncall_arg); } } } diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index bfd38f69..39f8c0a1 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -759,7 +759,10 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c if (drv_std_get_size() < kHeFSMinimumDiskSize) { (Void)(kout << "OpenHeFS recommends at least 128 GiB of free space." << kendl); - (Void)(kout << "The OS will still try to format a HeFS disk here anyway, don't expect perfect geometry." << kendl); + (Void)( + kout + << "The OS will still try to format a HeFS disk here anyway, don't expect perfect geometry." + << kendl); } HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) RTL_ALLOCA(sizeof(HEFS_BOOT_NODE)); diff --git a/dev/libSystem/SystemKit/System.h b/dev/libSystem/SystemKit/System.h index 91899efe..421868ae 100644 --- a/dev/libSystem/SystemKit/System.h +++ b/dev/libSystem/SystemKit/System.h @@ -309,16 +309,20 @@ IMPORT_C SInt32 PwrSendCode(_Output SInt32& code); // CD-ROM API. // ------------------------------------------------------------------------------------------ // -IMPORT_C SInt32 CdEjectDrive(_Input Char drv_letter); +#define kCDDevicePath "/devices/dvd{}" -IMPORT_C SInt32 CdOpenTray(Void); +IMPORT_C IORef CdOpenTray(Void); + +IMPORT_C SInt32 CdEjectDrive(_Input IORef cdrom); IMPORT_C SInt32 CdCloseTray(Void); // ------------------------------------------------------------------------------------------ // -// Printer API. +// TTY API. // ------------------------------------------------------------------------------------------ // +#define kPrintDevicePath "/devices/tty{}" + IMPORT_C SInt32 PrintOut(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); IMPORT_C SInt32 PrintIn(IORef file /* nullptr to direct to stdout */, const Char* fmt, ...); -- cgit v1.2.3 From 74d03a91ea9fa5f7351315b2f94910cc79ecdd9f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 14 Jun 2025 21:49:56 +0200 Subject: fix: Fix CB header regarding NeKernel.org's `/fw` repo. why? - In order to prevent future issues. next: - More ARM64 commits are coming. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/HEL/ARM64/BootCB.S | 4 ++-- dev/boot/src/HEL/POWER/BootCB.S | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'dev/boot/src/HEL') diff --git a/dev/boot/src/HEL/ARM64/BootCB.S b/dev/boot/src/HEL/ARM64/BootCB.S index 0c12c6c7..3b0e1737 100644 --- a/dev/boot/src/HEL/ARM64/BootCB.S +++ b/dev/boot/src/HEL/ARM64/BootCB.S @@ -15,9 +15,9 @@ boot_hdr_mag: .ascii "CB" boot_hdr_name: // it has to match ten bytes. - .asciz "bootz\0\0" + .asciz "bootz\0\0\0" boot_hdr_ver: - .word 0x104 + .word 0x101 boot_hdr_proc: .long bootloader_start diff --git a/dev/boot/src/HEL/POWER/BootCB.S b/dev/boot/src/HEL/POWER/BootCB.S index dae28871..3887ff10 100644 --- a/dev/boot/src/HEL/POWER/BootCB.S +++ b/dev/boot/src/HEL/POWER/BootCB.S @@ -15,7 +15,7 @@ boot_hdr_name: // it has to match ten bytes. .asciz "bootz\0\0\0" boot_hdr_ver: - .word 0x104 + .word 0x101 boot_hdr_proc: .long bootloader_start -- cgit v1.2.3