summaryrefslogtreecommitdiffhomepage
path: root/dev/boot/src/HEL
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-06-15 16:03:38 +0200
committerGitHub <noreply@github.com>2025-06-15 16:03:38 +0200
commiteb9df5eea339812513c25a8d3b2eeb03c633e7ac (patch)
treeefcdaaa25d08daadcd27e0597a0fb20defc49a23 /dev/boot/src/HEL
parent6511afbf405c31513bc88ab06bca58218610a994 (diff)
parentf7e5542dc13519cc78c204b4062acb0b71296a58 (diff)
Merge pull request #41 from nekernel-org/dev
NeKernel v0.0.3e1
Diffstat (limited to 'dev/boot/src/HEL')
-rw-r--r--dev/boot/src/HEL/AMD64/BootATA.cc13
-rw-r--r--dev/boot/src/HEL/AMD64/BootEFI.cc20
-rw-r--r--dev/boot/src/HEL/ARM64/BootAPI.S6
-rw-r--r--dev/boot/src/HEL/ARM64/BootCB.S4
-rw-r--r--dev/boot/src/HEL/ARM64/BootEFI.cc110
-rw-r--r--dev/boot/src/HEL/POWER/BootCB.S2
6 files changed, 60 insertions, 95 deletions
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