summaryrefslogtreecommitdiffhomepage
path: root/dev/Boot/src
diff options
context:
space:
mode:
Diffstat (limited to 'dev/Boot/src')
-rw-r--r--dev/Boot/src/BootFileReader.cc31
-rw-r--r--dev/Boot/src/BootThread.cc2
-rw-r--r--dev/Boot/src/HEL/AMD64/EFIBootStartup.cc17
-rw-r--r--dev/Boot/src/HEL/ARM64/CoreBootStartup.S6
-rw-r--r--dev/Boot/src/HEL/ARM64/EFIBootStartup.cc190
-rw-r--r--dev/Boot/src/Root/EFI/STARTUP.NSH2
6 files changed, 201 insertions, 47 deletions
diff --git a/dev/Boot/src/BootFileReader.cc b/dev/Boot/src/BootFileReader.cc
index eb5f80a2..e8f8772c 100644
--- a/dev/Boot/src/BootFileReader.cc
+++ b/dev/Boot/src/BootFileReader.cc
@@ -128,23 +128,26 @@ Boot::BFileReader::~BFileReader()
*/
Void Boot::BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr out_address)
{
- if (mBlob == nullptr)
- {
- EfiFileInfo newPtrInfo{};
- UInt32 szInfo = 0U;
+ UInt32 szInfo = sizeof(EfiFileInfo);
- EfiGUID kFileInfoGUID = EFI_FILE_INFO_GUID;
+ EfiFileInfo newPtrInfo{};
- if (mFile->GetInfo(mFile, &kFileInfoGUID, &szInfo, &newPtrInfo) == kEfiOk)
- {
- if (newPtrInfo.FileSize < readUntil)
- readUntil = newPtrInfo.FileSize;
- else if (readUntil < 1)
- readUntil = newPtrInfo.FileSize;
+ EfiGUID kFileInfoGUID = EFI_FILE_INFO_GUID;
- mWriter.Write(L"BootZ: File size: ").Write(readUntil).Write("\r");
- }
+ if (mFile->GetInfo(mFile, &kFileInfoGUID, &szInfo, &newPtrInfo) == kEfiOk)
+ {
+ readUntil = newPtrInfo.FileSize;
+ mWriter.Write(L"BootZ: File size: ").Write(readUntil).Write("\r");
+ }
+ if (readUntil == 0)
+ {
+ mErrorCode = kNotSupported;
+ return;
+ }
+
+ if (mBlob == nullptr)
+ {
if (!out_address)
{
if (auto err = BS->AllocatePool(EfiLoaderCode, readUntil, (VoidPtr*)&mBlob) !=
@@ -160,7 +163,7 @@ Void Boot::BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr out_
}
}
- mErrorCode = kNotSupported;
+ mWriter.Write(L"*** Bytes to read: ").Write(readUntil).Write(L" ***\r");
UInt64 bufSize = chunkToRead;
UInt64 szCnt = 0UL;
diff --git a/dev/Boot/src/BootThread.cc b/dev/Boot/src/BootThread.cc
index 61f3e805..15773b9b 100644
--- a/dev/Boot/src/BootThread.cc
+++ b/dev/Boot/src/BootThread.cc
@@ -55,7 +55,7 @@ namespace Boot
return;
}
#elif defined(__ZKA_ARM64__)
- if (header_ptr->mMachine != kPeMachineAMD64 ||
+ if (header_ptr->mMachine != kPeMachineARM64 ||
header_ptr->mSignature != kPeSignature)
{
writer.Write("BootZ: Not a PE32+ executable.\r");
diff --git a/dev/Boot/src/HEL/AMD64/EFIBootStartup.cc b/dev/Boot/src/HEL/AMD64/EFIBootStartup.cc
index ff705652..000e5b40 100644
--- a/dev/Boot/src/HEL/AMD64/EFIBootStartup.cc
+++ b/dev/Boot/src/HEL/AMD64/EFIBootStartup.cc
@@ -72,9 +72,6 @@ STATIC Bool boot_init_fb() noexcept
return No;
}
-EXTERN_C VoidPtr boot_read_cr3();
-EXTERN_C Void boot_write_cr3(VoidPtr new_cr3);
-
EXTERN EfiBootServices* BS;
/// @brief Main EFI entrypoint.
@@ -152,9 +149,15 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr image_handle,
UInt32 cnt_enabled = 0;
UInt32 cnt_disabled = 0;
- mp->GetNumberOfProcessors(mp, &cnt_disabled, &cnt_enabled);
-
- handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1;
+ if (mp)
+ {
+ mp->GetNumberOfProcessors(mp, &cnt_disabled, &cnt_enabled);
+ handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1;
+ }
+ else
+ {
+ handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = NO;
+ }
// Fill handover header now.
// ---------------------------------------------------- //
@@ -316,7 +319,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr image_handle,
// Finally load the OS kernel.
// ---------------------------------------------------- //
- kernel_thread->Start(handover_hdr, YES);
+ kernel_thread->Start(handover_hdr, NO);
CANT_REACH();
}
diff --git a/dev/Boot/src/HEL/ARM64/CoreBootStartup.S b/dev/Boot/src/HEL/ARM64/CoreBootStartup.S
index ee2dd3ec..000ade0f 100644
--- a/dev/Boot/src/HEL/ARM64/CoreBootStartup.S
+++ b/dev/Boot/src/HEL/ARM64/CoreBootStartup.S
@@ -4,6 +4,8 @@
------------------------------------------- */
+#ifdef __ZKA_COREBOOT__
+
.section .boot_hdr
.align 4
@@ -33,4 +35,6 @@ bootloader_start:
mov sp, x0
bl bootloader_main
- ret \ No newline at end of file
+ ret
+
+#endif // __ZKA_COREBOOT__ \ No newline at end of file
diff --git a/dev/Boot/src/HEL/ARM64/EFIBootStartup.cc b/dev/Boot/src/HEL/ARM64/EFIBootStartup.cc
index 279d1e40..bf940074 100644
--- a/dev/Boot/src/HEL/ARM64/EFIBootStartup.cc
+++ b/dev/Boot/src/HEL/ARM64/EFIBootStartup.cc
@@ -4,43 +4,56 @@
------------------------------------------- */
-#include <FirmwareKit/EFI/API.h>
+#include <BootKit/BootKit.h>
+#include <Mod/GfxMgr/FBMgr.h>
+#include <Mod/GfxMgr/TextMgr.h>
#include <FirmwareKit/EFI.h>
+#include <FirmwareKit/EFI/API.h>
+#include <FirmwareKit/Handover.h>
+#include <KernelKit/MSDOS.h>
+#include <KernelKit/PE.h>
+#include <KernelKit/PEF.h>
+#include <NewKit/Macros.h>
+#include <NewKit/Ref.h>
#include <BootKit/BootThread.h>
-#include <BootKit/BootKit.h>
+#include <Mod/GfxMgr/FBMgr.h>
+
+// Makes the compiler shut up.
+#ifndef kMachineModel
+#define kMachineModel "ZkaOS"
+#endif // !kMachineModel
#ifndef kExpectedWidth
-#define kExpectedWidth (1280)
+#define kExpectedWidth (1920)
#endif
#ifndef kExpectedHeight
-#define kExpectedHeight (720)
+#define kExpectedHeight (1080)
#endif
-EXTERN EfiBootServices* BS;
+/** Graphics related. */
STATIC EfiGraphicsOutputProtocol* kGop = nullptr;
STATIC UInt16 kGopStride = 0U;
STATIC EfiGUID kGopGuid;
-/// @brief Main EFI entrypoint.
-/// @param ImageHandle Handle of this image.
-/// @param SystemTable The system table of it.
-/// @return nothing, never returns.
-EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle,
- EfiSystemTable* SystemTable)
-{
- InitEFI(SystemTable);
+EXTERN_C Void rt_reset_hardware();
+
+EXTERN EfiBootServices* BS;
+/**
+ @brief Finds and stores the GOP object.
+*/
+STATIC Bool boot_init_fb() noexcept
+{
kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID);
kGop = nullptr;
- BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop);
+ if (BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop) != kEfiOk)
+ return No;
kGopStride = 4;
- Boot::BTextWriter writer;
-
for (SizeT i = 0; i < kGop->Mode->MaxMode; ++i)
{
EfiGraphicsOutputProtocolModeInformation* infoPtr = nullptr;
@@ -48,28 +61,159 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle,
kGop->QueryMode(kGop, i, &sz, &infoPtr);
- writer.Write(infoPtr->HorizontalResolution);
- writer.Write(infoPtr->VerticalResolution);
- writer.Write("\r");
-
if (infoPtr->HorizontalResolution == kExpectedWidth &&
infoPtr->VerticalResolution == kExpectedHeight)
{
kGop->SetMode(kGop, i);
+ return Yes;
+ }
+ }
+
+ return No;
+}
+
+EXTERN EfiBootServices* BS;
+
+/// @brief Main 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 Main(EfiHandlePtr image_handle,
+ EfiSystemTable* sys_table)
+{
+ InitEFI(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())
+ return 1; ///! Init the GOP.
+
+ for (SizeT index_vt = 0; index_vt < sys_table->NumberOfTableEntries;
+ ++index_vt)
+ {
+ Char* vendor_table = reinterpret_cast<Char*>(
+ sys_table->ConfigurationTable[index_vt].VendorTable);
+
+ // ACPI's 'RSD PTR', which contains the ACPI SDT (MADT, FACP...)
+ 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;
break;
}
}
- Boot::BFileReader reader_kernel(L"minoskrnl.exe", ImageHandle);
+ // ------------------------------------------ //
+ // 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;
+#endif // ZBA_USE_FB
+
+ // ------------------------------------------- //
+ // Grab MP services, extended to runtime. //
+ // ------------------------------------------- //
+
+ EfiGUID guid_mp = EfiGUID(EFI_MP_SERVICES_PROTOCOL_GUID);
+ EfiMpServicesProtocol* mp = nullptr;
+
+ BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast<VoidPtr*>(&mp));
+
+ handover_hdr->f_HardwareTables.f_MpPtr = reinterpret_cast<VoidPtr>(mp);
+
+ kHandoverHeader = handover_hdr;
+
+ fb_init();
+
+ UI::fb_clear_video();
+
+ FBDrawBitMapInRegion(zka_disk, ZKA_DISK_WIDTH, ZKA_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - ZKA_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - ZKA_DISK_HEIGHT) / 2);
+
+ fb_clear();
+
+ 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;
+ }
+ else
+ {
+ handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = NO;
+ }
+
+ //-------------------------------------------------------------//
+ // 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. */
+
+ while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk)
+ {
+ if (handover_hdr->f_BitMapStart)
+ {
+ BS->FreePool(handover_hdr->f_BitMapStart);
+ handover_hdr->f_BitMapStart = nullptr;
+ }
+ }
+
+ // ------------------------------------------ //
+ // null these fields, to avoid being reused later.
+ // ------------------------------------------ //
+
+ handover_hdr->f_FirmwareCustomTables[0] = nullptr;
+ handover_hdr->f_FirmwareCustomTables[1] = nullptr;
+
+ handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor);
+
+ handover_hdr->f_Magic = kHandoverMagic;
+ handover_hdr->f_Version = kHandoverVersion;
+
+ // Provide fimware vendor name.
+
+ Boot::BCopyMem(handover_hdr->f_FirmwareVendorName, sys_table->FirmwareVendor,
+ handover_hdr->f_FirmwareVendorLen);
+
+ handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor);
+
+ // Assign to global 'kHandoverHeader'.
+
+ Boot::BFileReader reader_kernel(L"minoskrnl.exe", image_handle);
reader_kernel.ReadAll(0);
+ // ------------------------------------------ //
+ // If we succeed in reading the blob, then execute it.
+ // ------------------------------------------ //
+
if (reader_kernel.Blob())
{
auto kernel_thread = Boot::BootThread(reader_kernel.Blob());
+ kernel_thread.SetName("BootZ: MicroKernel.");
- if (kernel_thread.IsValid())
- kernel_thread.Start(nullptr, YES);
+ handover_hdr->f_KernelImage = reader_kernel.Blob();
+
+ EFI::ExitBootServices(map_key, image_handle);
+
+ kernel_thread.Start(handover_hdr, NO);
}
CANT_REACH();
diff --git a/dev/Boot/src/Root/EFI/STARTUP.NSH b/dev/Boot/src/Root/EFI/STARTUP.NSH
index d29ba8fd..2cf25f23 100644
--- a/dev/Boot/src/Root/EFI/STARTUP.NSH
+++ b/dev/Boot/src/Root/EFI/STARTUP.NSH
@@ -1,2 +1,2 @@
fs0:
-BOOT\BOOTX64.EFI
+BOOT\BOOTAA64.EFI