diff options
Diffstat (limited to 'dev/boot/src')
| -rw-r--r-- | dev/boot/src/BootThread.cc | 25 | ||||
| -rw-r--r-- | dev/boot/src/HEL/AMD64/BootATA.cc | 13 | ||||
| -rw-r--r-- | dev/boot/src/HEL/AMD64/BootEFI.cc | 20 | ||||
| -rw-r--r-- | dev/boot/src/HEL/ARM64/BootAPI.S | 6 | ||||
| -rw-r--r-- | dev/boot/src/HEL/ARM64/BootCB.S | 4 | ||||
| -rw-r--r-- | dev/boot/src/HEL/ARM64/BootEFI.cc | 110 | ||||
| -rw-r--r-- | dev/boot/src/HEL/POWER/BootCB.S | 2 | ||||
| -rw-r--r-- | dev/boot/src/boot_rsrc.rsrc (renamed from dev/boot/src/BootloaderRsrc.rsrc) | 2 |
8 files changed, 74 insertions, 108 deletions
diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc index b502b52e..c477d659 100644 --- a/dev/boot/src/BootThread.cc +++ b/dev/boot/src/BootThread.cc @@ -15,6 +15,8 @@ #include <KernelKit/PEF.h> #include <modules/CoreGfx/TextGfx.h> +#define kBootThreadSz mib_cast(16) + /// @brief External boot services symbol. EXTERN EfiBootServices* BS; @@ -67,11 +69,10 @@ BootThread::BootThread(VoidPtr blob) : fStartAddress(nullptr), fBlob(blob) { writer.Write("BootZ: Magic: ").Write(header_ptr->Signature).Write("\r"); EfiPhysicalAddress loadStartAddress = opt_header_ptr->ImageBase; - loadStartAddress += opt_header_ptr->BaseOfData; - writer.Write("BootZ: Image base: ").Write(loadStartAddress).Write("\r"); + writer.Write("BootZ: Image-Base: ").Write(loadStartAddress).Write("\r"); - fStack = new UInt8[mib_cast(16)]; + fStack = new UInt8[kBootThreadSz]; if (!fStack) { writer.Write("BootZ: Unable to allocate stack.\r"); @@ -155,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"); @@ -172,13 +173,13 @@ Int32 BootThread::Start(HEL::BootInfoHeader* handover, Bool own_stack) { if (own_stack) { writer.Write("BootZ: Using it's own stack.\r"); - writer.Write("BootZ: Stack address: ").Write((UIntPtr) &fStack[mib_cast(16) - 1]).Write("\r"); - writer.Write("BootZ: Stack size: ").Write(mib_cast(16)).Write("\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[mib_cast(16) - 1]; - fHandover->f_StackSz = mib_cast(16); + fHandover->f_StackTop = &fStack[kBootThreadSz - 1]; + fHandover->f_StackSz = kBootThreadSz; - auto ret = rt_jump_to_address(fStartAddress, fHandover, &fStack[mib_cast(16) - 1]); + auto ret = rt_jump_to_address(fStartAddress, fHandover, &fStack[kBootThreadSz - 1]); // we don't need the stack anymore. @@ -187,7 +188,7 @@ Int32 BootThread::Start(HEL::BootInfoHeader* handover, Bool own_stack) { return ret; } else { - writer.Write("BootZ: Using Bootloader's stack.\r"); + writer.Write("BootZ: Using the bootloader's stack.\r"); return reinterpret_cast<HEL::HandoverProc>(fStartAddress)(fHandover); } 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); 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/BootAPI.S b/dev/boot/src/HEL/ARM64/BootAPI.S index a60ad218..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 x19, x0 - mov sp, x2 - blr x19 + mov sp, x1 + br x0 + ret 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/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc index 66f91352..467cae23 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,29 +109,16 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa EfiMpServicesProtocol* mp = nullptr; BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast<VoidPtr*>(&mp)); - handover_hdr->f_HardwareTables.f_MpPtr = reinterpret_cast<VoidPtr>(mp); - - // 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(); + kHandoverHeader->f_HardwareTables.f_MpPtr = reinterpret_cast<VoidPtr>(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; } //-------------------------------------------------------------// @@ -142,73 +127,52 @@ 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. */ - Int32 trials = 5 * 10000000; + kHandoverHeader->f_BitMapStart = nullptr; /* Start of bitmap. */ + kHandoverHeader->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */ + + 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 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; - 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(); } } } } - 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. // ------------------------------------------ // - 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); @@ -220,14 +184,12 @@ 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."); - - handover_hdr->f_KernelImage = reader_kernel.Blob(); - handover_hdr->f_KernelSz = reader_kernel.Size(); + kernel_thread.SetName("NeKernel"); - Boot::ExitBootServices(map_key, image_handle); + 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(); 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 diff --git a/dev/boot/src/BootloaderRsrc.rsrc b/dev/boot/src/boot_rsrc.rsrc index 33bce7f7..fedbdee0 100644 --- a/dev/boot/src/BootloaderRsrc.rsrc +++ b/dev/boot/src/boot_rsrc.rsrc @@ -12,7 +12,7 @@ BEGIN VALUE "FileDescription", "NeKernel OS Loader." VALUE "FileVersion", BOOTLOADER_VERSION VALUE "InternalName", "bootz" - VALUE "LegalCopyright", "Copyright (C) 2024, Amlal El Mahrouss all rights reserved." + VALUE "LegalCopyright", "Copyright (C) 2024-2025, Amlal El Mahrouss all rights reserved." VALUE "OriginalFilename", "ne_bootz" VALUE "ProductName", "bootz" VALUE "ProductVersion", BOOTLOADER_VERSION |
