summaryrefslogtreecommitdiffhomepage
path: root/dev/Boot/Sources
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
commitf3d931aa7cfaf96baef8383b59a8938779541ee7 (patch)
treefdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Boot/Sources
parent86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff)
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Boot/Sources')
-rw-r--r--dev/Boot/Sources/.gitkeep0
-rw-r--r--dev/Boot/Sources/BootloaderRsrc.rsrc25
-rw-r--r--dev/Boot/Sources/HEL/64X000/.gitkeep0
-rw-r--r--dev/Boot/Sources/HEL/64X000/Boot64x0.S35
-rw-r--r--dev/Boot/Sources/HEL/AMD64/.gitkeep0
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootAHCI.cxx20
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootATA.cxx276
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootFileReader.cxx200
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootJump.S21
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootMain.cxx259
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootPlatform.cxx103
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootString.cxx92
-rw-r--r--dev/Boot/Sources/HEL/AMD64/BootTextWriter.cxx170
-rw-r--r--dev/Boot/Sources/HEL/AMD64/New+Delete.cxx62
-rw-r--r--dev/Boot/Sources/HEL/AMD64/Support.cxx82
-rw-r--r--dev/Boot/Sources/HEL/AMD64/compile_flags.txt7
-rw-r--r--dev/Boot/Sources/HEL/ARM64/.gitkeep0
-rw-r--r--dev/Boot/Sources/HEL/POWER/.gitkeep0
-rw-r--r--dev/Boot/Sources/HEL/POWER/CoreBootStartup.S34
-rw-r--r--dev/Boot/Sources/Root/EFI/STARTUP.NSH2
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-Black.ttfbin0 -> 42784 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-BlackItalic.ttfbin0 -> 44084 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-Bold.ttfbin0 -> 42636 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-BoldItalic.ttfbin0 -> 43900 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBold.ttfbin0 -> 42908 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBoldItalic.ttfbin0 -> 44208 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLight.ttfbin0 -> 42792 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLightItalic.ttfbin0 -> 44104 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-Italic.ttfbin0 -> 43996 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-Light.ttfbin0 -> 42764 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-LightItalic.ttfbin0 -> 44052 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-Medium.ttfbin0 -> 42752 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-MediumItalic.ttfbin0 -> 44080 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-Regular.ttfbin0 -> 42704 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-SemiBold.ttfbin0 -> 42740 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-SemiBoldItalic.ttfbin0 -> 44088 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-Thin.ttfbin0 -> 42580 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/Urbanist-ThinItalic.ttfbin0 -> 43868 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/boot-scr.bmpbin0 -> 11059254 bytes
-rw-r--r--dev/Boot/Sources/Root/ZKA/fonts.json4
-rw-r--r--dev/Boot/Sources/Thread.cxx179
-rw-r--r--dev/Boot/Sources/compile_flags.txt8
42 files changed, 1579 insertions, 0 deletions
diff --git a/dev/Boot/Sources/.gitkeep b/dev/Boot/Sources/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/Boot/Sources/.gitkeep
diff --git a/dev/Boot/Sources/BootloaderRsrc.rsrc b/dev/Boot/Sources/BootloaderRsrc.rsrc
new file mode 100644
index 00000000..6aa1d5a5
--- /dev/null
+++ b/dev/Boot/Sources/BootloaderRsrc.rsrc
@@ -0,0 +1,25 @@
+#include "../../Kernel/CompilerKit/Version.hxx"
+
+1 VERSIONINFO
+FILEVERSION 1,0,0,0
+PRODUCTVERSION 1,0,0,0
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "080904E4"
+ BEGIN
+ VALUE "CompanyName", "ZKA Technologies"
+ VALUE "FileDescription", "New OS Loader."
+ VALUE "FileVersion", BOOTLOADER_VERSION
+ VALUE "InternalName", "newosldr"
+ VALUE "LegalCopyright", "Copyright ZKA Technologies., all rights reserved."
+ VALUE "OriginalFilename", "newosldr.exe"
+ VALUE "ProductName", "newosldr"
+ VALUE "ProductVersion", BOOTLOADER_VERSION
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x809, 1252
+ END
+END
diff --git a/dev/Boot/Sources/HEL/64X000/.gitkeep b/dev/Boot/Sources/HEL/64X000/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/Boot/Sources/HEL/64X000/.gitkeep
diff --git a/dev/Boot/Sources/HEL/64X000/Boot64x0.S b/dev/Boot/Sources/HEL/64X000/Boot64x0.S
new file mode 100644
index 00000000..271a3f28
--- /dev/null
+++ b/dev/Boot/Sources/HEL/64X000/Boot64x0.S
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+.section .boot_hdr
+.align 4
+
+/* NewBoot boot header begin for a 64x000 kernel. */
+
+boot_hdr_mag:
+ .ascii "CB"
+boot_hdr_name:
+ // it has to match ten bytes.
+ .asciz "newosldr\0\0"
+boot_hdr_ver:
+ .word 0x104
+boot_hdr_proc:
+ .long bootloader_start
+
+/* NewBoot boot header end */
+
+.extern bootloader_main
+.extern bootloader_stack
+
+.globl bootloader_start
+bootloader_start:
+ psh 4 /* real address of .Laddr */
+ ldi 0,(bootloader_stack-bootloader_start)(4) /* stack address location */
+ mv 19,0 /* use user defined stack */
+ jrl
+
+ bl bootloader_main
+ blr
diff --git a/dev/Boot/Sources/HEL/AMD64/.gitkeep b/dev/Boot/Sources/HEL/AMD64/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/.gitkeep
diff --git a/dev/Boot/Sources/HEL/AMD64/BootAHCI.cxx b/dev/Boot/Sources/HEL/AMD64/BootAHCI.cxx
new file mode 100644
index 00000000..776f3f88
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootAHCI.cxx
@@ -0,0 +1,20 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/**
+ * @file AHCI.cxx
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief AHCI driver.
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright Copyright (c) ZKA Technologies
+ *
+ */
+
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
+#include <BootKit/HW/SATA.hxx>
diff --git a/dev/Boot/Sources/HEL/AMD64/BootATA.cxx b/dev/Boot/Sources/HEL/AMD64/BootATA.cxx
new file mode 100644
index 00000000..4beed241
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootATA.cxx
@@ -0,0 +1,276 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+/**
+ * @file ATA.cxx
+ * @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
+ * @brief ATA driver.
+ * @version 0.1
+ * @date 2024-02-02
+ *
+ * @copyright Copyright (c) ZKA Technologies
+ *
+ */
+
+#include <FirmwareKit/EFI.hxx>
+#include <BootKit/BootKit.hxx>
+#include <BootKit/HW/ATA.hxx>
+
+/// bugs: 0
+
+#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 < 4; 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"newosldr: ATA: Select 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)
+{
+ 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, 2);
+
+ Out8(IO + ATA_REG_LBA0, (Lba));
+ 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)
+{
+ 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, 2);
+
+ Out8(IO + ATA_REG_LBA0, (Lba));
+ 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;
+
+ auto lba = this->Leak().mBase / SectorSz;
+
+ boot_ata_read(lba, 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;
+
+ auto lba = this->Leak().mBase / SectorSz;
+
+ boot_ata_write(lba, 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/Boot/Sources/HEL/AMD64/BootFileReader.cxx b/dev/Boot/Sources/HEL/AMD64/BootFileReader.cxx
new file mode 100644
index 00000000..e94c690a
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootFileReader.cxx
@@ -0,0 +1,200 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: FileReader.cxx
+ Purpose: New Boot FileReader,
+ Read complete file and store it in a buffer.
+
+------------------------------------------- */
+
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
+#include <BootKit/BootKit.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <FirmwareKit/EFI/API.hxx>
+
+/// @file BootFileReader
+/// @brief Bootloader File reader.
+/// BUGS: 0
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+///
+///
+/// @name BFileReader class
+/// @brief Reads the file as a blob.
+///
+///
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/***
+ @brief File Reader constructor.
+*/
+BFileReader::BFileReader(const CharacterTypeUTF16* path,
+ EfiHandlePtr ImageHandle)
+{
+ if (path != nullptr)
+ {
+ SizeT index = 0UL;
+ for (; path[index] != L'\0'; ++index)
+ {
+ mPath[index] = path[index];
+ }
+
+ mPath[index] = 0;
+ }
+
+ /// Load protocols with their GUIDs.
+
+ EfiGUID guidEfp = EfiGUID(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID);
+
+ EfiSimpleFilesystemProtocol* efp = nullptr;
+
+ EfiLoadImageProtocol* img = nullptr;
+ EfiGUID guidImg = EfiGUID(EFI_LOADED_IMAGE_PROTOCOL_GUID);
+
+ if (BS->HandleProtocol(ImageHandle, &guidImg, (void**)&img) != kEfiOk)
+ {
+ mWriter.Write(L"newosldr: Handle-Protocol: No-Such-Protocol").Write(L"\r");
+ this->mErrorCode = kNotSupported;
+ }
+
+ if (BS->HandleProtocol(img->DeviceHandle, &guidEfp, (void**)&efp) != kEfiOk)
+ {
+ mWriter.Write(L"newosldr: Handle-Protocol: No-Such-Protocol").Write(L"\r");
+ this->mErrorCode = kNotSupported;
+ return;
+ }
+
+ /// Start doing disk I/O
+
+ if (efp->OpenVolume(efp, &mRootFs) != kEfiOk)
+ {
+ mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Volume").Write(L"\r");
+ this->mErrorCode = kNotSupported;
+ return;
+ }
+
+ EfiFileProtocol* kernelFile = nullptr;
+
+ if (mRootFs->Open(mRootFs, &kernelFile, mPath, kEFIFileRead, kEFIReadOnly) !=
+ kEfiOk)
+ {
+ mWriter.Write(L"newosldr: Fetch-Protocol: No-Such-Path: ")
+ .Write(mPath)
+ .Write(L"\r");
+ this->mErrorCode = kNotSupported;
+
+ mRootFs->Close(mRootFs);
+
+ return;
+ }
+
+ mSizeFile = 0;
+ mFile = kernelFile;
+ mErrorCode = kOperationOkay;
+}
+
+BFileReader::~BFileReader()
+{
+ if (this->mFile)
+ {
+ this->mFile->Close(this->mFile);
+ this->mFile = nullptr;
+ }
+
+ if (this->mRootFs)
+ {
+ this->mRootFs->Close(this->mRootFs);
+ this->mRootFs = nullptr;
+ }
+
+ if (this->mBlob)
+ {
+ BS->FreePool(this->mBlob);
+ this->mBlob = nullptr;
+ }
+
+ BSetMem(this->mPath, 0, kPathLen);
+}
+
+/**
+ @brief Reads all of the file into a buffer.
+ @param **readUntil** size of file
+ @param **chunkToRead** chunk to read each time.
+*/
+Void BFileReader::ReadAll(SizeT readUntil, SizeT chunkToRead, UIntPtr outAddress)
+{
+ if (mBlob == nullptr)
+ {
+ EfiFileInfo newPtrInfo;
+ UInt32 szInfo = 0;
+
+ EfiGUID cFileInfoGUID = EFI_FILE_INFO_GUID;
+
+ if (mFile->GetInfo(mFile, &cFileInfoGUID, &szInfo, &newPtrInfo) == kEfiOk)
+ {
+ if (newPtrInfo.FileSize < readUntil)
+ readUntil = newPtrInfo.FileSize;
+ else if (readUntil < 1)
+ readUntil = newPtrInfo.FileSize;
+
+ mWriter.Write(L"newosldr: physical size: ").Write(readUntil).Write("\r");
+ }
+
+ if (!outAddress)
+ {
+ if (auto err = BS->AllocatePool(EfiLoaderCode, readUntil, (VoidPtr*)&mBlob) !=
+ kEfiOk)
+ {
+ mWriter.Write(L"*** error: ").Write(err).Write(L" ***\r");
+ EFI::ThrowError(L"OutOfMemory", L"Out of memory.");
+ }
+ }
+ else
+ {
+ mBlob = (VoidPtr)outAddress;
+ }
+ }
+
+ mErrorCode = kNotSupported;
+
+ UInt64 bufSize = chunkToRead;
+ UInt64 szCnt = 0UL;
+
+ while (szCnt < readUntil)
+ {
+ auto res = mFile->Read(mFile, &bufSize, (VoidPtr)(&((Char*)mBlob)[szCnt]));
+
+ szCnt += bufSize;
+
+ if (res == kBufferTooSmall)
+ {
+ bufSize = chunkToRead;
+ }
+ }
+
+ mSizeFile = szCnt;
+ mErrorCode = kOperationOkay;
+}
+
+/// @brief error code getter.
+/// @return the error code.
+Int32& BFileReader::Error()
+{
+ return mErrorCode;
+}
+
+/// @brief blob getter.
+/// @return the blob.
+VoidPtr BFileReader::Blob()
+{
+ return mBlob;
+}
+
+/// @breif Size getter.
+/// @return the size of the file.
+UInt64& BFileReader::Size()
+{
+ return mSizeFile;
+}
diff --git a/dev/Boot/Sources/HEL/AMD64/BootJump.S b/dev/Boot/Sources/HEL/AMD64/BootJump.S
new file mode 100644
index 00000000..7c2fcbc4
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootJump.S
@@ -0,0 +1,21 @@
+.global rt_jump_to_address
+.text
+
+.text
+.intel_syntax noprefix
+
+/**
+ @brief this function setups a stack and then jumps to
+ a function */
+rt_jump_to_address:
+ mov rsp, r8
+
+ push rax
+ push rdx
+ mov rbx, rcx
+ mov rcx, rdx
+ jmp rbx
+ pop rdx
+ pop rax
+
+ ret
diff --git a/dev/Boot/Sources/HEL/AMD64/BootMain.cxx b/dev/Boot/Sources/HEL/AMD64/BootMain.cxx
new file mode 100644
index 00000000..a1d5ab07
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootMain.cxx
@@ -0,0 +1,259 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <BootKit/BootKit.hxx>
+#include <BootKit/Rsrc/NewBoot.rsrc>
+#include <Modules/CoreCG/FbRenderer.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
+#include <FirmwareKit/EFI.hxx>
+#include <FirmwareKit/EFI/API.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <KernelKit/MSDOS.hxx>
+#include <KernelKit/PE.hxx>
+#include <KernelKit/PEF.hxx>
+#include <NewKit/Macros.hxx>
+#include <NewKit/Ref.hxx>
+#include <BootKit/Thread.hxx>
+#include <cstring>
+
+// make the compiler shut up.
+#ifndef kMachineModel
+#define kMachineModel "ZKA SSD"
+#endif // !kMachineModel
+
+#ifndef cExpectedWidth
+#define cExpectedWidth 1280
+#endif
+
+#ifndef cExpectedHeight
+#define cExpectedHeight 720
+#endif
+
+/** Graphics related. */
+
+STATIC EfiGraphicsOutputProtocol* kGop = nullptr;
+STATIC UInt16 kStride = 0U;
+STATIC EfiGUID kGopGuid;
+
+EXTERN_C Void hal_init_platform(HEL::HandoverInformationHeader* HIH);
+
+/**
+ @brief Finds and stores the GOP.
+*/
+
+STATIC Void InitVideoFB() noexcept
+{
+ kGopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID);
+ kGop = nullptr;
+
+ extern EfiBootServices* BS;
+
+ BS->LocateProtocol(&kGopGuid, nullptr, (VoidPtr*)&kGop);
+
+ kStride = 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 == cExpectedWidth &&
+ infoPtr->VerticalResolution == cExpectedHeight)
+ {
+ kGop->SetMode(kGop, i);
+ break;
+ }
+ }
+}
+
+/// @brief check the BootDevice if suitable.
+STATIC Bool CheckBootDevice(BootDeviceATA& ataDev)
+{
+ if (ataDev.Leak().mErr)
+ return false;
+ return true;
+}
+
+/// @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 Int Main(EfiHandlePtr ImageHandle,
+ EfiSystemTable* SystemTable)
+{
+ InitEFI(SystemTable); ///! Init the EFI library.
+ InitVideoFB(); ///! Init the GOP.
+
+ BTextWriter writer;
+
+ /// Splash screen stuff
+
+ writer.Write(L"ZKA Technologies (R) newosldr: ")
+ .Write(BVersionString::The())
+ .Write("\r");
+
+ UInt32 MapKey = 0;
+ UInt32 SizePtr = sizeof(EfiMemoryDescriptor);
+ EfiMemoryDescriptor* Descriptor = nullptr;
+ UInt32 SzDesc = sizeof(EfiMemoryDescriptor);
+ UInt32 RevDesc = 0;
+
+ HEL::HandoverInformationHeader* handoverHdrPtr =
+ new HEL::HandoverInformationHeader();
+
+ for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries;
+ ++indexVT)
+ {
+ Char* vendorTable = reinterpret_cast<Char*>(
+ SystemTable->ConfigurationTable[indexVT].VendorTable);
+
+ /// ACPI's 'RSD PTR', which contains hardware tables (MADT, FACP...)
+ if (vendorTable[0] == 'R' && vendorTable[1] == 'S' &&
+ vendorTable[2] == 'D' && vendorTable[3] == ' ' &&
+ vendorTable[4] == 'P' && vendorTable[5] == 'T' &&
+ vendorTable[6] == 'R' && vendorTable[7] == ' ')
+ {
+ writer.Write(L"newosldr: Filling RSD PTR...\r");
+ handoverHdrPtr->f_HardwareTables.f_VendorPtr = (VoidPtr)vendorTable;
+
+ break;
+ }
+ }
+
+ // Fill handover header now.
+
+ BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc);
+
+ Descriptor = new EfiMemoryDescriptor[SzDesc];
+ BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc);
+
+ auto cDefaultMemoryMap = 0; // The sixth entry.
+
+ //-----------------------------------------------------------//
+ // A simple loop which finds a usable memory region for us.
+ //-----------------------------------------------------------//
+
+ SizeT lookIndex = 0UL;
+
+ for (; Descriptor[lookIndex].Kind != EfiMemoryType::EfiConventionalMemory; ++lookIndex)
+ {
+ ;
+ }
+
+ cDefaultMemoryMap = lookIndex;
+
+ //-----------------------------------------------------------//
+ // Update handover file specific table and phyiscal start field.
+ //-----------------------------------------------------------//
+
+ handoverHdrPtr->f_PhysicalStart =
+ (VoidPtr)Descriptor[cDefaultMemoryMap].PhysicalStart;
+
+ handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificAttrib] =
+ Descriptor[cDefaultMemoryMap].Attribute;
+ handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificKind] =
+ Descriptor[cDefaultMemoryMap].Kind;
+ handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificMemoryEfi] =
+ (UIntPtr)Descriptor;
+
+ handoverHdrPtr->f_VirtualStart =
+ (VoidPtr)Descriptor[cDefaultMemoryMap].VirtualStart;
+
+ handoverHdrPtr->f_VirtualSize =
+ Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */
+
+ handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+
+ handoverHdrPtr->f_Magic = kHandoverMagic;
+ handoverHdrPtr->f_Version = kHandoverVersion;
+
+ // Provide fimware vendor name.
+
+ BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
+ handoverHdrPtr->f_FirmwareVendorLen);
+
+ handoverHdrPtr->f_GOP.f_The = kGop->Mode->FrameBufferBase;
+ handoverHdrPtr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution;
+ handoverHdrPtr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution;
+ handoverHdrPtr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine;
+ handoverHdrPtr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat;
+ handoverHdrPtr->f_GOP.f_Size = kGop->Mode->FrameBufferSize;
+
+ // Assign to global 'kHandoverHeader'.
+
+ kHandoverHeader = handoverHdrPtr;
+
+ // ------------------------------------------ //
+ // draw background color.
+ // ------------------------------------------ //
+
+ CGInit();
+ CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), handoverHdrPtr->f_GOP.f_Height, handoverHdrPtr->f_GOP.f_Width, 0, 0);
+ CGFini();
+
+ BDiskFormatFactory<BootDeviceATA> checkPart;
+
+ if (!checkPart.IsPartitionValid())
+ {
+ writer.Write("newosldr: Warning, partition isn't valid! repaired it.\rPlease restart the computer now.\r");
+
+ BDiskFormatFactory<BootDeviceATA>::BFileDescriptor root;
+ root.fFileName[0] = kNewFSRoot[0];
+ root.fFileName[1] = 0;
+
+ root.fKind = kNewFSCatalogKindDir;
+
+ checkPart.Format("ZKA (C:)", &root, 1);
+
+ EFI::Stop();
+ }
+
+ // ---------------------------------------------------- //
+ // The following checks for an exisiting partition
+ // inside the disk, if it doesn't have one,
+ // format the disk.
+ // ---------------------------------------------------- //
+
+ BFileReader readerKernel(L"newoskrnl.dll", ImageHandle);
+
+ readerKernel.ReadAll(0);
+
+ Boot::Thread* loader = nullptr;
+
+ // ------------------------------------------ //
+ // If we succeed in reading the blob, then execute it.
+ // ------------------------------------------ //
+
+ if (readerKernel.Blob())
+ {
+ loader = new Boot::Thread(readerKernel.Blob());
+ loader->SetName("64-bit Kernel SMP DLL.");
+ }
+
+ writer.Write("newosldr: Running: ").Write(loader->GetName()).Write("\r");
+
+ /// TODO: Parse command line from ZKA\cmd.json
+ // CopyMem(handoverHdrPtr->f_CommandLine[0], "/SMP", StrLen("/SMP"));
+
+ handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+
+ EFI::ExitBootServices(MapKey, ImageHandle);
+
+ // ---------------------------------------------------- //
+ // Call kernel.
+ // ---------------------------------------------------- //
+
+ cg_write_text("NEWOSLDR (C) ZKA TECHNOLOGIES.", 10, 10, RGB(0x00, 0x00, 0x00));
+ cg_write_text("LOADING NEWOSKRNL...", 20, 10, RGB(0x00, 0x00, 0x00));
+
+ loader->Start(handoverHdrPtr);
+
+ EFI::Stop();
+
+ CANT_REACH();
+}
diff --git a/dev/Boot/Sources/HEL/AMD64/BootPlatform.cxx b/dev/Boot/Sources/HEL/AMD64/BootPlatform.cxx
new file mode 100644
index 00000000..c5218fe1
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootPlatform.cxx
@@ -0,0 +1,103 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
+#include <BootKit/BootKit.hxx>
+
+#ifdef __STANDALONE__
+
+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.hxx>
+
+void rt_hlt()
+{
+ Kernel::HAL::rt_halt();
+}
+
+#endif // 0
diff --git a/dev/Boot/Sources/HEL/AMD64/BootString.cxx b/dev/Boot/Sources/HEL/AMD64/BootString.cxx
new file mode 100644
index 00000000..ad87bce2
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootString.cxx
@@ -0,0 +1,92 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: String.cxx
+ Purpose: NewBoot string library
+
+ Revision History:
+
+
+
+------------------------------------------- */
+
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
+#include <BootKit/BootKit.hxx>
+
+/// bugs 0
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+Kernel::SizeT BCopyMem(CharacterTypeUTF16* dest, CharacterTypeUTF16* src, const Kernel::SizeT len)
+{
+ if (!dest || !src)
+ return 0;
+
+ SizeT index = 0UL;
+ for (; index < len; ++index)
+ {
+ dest[index] = src[index];
+ }
+
+ return index;
+}
+
+Kernel::SizeT BStrLen(const CharacterTypeUTF16* ptr)
+{
+ if (!ptr)
+ return 0;
+
+ Kernel::SizeT cnt = 0;
+
+ while (*ptr != (CharacterTypeUTF16)0)
+ {
+ ++ptr;
+ ++cnt;
+ }
+
+ return cnt;
+}
+
+Kernel::SizeT BSetMem(CharacterTypeUTF16* src, const CharacterTypeUTF16 byte, const Kernel::SizeT len)
+{
+ if (!src)
+ return 0;
+
+ Kernel::SizeT cnt = 0UL;
+
+ while (*src != 0)
+ {
+ if (cnt > len)
+ break;
+
+ *src = byte;
+ ++src;
+
+ ++cnt;
+ }
+
+ return cnt;
+}
+
+Kernel::SizeT BSetMem(CharacterTypeUTF8* src, const CharacterTypeUTF8 byte, const Kernel::SizeT len)
+{
+ if (!src)
+ return 0;
+
+ Kernel::SizeT cnt = 0UL;
+
+ while (*src != 0)
+ {
+ if (cnt > len)
+ break;
+
+ *src = byte;
+ ++src;
+
+ ++cnt;
+ }
+
+ return cnt;
+}
diff --git a/dev/Boot/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/Boot/Sources/HEL/AMD64/BootTextWriter.cxx
new file mode 100644
index 00000000..467f4303
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/BootTextWriter.cxx
@@ -0,0 +1,170 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+ File: String.cxx
+ Purpose: NewBoot string library
+
+ Revision History:
+
+
+
+------------------------------------------- */
+
+#include <FirmwareKit/EFI/API.hxx>
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
+#include <BootKit/BootKit.hxx>
+
+/// BUGS: 0
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+@brief puts wrapper over EFI ConOut.
+*/
+BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str)
+{
+#ifdef __DEBUG__
+ if (!str || *str == 0)
+ return *this;
+
+ CharacterTypeUTF16 strTmp[2];
+ strTmp[1] = 0;
+
+ for (size_t i = 0; str[i] != 0; i++)
+ {
+ if (str[i] == '\r')
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+
+ strTmp[0] = '\n';
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ else
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ }
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+/// @brief UTF-8 equivalent of Write (UTF-16).
+/// @param str the input string.
+BTextWriter& BTextWriter::Write(const Char* str)
+{
+#ifdef __DEBUG__
+ if (!str || *str == 0)
+ return *this;
+
+ CharacterTypeUTF16 strTmp[2];
+ strTmp[1] = 0;
+
+ for (size_t i = 0; str[i] != 0; i++)
+ {
+ if (str[i] == '\r')
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+
+ strTmp[0] = '\n';
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ else
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ }
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+BTextWriter& BTextWriter::Write(const UChar* str)
+{
+#ifdef __DEBUG__
+ if (!str || *str == 0)
+ return *this;
+
+ CharacterTypeUTF16 strTmp[2];
+ strTmp[1] = 0;
+
+ for (size_t i = 0; str[i] != 0; i++)
+ {
+ if (str[i] == '\r')
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+
+ strTmp[0] = '\n';
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ else
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ }
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+/**
+@brief putc wrapper over EFI ConOut.
+*/
+BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c)
+{
+#ifdef __DEBUG__
+ EfiCharType str[2];
+
+ str[0] = c;
+ str[1] = 0;
+ ST->ConOut->OutputString(ST->ConOut, str);
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+BTextWriter& BTextWriter::Write(const Long& x)
+{
+#ifdef __DEBUG__
+ this->Write(L"0x");
+ this->_Write(x);
+
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+BTextWriter& BTextWriter::_Write(const Long& x)
+{
+#ifdef __DEBUG__
+ UInt64 y = (x > 0 ? x : -x) / 16;
+ UInt64 h = (x > 0 ? x : -x) % 16;
+
+ if (y)
+ this->_Write(y);
+
+ /* fail if the hex number is not base-16 */
+ if (h > 15)
+ {
+ this->WriteCharacter('?');
+ return *this;
+ }
+
+ if (y < 0)
+ y = -y;
+
+ const char cNumbers[17] = "0123456789ABCDEF";
+
+ this->WriteCharacter(cNumbers[h]);
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
diff --git a/dev/Boot/Sources/HEL/AMD64/New+Delete.cxx b/dev/Boot/Sources/HEL/AMD64/New+Delete.cxx
new file mode 100644
index 00000000..8b9a41fa
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/New+Delete.cxx
@@ -0,0 +1,62 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <BootKit/Platform.hxx>
+#include <BootKit/Protocol.hxx>
+#include <BootKit/BootKit.hxx>
+
+#ifdef __STANDALONE__
+#include <cstddef> /* Since we're using GCC for this EFI program. */
+
+EXTERN EfiBootServices* BS;
+
+/// @brief Allocates a new object.
+/// @param sz the size.
+/// @return
+void* operator new(size_t sz)
+{
+ void* buf = nullptr;
+
+ while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) == kBufferTooSmall)
+ BS->FreePool(buf);
+
+ return buf;
+}
+
+/// @brief Allocates a new object.
+/// @param sz the size.
+/// @return
+void* operator new[](size_t sz)
+{
+ void* buf = nullptr;
+ BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf);
+
+ return buf;
+}
+
+/// @brief Deletes the object.
+/// @param buf the object.
+void operator delete(void* buf)
+{
+ BS->FreePool(buf);
+}
+
+/// @brief Deletes the object.
+/// @param buf the object.
+void operator delete[](void* buf)
+{
+ BS->FreePool(buf);
+}
+
+/// @brief Deletes the object (array specific).
+/// @param buf the object.
+/// @param size it's size.
+void operator delete(void* buf, size_t size)
+{
+ BS->FreePool(buf);
+}
+
+#endif // Inactive
diff --git a/dev/Boot/Sources/HEL/AMD64/Support.cxx b/dev/Boot/Sources/HEL/AMD64/Support.cxx
new file mode 100644
index 00000000..667bbfda
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/Support.cxx
@@ -0,0 +1,82 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <BootKit/BootKit.hxx>
+#include <FirmwareKit/EFI/API.hxx>
+#include <FirmwareKit/EFI/EFI.hxx>
+#include <FirmwareKit/Handover.hxx>
+#include <BootKit/Support.hxx>
+#include <KernelKit/MSDOS.hxx>
+#include <KernelKit/PE.hxx>
+
+#ifdef __STANDALONE__
+
+/// @brief memset definition in C++.
+/// @param dst destination pointer.
+/// @param byte value to fill in.
+/// @param len length of of src.
+EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len)
+{
+ for (size_t i = 0UL; i < len; ++i)
+ {
+ ((int*)dst)[i] = byte;
+ }
+
+ return dst;
+}
+
+/// @brief memcpy definition in C++.
+/// @param dst destination pointer.
+/// @param src source pointer.
+/// @param len length of of src.
+EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len)
+{
+ for (size_t i = 0UL; i < len; ++i)
+ {
+ ((int*)dst)[i] = ((int*)src)[i];
+ }
+
+ return dst;
+}
+
+/// @brief strlen definition in C++.
+EXTERN_C size_t strlen(const char* whatToCheck)
+{
+ SizeT len = 0;
+
+ while (whatToCheck[len] != 0)
+ {
+ ++len;
+ }
+
+ return len;
+}
+
+/// @brief strcmp definition in C++.
+EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight)
+{
+ if (!whatToCheck || *whatToCheck == 0)
+ return 0;
+
+ SizeT len = 0;
+
+ while (whatToCheck[len] == whatToCheckRight[len])
+ {
+ if (whatToCheck[len] == 0)
+ return 0;
+
+ ++len;
+ }
+
+ return whatToCheck[len] == whatToCheckRight[len] ? 0 : len;
+}
+
+/// @brief somthing specific to the Microsoft's ABI, When the stack grows too big.
+EXTERN_C void ___chkstk_ms(void)
+{
+}
+
+#endif
diff --git a/dev/Boot/Sources/HEL/AMD64/compile_flags.txt b/dev/Boot/Sources/HEL/AMD64/compile_flags.txt
new file mode 100644
index 00000000..c24c4b09
--- /dev/null
+++ b/dev/Boot/Sources/HEL/AMD64/compile_flags.txt
@@ -0,0 +1,7 @@
+-std=c++20
+-I../../../
+-I../../../../Kernel
+-D__NEWOS_AMD64__
+-std=c++20
+-D__x86_64__
+-D__NEWOS_OTA__
diff --git a/dev/Boot/Sources/HEL/ARM64/.gitkeep b/dev/Boot/Sources/HEL/ARM64/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/Boot/Sources/HEL/ARM64/.gitkeep
diff --git a/dev/Boot/Sources/HEL/POWER/.gitkeep b/dev/Boot/Sources/HEL/POWER/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev/Boot/Sources/HEL/POWER/.gitkeep
diff --git a/dev/Boot/Sources/HEL/POWER/CoreBootStartup.S b/dev/Boot/Sources/HEL/POWER/CoreBootStartup.S
new file mode 100644
index 00000000..502f415c
--- /dev/null
+++ b/dev/Boot/Sources/HEL/POWER/CoreBootStartup.S
@@ -0,0 +1,34 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+.section .boot_hdr
+.align 4
+
+/* NewBoot boot header begin */
+
+boot_hdr_mag:
+ .ascii "CB"
+boot_hdr_name:
+ // it has to match ten bytes.
+ .asciz "newosldr\0\0"
+boot_hdr_ver:
+ .word 0x104
+boot_hdr_proc:
+ .long bootloader_start
+
+/* NewBoot boot header end */
+
+.extern bootloader_main
+.extern bootloader_stack
+
+.globl bootloader_start
+bootloader_start:
+ mflr 4 /* real address of .Laddr */
+ lwz 0,(bootloader_stack-bootloader_start)(4) /* stack address location */
+ mr 1,0 /* use user defined stack */
+
+ bl bootloader_main
+ blr
diff --git a/dev/Boot/Sources/Root/EFI/STARTUP.NSH b/dev/Boot/Sources/Root/EFI/STARTUP.NSH
new file mode 100644
index 00000000..d29ba8fd
--- /dev/null
+++ b/dev/Boot/Sources/Root/EFI/STARTUP.NSH
@@ -0,0 +1,2 @@
+fs0:
+BOOT\BOOTX64.EFI
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-Black.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-Black.ttf
new file mode 100644
index 00000000..e1ec32b3
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-Black.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-BlackItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-BlackItalic.ttf
new file mode 100644
index 00000000..85323c97
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-BlackItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-Bold.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-Bold.ttf
new file mode 100644
index 00000000..330e84f9
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-Bold.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-BoldItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-BoldItalic.ttf
new file mode 100644
index 00000000..08d47a8a
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-BoldItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBold.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBold.ttf
new file mode 100644
index 00000000..7971b6db
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBold.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBoldItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBoldItalic.ttf
new file mode 100644
index 00000000..050297e2
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraBoldItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLight.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLight.ttf
new file mode 100644
index 00000000..a20a0bf9
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLight.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLightItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLightItalic.ttf
new file mode 100644
index 00000000..68968472
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-ExtraLightItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-Italic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-Italic.ttf
new file mode 100644
index 00000000..79688a6c
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-Italic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-Light.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-Light.ttf
new file mode 100644
index 00000000..59034000
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-Light.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-LightItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-LightItalic.ttf
new file mode 100644
index 00000000..1a455ce2
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-LightItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-Medium.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-Medium.ttf
new file mode 100644
index 00000000..e9a6dbb0
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-Medium.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-MediumItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-MediumItalic.ttf
new file mode 100644
index 00000000..44a9c897
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-MediumItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-Regular.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-Regular.ttf
new file mode 100644
index 00000000..2a794b27
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-Regular.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-SemiBold.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-SemiBold.ttf
new file mode 100644
index 00000000..6d393d1c
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-SemiBold.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-SemiBoldItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-SemiBoldItalic.ttf
new file mode 100644
index 00000000..327aa044
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-SemiBoldItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-Thin.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-Thin.ttf
new file mode 100644
index 00000000..9e272162
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-Thin.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/Urbanist-ThinItalic.ttf b/dev/Boot/Sources/Root/ZKA/Urbanist-ThinItalic.ttf
new file mode 100644
index 00000000..5cf054f1
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/Urbanist-ThinItalic.ttf
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/boot-scr.bmp b/dev/Boot/Sources/Root/ZKA/boot-scr.bmp
new file mode 100644
index 00000000..f901bb28
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/boot-scr.bmp
Binary files differ
diff --git a/dev/Boot/Sources/Root/ZKA/fonts.json b/dev/Boot/Sources/Root/ZKA/fonts.json
new file mode 100644
index 00000000..05487cec
--- /dev/null
+++ b/dev/Boot/Sources/Root/ZKA/fonts.json
@@ -0,0 +1,4 @@
+{
+ "font_pkg_src": "*.ttf",
+ "font_pkg_name": "ZKA Standard Fonts."
+}
diff --git a/dev/Boot/Sources/Thread.cxx b/dev/Boot/Sources/Thread.cxx
new file mode 100644
index 00000000..5bd18b19
--- /dev/null
+++ b/dev/Boot/Sources/Thread.cxx
@@ -0,0 +1,179 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <BootKit/Thread.hxx>
+#include <BootKit/Support.hxx>
+#include <BootKit/BootKit.hxx>
+#include <FirmwareKit/EFI/API.hxx>
+
+#include <KernelKit/PEF.hxx>
+#include <KernelKit/PE.hxx>
+#include <KernelKit/MSDOS.hxx>
+#include <Modules/CoreCG/TextRenderer.hxx>
+#include <CFKit/LoaderUtils.hxx>
+
+EXTERN_C
+{
+#include <string.h>
+}
+
+#define kHOTypeKernel 100
+
+EXTERN EfiBootServices* BS;
+
+namespace Boot
+{
+ Thread::Thread(VoidPtr blob)
+ : fBlob(blob), fStartAddress(nullptr)
+ {
+ // detect the format.
+ const Char* firstBytes = reinterpret_cast<char*>(fBlob);
+
+ BTextWriter writer;
+
+ if (!firstBytes)
+ {
+ // failed to provide a valid pointer.
+ return;
+ }
+
+ if (firstBytes[0] == kMagMz0 &&
+ firstBytes[1] == kMagMz1)
+ {
+ ExecHeaderPtr hdrPtr = ldr_find_exec_header(firstBytes);
+ ExecOptionalHeaderPtr optHdr = ldr_find_opt_exec_header(firstBytes);
+
+ if (hdrPtr->mMachine != kPeMachineAMD64 ||
+ hdrPtr->mSignature != kPeMagic)
+ {
+ writer.Write("newosldr: Not a PE32+ executable.\r");
+ return;
+ }
+
+ if (optHdr->mSubsystem != kNewOSSubsystem)
+ {
+ writer.Write("newosldr: Not a New OS executable.\r");
+ return;
+ }
+
+ writer.Write("newosldr: PE32+ executable detected (New OS Subsystem).\r");
+
+ auto numSecs = hdrPtr->mNumberOfSections;
+
+ writer.Write("newosldr: Major Linker Ver: ").Write(optHdr->mMajorLinkerVersion).Write("\r");
+ writer.Write("newosldr: Minor Linker Ver: ").Write(optHdr->mMinorLinkerVersion).Write("\r");
+ writer.Write("newosldr: Major Subsystem Ver: ").Write(optHdr->mMajorSubsystemVersion).Write("\r");
+ writer.Write("newosldr: Minor Subsystem Ver: ").Write(optHdr->mMinorSubsystemVersion).Write("\r");
+ writer.Write("newosldr: Magic: ").Write(hdrPtr->mSignature).Write("\r");
+
+ constexpr auto cPageSize = 512;
+
+ EfiPhysicalAddress loadStartAddress = optHdr->mImageBase;
+ loadStartAddress += optHdr->mBaseOfData;
+
+ writer.Write("newosldr: ImageBase: ").Write(loadStartAddress).Write("\r");
+
+ auto numPages = optHdr->mSizeOfImage / cPageSize;
+ BS->AllocatePages(AllocateAddress, EfiLoaderData, numPages, &loadStartAddress);
+
+ ExecSectionHeaderPtr sectPtr = (ExecSectionHeaderPtr)(((Char*)optHdr) + hdrPtr->mSizeOfOptionalHeader);
+
+ constexpr auto sectionForCode = ".text";
+ constexpr auto sectionForNewLdr = ".ldr";
+ constexpr auto sectionForBSS = ".bss";
+
+ for (SizeT sectIndex = 0; sectIndex < numSecs; ++sectIndex)
+ {
+ ExecSectionHeaderPtr sect = &sectPtr[sectIndex];
+
+ if (StrCmp(sectionForCode, sect->mName) == 0)
+ {
+ fStartAddress = (VoidPtr)((UIntPtr)loadStartAddress + optHdr->mAddressOfEntryPoint);
+ writer.Write("newosldr: Start Address: ").Write((UIntPtr)fStartAddress).Write("\r");
+ }
+ else if (StrCmp(sectionForBSS, sect->mName) == 0)
+ {
+ SetMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), 0, sect->mSizeOfRawData);
+ }
+ else if (StrCmp(sectionForNewLdr, sect->mName) == 0)
+ {
+ struct HANDOVER_INFORMATION_STUB
+ {
+ UInt64 HandoverMagic;
+ UInt32 HandoverType;
+ }* structHandover = (struct HANDOVER_INFORMATION_STUB*)((UIntPtr)fBlob + sect->mPointerToRawData);
+
+ if (structHandover->HandoverMagic != kHandoverMagic ||
+ structHandover->HandoverType != kHOTypeKernel)
+ {
+ cg_write_text("NEWOSLDR: INVALID HANDOVER IMAGE! ABORTING...", 40, 10, RGB(0x00, 0x00, 0x00));
+ EFI::Stop();
+ }
+ }
+
+ writer.Write("newosldr: offset ").Write(sect->mPointerToRawData).Write(" of ").Write(sect->mName).Write("\r");
+
+ CopyMem((VoidPtr)(loadStartAddress + sect->mVirtualAddress), (VoidPtr)((UIntPtr)fBlob + sect->mPointerToRawData), sect->mSizeOfRawData);
+ }
+ }
+ else if (firstBytes[0] == kPefMagic[0] &&
+ firstBytes[1] == kPefMagic[1] &&
+ firstBytes[2] == kPefMagic[2] &&
+ firstBytes[3] == kPefMagic[3])
+ {
+ // ========================================= //
+ // PEF executable detected.
+ // ========================================= //
+
+ fStartAddress = nullptr;
+ writer.Write("newosldr: PEF executable detected.\r");
+ }
+ else
+ {
+ writer.Write("newosldr: Invalid executable.\r");
+ }
+ }
+
+ /// @note handover header has to be valid!
+ Void Thread::Start(HEL::HandoverInformationHeader* handover)
+ {
+ BTextWriter writer;
+
+ if (!handover)
+ {
+ writer.Write("newosldr: Exec format error.\r");
+ return;
+ }
+
+ HEL::HandoverProc err_fn = [](HEL::HandoverInformationHeader* rcx) -> void {
+ cg_write_text("NEWOSLDR: INVALID IMAGE! ABORTING...", 40, 10, RGB(0x00, 0x00, 0x00));
+ EFI::Stop();
+ };
+
+ if (!fStartAddress)
+ {
+ err_fn(handover);
+ }
+
+ reinterpret_cast<HEL::HandoverProc>(fStartAddress)(handover);
+ err_fn(handover);
+ }
+
+ const Char* Thread::GetName()
+ {
+ return fBlobName;
+ }
+
+ Void Thread::SetName(const Char* name)
+ {
+ CopyMem(fBlobName, name, StrLen(name));
+ }
+
+ bool Thread::IsValid()
+ {
+ return fStartAddress != nullptr;
+ }
+} // namespace Boot
diff --git a/dev/Boot/Sources/compile_flags.txt b/dev/Boot/Sources/compile_flags.txt
new file mode 100644
index 00000000..f9ca281f
--- /dev/null
+++ b/dev/Boot/Sources/compile_flags.txt
@@ -0,0 +1,8 @@
+-std=c++20
+-I../
+-I../../
+-I../../Kernel
+-D__NEWOS_AMD64__
+-std=c++20
+-D__x86_64__
+-D__NEWOS_OTA__