summaryrefslogtreecommitdiffhomepage
path: root/dev/ZBAKit/src/HEL/AMD64
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2024-10-28 07:01:58 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2024-10-28 07:01:58 +0100
commite0024d9ea688ee91a77abc0e28c5ea24b13ca67d (patch)
treea4e29bd919cbeccf2689e81a5d52bfc02f2a8b77 /dev/ZBAKit/src/HEL/AMD64
parent36a3600ff7fc65a63b7386b7a680dbe8e647bd8f (diff)
IMP: Refactor whole source code to make it even.
- That is because previously the source was both in lowercase and lettercase. Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZBAKit/src/HEL/AMD64')
-rw-r--r--dev/ZBAKit/src/HEL/AMD64/.gitkeep0
-rw-r--r--dev/ZBAKit/src/HEL/AMD64/BootAHCI.cc20
-rw-r--r--dev/ZBAKit/src/HEL/AMD64/BootAPI.S52
-rw-r--r--dev/ZBAKit/src/HEL/AMD64/BootATA.cc278
-rw-r--r--dev/ZBAKit/src/HEL/AMD64/BootMain.cc322
-rw-r--r--dev/ZBAKit/src/HEL/AMD64/BootPlatform.cc106
6 files changed, 778 insertions, 0 deletions
diff --git a/dev/ZBAKit/src/HEL/AMD64/.gitkeep b/dev/ZBAKit/src/HEL/AMD64/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/ZBAKit/src/HEL/AMD64/.gitkeep
diff --git a/dev/ZBAKit/src/HEL/AMD64/BootAHCI.cc b/dev/ZBAKit/src/HEL/AMD64/BootAHCI.cc
new file mode 100644
index 00000000..60520ac9
--- /dev/null
+++ b/dev/ZBAKit/src/HEL/AMD64/BootAHCI.cc
@@ -0,0 +1,20 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+/**
+ * @file BootAHCI.cc
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief AHCI support for ZBA.
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright Copyright (c) ZKA Web Services Co
+ *
+ */
+
+#include <BootKit/Platform.h>
+#include <BootKit/Protocol.h>
+#include <BootKit/HW/SATA.h>
diff --git a/dev/ZBAKit/src/HEL/AMD64/BootAPI.S b/dev/ZBAKit/src/HEL/AMD64/BootAPI.S
new file mode 100644
index 00000000..47f250f1
--- /dev/null
+++ b/dev/ZBAKit/src/HEL/AMD64/BootAPI.S
@@ -0,0 +1,52 @@
+.global rt_jump_to_address
+.global rt_reset_hardware
+
+.text
+
+.intel_syntax noprefix
+
+/**
+ @brief this function setups a stack and then jumps to
+ a function */
+rt_jump_to_address:
+ mov rbx, rcx
+ mov rcx, rdx
+ jmp rbx
+
+ ret
+
+rt_reset_hardware:
+ /* dont raise any interrupts. (except ofc NMIs.) */
+ cli
+ /* remap PIC */
+wait_gate1:
+ in al,0x64
+ and al,2
+ jnz wait_gate1
+ mov al,0x0D1
+ out 0x64,al
+wait_gate2:
+ in al,0x64
+ and al,2
+ jnz wait_gate2
+ mov al,0x0FE
+ out 0x60,al
+
+ /* trigger triple fault, by writing to cr4 */
+
+ mov rax, 0
+ lidt [rax]
+
+reset_wait:
+ jmp reset_wait
+
+.global boot_write_cr3
+.global boot_read_cr3
+
+boot_read_cr3:
+ mov rax, rax
+ ret
+
+boot_write_cr3:
+ mov cr3, rcx
+ ret
diff --git a/dev/ZBAKit/src/HEL/AMD64/BootATA.cc b/dev/ZBAKit/src/HEL/AMD64/BootATA.cc
new file mode 100644
index 00000000..34f1df29
--- /dev/null
+++ b/dev/ZBAKit/src/HEL/AMD64/BootATA.cc
@@ -0,0 +1,278 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+/**
+ * @file BootATA.cc
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief ATA driver.
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright Copyright (c) ZKA Web Services Co
+ *
+ */
+
+#include <FirmwareKit/EFI.h>
+#include <BootKit/BootKit.h>
+#include <BootKit/HW/ATA.h>
+
+/// bugs: 0
+
+using namespace Boot;
+
+#define kATADataLen 256
+
+static Boolean kATADetected = false;
+static Int32 kATADeviceType = kATADeviceCount;
+static UInt16 kATAData[kATADataLen] = {0};
+
+Boolean boot_ata_detected(Void);
+
+STATIC Boolean boot_ata_wait_io(UInt16 IO)
+{
+ for (int i = 0; i < 400; i++)
+ In8(IO + ATA_REG_STATUS);
+
+ATAWaitForIO_Retry:
+ auto statRdy = In8(IO + ATA_REG_STATUS);
+
+ if ((statRdy & ATA_SR_BSY))
+ goto ATAWaitForIO_Retry;
+
+ATAWaitForIO_Retry2:
+ statRdy = In8(IO + ATA_REG_STATUS);
+
+ if (statRdy & ATA_SR_ERR)
+ return false;
+
+ if (!(statRdy & ATA_SR_DRDY))
+ goto ATAWaitForIO_Retry2;
+
+ return true;
+}
+
+Void boot_ata_select(UInt16 Bus)
+{
+ if (Bus == ATA_PRIMARY_IO)
+ Out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL);
+ else
+ Out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL);
+}
+
+Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster)
+{
+ if (boot_ata_detected())
+ return true;
+
+ BTextWriter writer;
+
+ UInt16 IO = Bus;
+
+ boot_ata_select(IO);
+
+ // Bus init, NEIN bit.
+ Out8(IO + ATA_REG_NEIN, 1);
+
+ // identify until it's good.
+ATAInit_Retry:
+ auto statRdy = In8(IO + ATA_REG_STATUS);
+
+ if (statRdy & ATA_SR_ERR)
+ {
+ writer.Write(
+ L"ZBA: ATA: error, not an IDE based hard-drive.\r");
+
+ return false;
+ }
+
+ if ((statRdy & ATA_SR_BSY))
+ goto ATAInit_Retry;
+
+ Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY);
+
+ /// fetch serial info
+ /// model, speed, number of sectors...
+
+ boot_ata_wait_io(IO);
+
+ for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData)
+ {
+ kATAData[indexData] = In16(IO + ATA_REG_DATA);
+ }
+
+ OutBus =
+ (Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary;
+
+ OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE;
+
+ return true;
+}
+
+Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size)
+{
+ Lba /= SectorSz;
+
+ UInt8 Command = ((!Master) ? 0xE0 : 0xF0);
+
+ boot_ata_wait_io(IO);
+ boot_ata_select(IO);
+
+ Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
+
+ Out8(IO + ATA_REG_SEC_COUNT0, ((Size + SectorSz) / SectorSz));
+
+ Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
+ Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
+ Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
+ Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
+
+ Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
+
+ boot_ata_wait_io(IO);
+
+ for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff)
+ {
+ boot_ata_wait_io(IO);
+ Buf[IndexOff] = In16(IO + ATA_REG_DATA);
+ boot_ata_wait_io(IO);
+ }
+}
+
+Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size)
+{
+ Lba /= SectorSz;
+
+ UInt8 Command = ((!Master) ? 0xE0 : 0xF0);
+
+ boot_ata_wait_io(IO);
+ boot_ata_select(IO);
+
+ Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F));
+
+ Out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz));
+
+ Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF);
+ Out8(IO + ATA_REG_LBA1, (Lba) >> 8);
+ Out8(IO + ATA_REG_LBA2, (Lba) >> 16);
+ Out8(IO + ATA_REG_LBA3, (Lba) >> 24);
+
+ Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO);
+
+ boot_ata_wait_io(IO);
+
+ for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff)
+ {
+ boot_ata_wait_io(IO);
+ Out16(IO + ATA_REG_DATA, Buf[IndexOff]);
+ boot_ata_wait_io(IO);
+ }
+}
+
+/// @check is ATA detected?
+Boolean boot_ata_detected(Void)
+{
+ return kATADetected;
+}
+
+/***
+ *
+ *
+ * @brief ATA Device class.
+ *
+ *
+ */
+
+/**
+ * @brief ATA Device constructor.
+ * @param void none.
+ */
+BootDeviceATA::BootDeviceATA() noexcept
+{
+ if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus,
+ this->Leak().mMaster) ||
+ boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus,
+ this->Leak().mMaster))
+ {
+ kATADetected = true;
+ }
+}
+/**
+ * @brief Is ATA detected?
+ */
+BootDeviceATA::operator bool()
+{
+ return boot_ata_detected();
+}
+
+/**
+ @brief Read Buf from disk
+ @param Sz Sector size
+ @param Buf buffer
+*/
+BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz)
+{
+ if (!boot_ata_detected())
+ {
+ Leak().mErr = true;
+ return *this;
+ }
+
+ this->Leak().mErr = false;
+
+ if (!Buf || SectorSz < 1)
+ return *this;
+
+ boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster,
+ Buf, SectorSz, this->Leak().mSize);
+
+ return *this;
+}
+
+/**
+ @brief Write Buf into disk
+ @param Sz Sector size
+ @param Buf buffer
+*/
+BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorSz)
+{
+ if (!boot_ata_detected())
+ {
+ Leak().mErr = true;
+ return *this;
+ }
+
+ Leak().mErr = false;
+
+ if (!Buf || SectorSz < 1)
+ return *this;
+
+ boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster,
+ Buf, SectorSz, this->Leak().mSize);
+
+ return *this;
+}
+
+/**
+ * @brief ATA trait getter.
+ * @return BootDeviceATA::ATATrait& the drive config.
+ */
+BootDeviceATA::ATATrait& BootDeviceATA::Leak()
+{
+ return mTrait;
+}
+
+/***
+ @brief Getter, gets the number of sectors inside the drive.
+*/
+SizeT BootDeviceATA::GetSectorsCount() noexcept
+{
+ return (kATAData[61] << 16) | kATAData[60];
+}
+
+SizeT BootDeviceATA::GetDiskSize() noexcept
+{
+ return this->GetSectorsCount() * BootDeviceATA::kSectorSize;
+}
diff --git a/dev/ZBAKit/src/HEL/AMD64/BootMain.cc b/dev/ZBAKit/src/HEL/AMD64/BootMain.cc
new file mode 100644
index 00000000..b802bdfb
--- /dev/null
+++ b/dev/ZBAKit/src/HEL/AMD64/BootMain.cc
@@ -0,0 +1,322 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#include <BootKit/BootKit.h>
+#include <Modules/FB/FB.h>
+#include <Modules/FB/Text.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/Thread.h>
+
+// Makes the compiler shut up.
+#ifndef kMachineModel
+#define kMachineModel "ZKA SSD"
+#endif // !kMachineModel
+
+#ifndef kExpectedWidth
+#define kExpectedWidth 1280
+#endif
+
+#ifndef kExpectedHeight
+#define kExpectedHeight 720
+#endif
+
+/** Graphics related. */
+
+STATIC EfiGraphicsOutputProtocol* kGop = nullptr;
+STATIC UInt16 kGopStride = 0U;
+STATIC EfiGUID kGopGuid;
+
+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;
+
+ if (BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop) != kEfiOk)
+ return No;
+
+ kGopStride = 4;
+
+ for (SizeT i = 0; i < kGop->Mode->MaxMode; ++i)
+ {
+ EfiGraphicsOutputProtocolModeInformation* infoPtr = nullptr;
+ UInt32 sz = 0U;
+
+ kGop->QueryMode(kGop, i, &sz, &infoPtr);
+
+ if (infoPtr->HorizontalResolution == kExpectedWidth &&
+ infoPtr->VerticalResolution == kExpectedHeight)
+ {
+ kGop->SetMode(kGop, i);
+ return Yes;
+ }
+ }
+
+ return No;
+}
+
+EXTERN_C VoidPtr boot_read_cr3();
+EXTERN_C Void boot_write_cr3(VoidPtr new_cr3);
+
+EXTERN EfiBootServices* BS;
+
+/// @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); ///! Init the EFI library.
+
+ HEL::HANDOVER_INFO_HEADER* handover_hdr =
+ new HEL::HANDOVER_INFO_HEADER();
+
+ UInt32 map_key = 0;
+ UInt32 size_struct_ptr = sizeof(EfiMemoryDescriptor);
+ EfiMemoryDescriptor* struct_ptr = nullptr;
+ UInt32 sz_desc = sizeof(EfiMemoryDescriptor);
+ UInt32 rev_desc = 0;
+
+#ifdef __ZKA_USE_FB__
+ if (!boot_init_fb())
+ return -1; ///! Init the GOP.
+
+ for (SizeT index_vt = 0; index_vt < SystemTable->NumberOfTableEntries;
+ ++index_vt)
+ {
+ Char* vendor_table = reinterpret_cast<Char*>(
+ SystemTable->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;
+ }
+ }
+
+ // ------------------------------------------ //
+ // 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 // __ZKA_USE_FB__
+
+ // ------------------------------------------- //
+ // Grab MP services, extended to runtime. //
+ // ------------------------------------------- //
+
+ auto 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;
+
+#ifdef __ZKA_USE_FB__
+ CGInit();
+ CGDrawInRegion(CGColor(0xFF, 0x3A, 0x3A), handover_hdr->f_GOP.f_Height, handover_hdr->f_GOP.f_Width, 0, 0);
+ CGFini();
+#endif // __ZKA_USE_FB__
+
+ UInt32 cnt_enabled = 0;
+ UInt32 cnt_disabled = 0;
+
+ mp->GetNumberOfProcessors(mp, &cnt_disabled, &cnt_enabled);
+
+#ifdef __ZKA_USE_FB__
+ CGDrawString("ZBA (C) ZKA WEB SERVICES.", 10, 10, RGB(0xFF, 0xFF, 0xFF));
+ CGDrawString((cnt_enabled > 1) ? "MULTIPLE PROCESSORS DETECTED." : "SINGLE PROCESSOR DETECTED.", 20, 10, RGB(0xFF, 0xFF, 0xFF));
+#endif // __ZKA_USE_FB__
+
+ handover_hdr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1;
+ // Fill handover header now.
+
+ Boot::BDiskFormatFactory<BootDeviceATA> partition_factory;
+
+ // ---------------------------------------------------- //
+ // The following checks for an exisiting partition
+ // inside the disk, if it doesn't have one,
+ // format the disk.
+ // ---------------------------------------------------- //
+
+#ifdef __ZKA_AUTO_FORMAT__
+ if (!partition_factory.IsPartitionValid())
+ {
+ Boot::BDiskFormatFactory<BootDeviceATA>::BFileDescriptor root;
+ root.fFileName[0] = kNeFSRoot[0];
+ root.fFileName[1] = 0;
+
+ root.fKind = kNeFSCatalogKindDir;
+
+ partition_factory.Format("FileSystem (A:)", &root, 1);
+
+ rt_reset_hardware();
+ }
+#endif // __ZKA_AUTO_FORMAT__
+
+ BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc);
+
+ struct_ptr = new EfiMemoryDescriptor[sz_desc];
+
+ BS->GetMemoryMap(&size_struct_ptr, struct_ptr, &map_key, &sz_desc, &rev_desc);
+
+ auto cDefaultMemoryMap = 0; // Grab any usable entries.
+
+ //-----------------------------------------------------------//
+ // A simple loop which finds a usable memory region for us.
+ //-----------------------------------------------------------//
+
+ SizeT lookup_index = 0UL;
+
+ for (; struct_ptr[lookup_index].Kind != EfiMemoryType::EfiConventionalMemory; ++lookup_index)
+ {
+ ZKA_UNUSED(0);
+ }
+
+ cDefaultMemoryMap = lookup_index;
+
+ //-----------------------------------------------------------//
+ // 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;
+ }
+ }
+
+ handover_hdr->f_FirmwareCustomTables[0] = (VoidPtr)BS;
+ handover_hdr->f_FirmwareCustomTables[1] = (VoidPtr)ST;
+
+ Boot::BFileReader reader_syschk(L"syschk.sys", ImageHandle);
+ reader_syschk.ReadAll(0);
+
+ Boot::BThread* syschk_thread = nullptr;
+
+ // ------------------------------------------ //
+ // If we succeed in reading the blob, then execute it.
+ // ------------------------------------------ //
+
+ if (reader_syschk.Blob())
+ {
+ syschk_thread = new Boot::BThread(reader_syschk.Blob());
+ syschk_thread->SetName("System Check (Integrity check)");
+ }
+
+ syschk_thread->Start(handover_hdr);
+
+ // nullify 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(SystemTable->FirmwareVendor);
+
+ handover_hdr->f_Magic = kHandoverMagic;
+ handover_hdr->f_Version = kHandoverVersion;
+
+ // Provide fimware vendor name.
+
+ Boot::BCopyMem(handover_hdr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
+ handover_hdr->f_FirmwareVendorLen);
+
+ handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(SystemTable->FirmwareVendor);
+
+ // Assign to global 'kHandoverHeader'.
+
+ Boot::BFileReader reader_kernel(L"minoskrnl.exe", ImageHandle);
+
+ reader_kernel.ReadAll(0);
+
+ Boot::BThread* kernel_thread = nullptr;
+
+ // ------------------------------------------ //
+ // If we succeed in reading the blob, then execute it.
+ // ------------------------------------------ //
+
+ if (reader_kernel.Blob())
+ {
+ kernel_thread = new Boot::BThread(reader_kernel.Blob());
+ kernel_thread->SetName("OS Kernel (Microkernel).");
+
+ handover_hdr->f_KernelImage = reader_kernel.Blob();
+ }
+ else
+ {
+#ifdef __ZKA_USE_FB__
+ CGDrawString("ZBA: PLEASE RECOVER YOUR KERNEL IMAGE.", 30, 10, RGB(0xFF, 0xFF, 0xFF));
+#endif // __ZKA_USE_FB__
+ }
+
+ Boot::BFileReader chime_wav(L"zka\\startup.wav", ImageHandle);
+ Boot::BFileReader ttf_font(L"zka\\urbanist.ttf", ImageHandle);
+
+ chime_wav.ReadAll(0);
+ ttf_font.ReadAll(0);
+
+ if (chime_wav.Blob() &&
+ ttf_font.Blob())
+ {
+ handover_hdr->f_StartupChime = chime_wav.Blob();
+ handover_hdr->f_ChimeSz = chime_wav.Size();
+ handover_hdr->f_KernelImage = reader_kernel.Blob();
+ handover_hdr->f_KernelSz = reader_kernel.Size();
+ handover_hdr->f_TTFallbackFont = ttf_font.Blob();
+ handover_hdr->f_FontSz = ttf_font.Size();
+ }
+ else
+ {
+#ifdef __ZKA_USE_FB__
+ CGDrawString("ZBA: ONE OR MORE SYSTEM COMPONENTS ARE MISSING, PLEASE REINSTALL THE OS.", 30, 10, RGB(0xFF, 0xFF, 0xFF));
+#endif // __ZKA_USE_FB__
+ }
+
+ EFI::ExitBootServices(map_key, ImageHandle);
+
+#ifdef __ZKA_USE_FB__
+ CGDrawInRegion(CGColor(0xFF, 0x3A, 0x3A), handover_hdr->f_GOP.f_Height, handover_hdr->f_GOP.f_Width, 0, 0);
+ CGFini();
+#endif // __ZKA_USE_FB__
+
+ // ---------------------------------------------------- //
+ // Finally load the operating system kernel.
+ // ---------------------------------------------------- //
+
+ kernel_thread->Start(handover_hdr);
+
+ CANT_REACH();
+}
diff --git a/dev/ZBAKit/src/HEL/AMD64/BootPlatform.cc b/dev/ZBAKit/src/HEL/AMD64/BootPlatform.cc
new file mode 100644
index 00000000..70b95734
--- /dev/null
+++ b/dev/ZBAKit/src/HEL/AMD64/BootPlatform.cc
@@ -0,0 +1,106 @@
+
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#include <BootKit/Platform.h>
+#include <BootKit/Protocol.h>
+#include <BootKit/BootKit.h>
+
+#ifdef __STANDALONE__
+
+using namespace Boot;
+
+EXTERN_C void rt_hlt()
+{
+ asm volatile("hlt");
+}
+
+EXTERN_C void rt_cli()
+{
+ asm volatile("cli");
+}
+
+EXTERN_C void rt_sti()
+{
+ asm volatile("sti");
+}
+
+EXTERN_C void rt_cld()
+{
+ asm volatile("cld");
+}
+
+EXTERN_C void rt_std()
+{
+ asm volatile("std");
+}
+
+EXTERN_C void Out8(UInt16 port, UInt8 value)
+{
+ asm volatile("outb %%al, %1"
+ :
+ : "a"(value), "Nd"(port)
+ : "memory");
+}
+
+EXTERN_C void Out16(UInt16 port, UInt16 value)
+{
+ asm volatile("outw %%ax, %1"
+ :
+ : "a"(value), "Nd"(port)
+ : "memory");
+}
+
+EXTERN_C void Out32(UInt16 port, UInt32 value)
+{
+ asm volatile("outl %%eax, %1"
+ :
+ : "a"(value), "Nd"(port)
+ : "memory");
+}
+
+EXTERN_C UInt8 In8(UInt16 port)
+{
+ UInt8 value;
+ asm volatile("inb %1, %%al"
+ : "=a"(value)
+ : "Nd"(port)
+ : "memory");
+
+ return value;
+}
+
+EXTERN_C UInt16 In16(UInt16 port)
+{
+ UInt16 value;
+ asm volatile("inw %%dx, %%ax"
+ : "=a"(value)
+ : "d"(port));
+
+ return value;
+}
+
+EXTERN_C UInt32 In32(UInt16 port)
+{
+ UInt32 value;
+ asm volatile("inl %1, %%eax"
+ : "=a"(value)
+ : "Nd"(port)
+ : "memory");
+
+ return value;
+}
+
+#else
+
+#include <HALKit/AMD64/Processor.h>
+
+void rt_hlt()
+{
+ Kernel::HAL::rt_halt();
+}
+
+#endif // __STANDALONE__