summaryrefslogtreecommitdiffhomepage
path: root/dev/boot/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-04-16 18:15:13 +0200
committerGitHub <noreply@github.com>2025-04-16 18:15:13 +0200
commit0033ef41f33ce3d39b4e7ed7e1353cec916bdd5d (patch)
treecf298a3b522fed5b829c4b250932ab13ef407838 /dev/boot/src
parentd3cf45311cf3f6de0bc25bb0ddb5c14a29a72cd6 (diff)
parent58b3d776ab5435de352217b2a3a525aeb9316e99 (diff)
Merge pull request #19 from amlel-el-mahrouss/dev
urgent patches.
Diffstat (limited to 'dev/boot/src')
-rw-r--r--dev/boot/src/BootThread.cc28
-rw-r--r--dev/boot/src/HEL/AMD64/BootAPI.S9
-rw-r--r--dev/boot/src/HEL/AMD64/BootEFI.cc103
-rw-r--r--dev/boot/src/HEL/ARM64/BootEFI.cc79
4 files changed, 103 insertions, 116 deletions
diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc
index ce691f96..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<HEL::HandoverProc>(fStartAddress)(fHandover);
}
- return kEfiOk;
+ return kEfiFail;
}
const Char* BootThread::GetName()
@@ -216,4 +194,4 @@ namespace Boot
{
return fStartAddress != nullptr;
}
-} // namespace Boot
+} // namespace Boot \ No newline at end of file
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 4220c6cb..fa0cb74b 100644
--- a/dev/boot/src/HEL/AMD64/BootEFI.cc
+++ b/dev/boot/src/HEL/AMD64/BootEFI.cc
@@ -73,27 +73,32 @@ 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 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 +128,6 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(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,12 +142,10 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
kHandoverHeader = handover_hdr;
- fb_init();
-
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;
@@ -161,14 +163,12 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(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. */
- //-------------------------------------------------------------//
- // Update handover file specific table and phyiscal start field.
- //-------------------------------------------------------------//
+ Int32 trials = 5 * 10000000;
- handover_hdr->f_BitMapSize = gib_cast(4); /* 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)
{
@@ -180,7 +180,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)
{
@@ -214,24 +214,12 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(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();
-
- Boot::Stop();
}
}
- // ------------------------------------------ //
- // null these fields, to avoid being reused later.
- // ------------------------------------------ //
-
- 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);
@@ -267,60 +255,45 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(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: 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");
+
+ // 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.
// ------------------------------------------ //
if (reader_kernel.Blob())
{
- kernel_thread = new Boot::BootThread(reader_kernel.Blob());
- kernel_thread->SetName("BootZ: Kernel");
+ // ------------------------------------------ //
+ // null these fields, to avoid being reused later.
+ // ------------------------------------------ //
+
+ auto kernel_thread = Boot::BootThread(reader_kernel.Blob());
+
+ kernel_thread.SetName("BootZ: Kernel");
handover_hdr->f_KernelImage = reader_kernel.Blob();
- }
- 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);
+ handover_hdr->f_KernelSz = reader_kernel.Size();
- Boot::Stop();
+ kernel_thread.Start(handover_hdr, YES);
}
Boot::BootFileReader reader_netboot(L"net.efi", image_handle);
reader_netboot.ReadAll(0);
- Boot::BootThread* netboot_thread = nullptr;
+ if (!reader_netboot.Blob())
+ return kEfiFail;
- // ---------------------------------------------------- //
- // 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())
- {
- netboot_thread = new Boot::BootThread(reader_netboot.Blob());
- netboot_thread->SetName("BootZ: BootNet");
- netboot_thread->Start(handover_hdr, YES);
- }
- }
+ auto netboot_thread = Boot::BootThread(reader_netboot.Blob());
+ netboot_thread.SetName("BootZ: BootNet");
- CANT_REACH();
+ return netboot_thread.Start(handover_hdr, NO);
}
diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc
index b6f28351..8008d846 100644
--- a/dev/boot/src/HEL/ARM64/BootEFI.cc
+++ b/dev/boot/src/HEL/ARM64/BootEFI.cc
@@ -18,17 +18,12 @@
#include <BootKit/BootThread.h>
#include <modules/CoreGfx/CoreGfx.h>
-// Makes the compiler shut up.
-#ifndef kMachineModel
-#define kMachineModel "NeKernel"
-#endif // !kMachineModel
-
#ifndef kExpectedWidth
-#define kExpectedWidth (1920)
+#define kExpectedWidth (800)
#endif
#ifndef kExpectedHeight
-#define kExpectedHeight (1080)
+#define kExpectedHeight (600)
#endif
/** Graphics related. */
@@ -74,23 +69,19 @@ 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();
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())
@@ -133,9 +124,9 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
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();
@@ -160,18 +151,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 +226,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 +237,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);