summaryrefslogtreecommitdiffhomepage
path: root/newBoot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-06 09:14:11 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-06 09:14:11 +0100
commit5339d016c07bf717ee388f4feb73544087324af0 (patch)
tree94be6f67ed626091f24aee24ec3b3be03d01e4e7 /newBoot
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'newBoot')
-rw-r--r--newBoot/BootKit/Boot.hpp70
-rw-r--r--newBoot/Source/.gitkeep0
-rw-r--r--newBoot/Source/Arch/AMD64/.gitkeep0
-rw-r--r--newBoot/Source/Arch/AMD64/ATA.cxx166
-rw-r--r--newBoot/Source/Arch/AMD64/ATA.hxx106
-rw-r--r--newBoot/Source/Arch/AMD64/BIOSAllocApi.inc40
-rw-r--r--newBoot/Source/Arch/AMD64/BIOSApiGdt.inc36
-rw-r--r--newBoot/Source/Arch/AMD64/BIOSRuntime.cxx8
-rw-r--r--newBoot/Source/Arch/AMD64/BIOSRuntime0.asm50
-rw-r--r--newBoot/Source/Arch/AMD64/BootAMD64.cxx60
-rw-r--r--newBoot/Source/Arch/AMD64/EFIApi.hxx25
-rw-r--r--newBoot/Source/Arch/AMD64/EFIApiCrt0.cxx33
-rw-r--r--newBoot/Source/Arch/AMD64/makefile32
-rw-r--r--newBoot/Source/Arch/NewCPU/Crt0.asm29
-rw-r--r--newBoot/Source/Arch/NewCPU/XPM.inc35
-rw-r--r--newBoot/Source/BootNotes.txt9
-rw-r--r--newBoot/Source/FSKit/.hgkeep0
-rw-r--r--newBoot/Source/FSKit/FileType.hxx30
-rw-r--r--newBoot/Source/FSKit/Files32.cxx10
-rw-r--r--newBoot/Source/FSKit/Files32.hxx36
-rw-r--r--newBoot/Source/FSKit/MPT.hxx29
-rw-r--r--newBoot/Source/Start.cxx19
-rw-r--r--newBoot/Source/makefile23
-rw-r--r--newBoot/cxxKitModule/__cxxkit_unwind.cxx11
-rw-r--r--newBoot/cxxKitModule/manifest.json3
-rw-r--r--newBoot/netBootModule/.hgkeep0
-rw-r--r--newBoot/netBootModule/manifest.json4
-rw-r--r--newBoot/netBootModule/module.cxx13
28 files changed, 877 insertions, 0 deletions
diff --git a/newBoot/BootKit/Boot.hpp b/newBoot/BootKit/Boot.hpp
new file mode 100644
index 00000000..b7199f08
--- /dev/null
+++ b/newBoot/BootKit/Boot.hpp
@@ -0,0 +1,70 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <NewKit/Defines.hpp>
+
+using namespace hCore;
+
+typedef void* PEFImage;
+
+enum
+{
+ kSegmentCode = 2,
+ kSegmentData = 4,
+ kSegmentBss = 6,
+};
+
+class BTextWriter final
+{
+ volatile UInt16* fWhere;
+
+public:
+ void WriteString(const char* c,
+ unsigned char forecolour,
+ unsigned char backcolour,
+ int x,
+ int y);
+
+ void WriteCharacter(char c,
+ unsigned char forecolour,
+ unsigned char backcolour,
+ int x,
+ int y);
+
+public:
+ BTextWriter() = default;
+ ~BTextWriter() = default;
+
+public:
+ BTextWriter& operator=(const BTextWriter&) = default;
+ BTextWriter(const BTextWriter&) = default;
+
+};
+
+enum
+{
+ kBlack,
+ kBlue,
+ kGreen,
+ kCyan,
+ kRed,
+ kMagenta,
+ kBrown,
+ kLightGray,
+ kDarkGray,
+ kLightBlue,
+ kLightGreen,
+ kLightCyan,
+ kLightRed,
+ kLightMagenta,
+ kYellow,
+ kWhite,
+};
diff --git a/newBoot/Source/.gitkeep b/newBoot/Source/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/newBoot/Source/.gitkeep
diff --git a/newBoot/Source/Arch/AMD64/.gitkeep b/newBoot/Source/Arch/AMD64/.gitkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/.gitkeep
diff --git a/newBoot/Source/Arch/AMD64/ATA.cxx b/newBoot/Source/Arch/AMD64/ATA.cxx
new file mode 100644
index 00000000..5ddf3efa
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/ATA.cxx
@@ -0,0 +1,166 @@
+/*
+ * Copyright Mahrouss Logic, all rights reserved
+ */
+
+#include "ATA.hxx"
+#include <ArchKit/Arch.hpp>
+
+using namespace hCore::HAL;
+
+static Boolean kATADetected = false;
+
+void IDESelect(UInt8 Bus, Boolean isMaster)
+{
+ if (Bus == ATA_PRIMARY)
+ out8(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL,
+ isMaster ? ATA_PRIMARY_SEL : ATA_SECONDARY_SEL);
+ else
+ out8(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL,
+ isMaster ? ATA_PRIMARY_SEL : ATA_SECONDARY_SEL);
+}
+
+Boolean ATAInitDriver(UInt8 Bus, UInt8 Drive)
+{
+ UInt16 IO = (Bus == ATA_PRIMARY) ? ATA_PRIMARY_IO : ATA_SECONDARY_IO;
+
+ IDESelect(Bus, Drive);
+
+ out8(IO + ATA_REG_SEC_COUNT0, 0);
+ out8(IO + ATA_REG_LBA0, 0);
+ out8(IO + ATA_REG_LBA1, 0);
+ out8(IO + ATA_REG_LBA2, 0);
+
+ out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY);
+
+ UInt8 status = in8(IO + ATA_REG_STATUS);
+
+ if (status)
+ {
+ while ((status = in8(IO + ATA_REG_STATUS) & ATA_SR_BSY))
+ ;
+
+ if (status & ATA_REG_ERROR)
+ {
+ return false;
+ }
+
+ kATADetected = true;
+ return status;
+ }
+
+ return false;
+}
+
+void ATAWait(UInt16 IO)
+{
+ for (int i = 0; i < 4000; i++)
+ in8(IO + ATA_REG_ALT_STATUS);
+}
+
+void IDEPoll(UInt16 IO) { ATAWait(IO); }
+
+UInt16 ATAReadLba(UInt32 lba, UInt8 bus, Boolean master)
+{
+ UInt16 IO = bus;
+ IDESelect(IO, master ? ATA_MASTER : ATA_SLAVE);
+
+ out8(IO + ATA_REG_LBA5, (UInt8)(lba >> 24) & 0xF);
+
+ out8(IO + ATA_REG_SEC_COUNT0, lba / 512);
+
+ out8(IO + ATA_REG_LBA0, (UInt8)lba);
+ out8(IO + ATA_REG_LBA1, (UInt8)(lba >> 8));
+ out8(IO + ATA_REG_LBA2, (UInt8)(lba >> 16));
+
+ out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO);
+
+ IDEPoll(IO);
+
+ UInt16 data = in16(IO + ATA_REG_DATA);
+
+ while ((in8(ATA_COMMAND(IO))) & 0x88)
+ ATAWait(IO);
+
+ return data;
+}
+
+Void ATAWriteLba(UInt16 Byte, UInt32 lba, UInt8 bus, Boolean master)
+{
+ UInt16 IO = bus;
+ IDESelect(IO, master ? ATA_MASTER : ATA_SLAVE);
+
+ out8(IO + ATA_REG_LBA5, (UInt8)(lba >> 24) & 0xF);
+
+ out8(IO + ATA_REG_SEC_COUNT0, lba / 512);
+
+ out8(IO + ATA_REG_LBA0, (UInt8)lba);
+ out8(IO + ATA_REG_LBA1, (UInt8)(lba >> 8));
+ out8(IO + ATA_REG_LBA2, (UInt8)(lba >> 16));
+
+ out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); // TODO: support DMA
+
+ IDEPoll(IO);
+
+ out32(IO + ATA_REG_DATA, Byte);
+
+ while ((in8(ATA_COMMAND(IO))) & 0x88)
+ ATAWait(IO);
+}
+
+Boolean ATAIsDetected(Void) { return kATADetected; }
+
+extern "C" void _start(void)
+{
+ ATAInitDriver(ATA_PRIMARY, true);
+ ATAInitDriver(ATA_PRIMARY, false);
+
+ ATAInitDriver(ATA_SECONDARY, true);
+ ATAInitDriver(ATA_SECONDARY, false);
+}
+
+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 = 0UL;
+ asm volatile("inb %1, %%al" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
+
+extern "C" UInt16 in16(UInt16 port)
+{
+ UInt16 value = 0UL;
+ asm volatile("inw %1, %%ax" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
+
+extern "C" UInt32 in32(UInt16 port)
+{
+ UInt32 value = 0UL;
+ asm volatile("inl %1, %%eax" : "=a"(value) : "Nd"(port) : "memory");
+
+ return value;
+}
+
+extern "C" void rt_halt() { 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"); } \ No newline at end of file
diff --git a/newBoot/Source/Arch/AMD64/ATA.hxx b/newBoot/Source/Arch/AMD64/ATA.hxx
new file mode 100644
index 00000000..09cc4007
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/ATA.hxx
@@ -0,0 +1,106 @@
+#pragma once
+
+#include <NewKit/Defines.hpp>
+
+using namespace hCore;
+
+// Status register
+#define ATA_SR_BSY 0x80
+#define ATA_SR_DRDY 0x40
+#define ATA_SR_DF 0x20
+#define ATA_SR_DSC 0x10
+#define ATA_SR_DRQ 0x08
+#define ATA_SR_CORR 0x04
+#define ATA_SR_IDX 0x02
+#define ATA_SR_ERR 0x01
+
+// Error register
+#define ATA_ER_BBK 0x80
+#define ATA_ER_UNC 0x40
+#define ATA_ER_MC 0x20
+#define ATA_ER_IDNF 0x10
+#define ATA_ER_MCR 0x08
+#define ATA_ER_ABRT 0x04
+#define ATA_ER_TK0NF 0x02
+#define ATA_ER_AMNF 0x01
+
+#define ATA_CMD_READ_PIO 0x20
+#define ATA_CMD_READ_PIO_EXT 0x24
+#define ATA_CMD_READ_DMA 0xC8
+#define ATA_CMD_READ_DMA_EXT 0x25
+#define ATA_CMD_WRITE_PIO 0x30
+#define ATA_CMD_WRITE_PIO_EXT 0x34
+#define ATA_CMD_WRITE_DMA 0xCA
+#define ATA_CMD_WRITE_DMA_EXT 0x35
+#define ATA_CMD_CACHE_FLUSH 0xE7
+#define ATA_CMD_CACHE_FLUSH_EXT 0xEA
+#define ATA_CMD_PACKET 0xA0
+#define ATA_CMD_IDENTIFY_PACKET 0xA1
+#define ATA_CMD_IDENTIFY 0xEC
+
+#define ATA_IDENT_DEVICE_TYPE 0
+#define ATA_IDENT_CYLINDERS 2
+#define ATA_IDENT_HEADS 6
+#define ATA_IDENT_SECTORS 12
+#define ATA_IDENT_SERIAL 20
+#define ATA_IDENT_MODEL 54
+#define ATA_IDENT_CAPABILITIES 98
+#define ATA_IDENT_FIELDVALID 106
+#define ATA_IDENT_MAX_LBA 120
+#define ATA_IDENT_COMMANDSETS 164
+#define ATA_IDENT_MAX_LBA_EXT 200
+
+
+#define ATA_MASTER 0x00
+#define ATA_SLAVE 0x01
+
+// Register
+#define ATA_REG_DATA 0x00
+#define ATA_REG_ERROR 0x01
+#define ATA_REG_FEATURES 0x01
+#define ATA_REG_SEC_COUNT0 0x02
+#define ATA_REG_LBA0 0x03
+#define ATA_REG_LBA1 0x04
+#define ATA_REG_LBA2 0x05
+#define ATA_REG_HDDEVSEL 0x06
+#define ATA_REG_COMMAND 0x07
+#define ATA_REG_STATUS 0x07
+#define ATA_REG_SEC_COUNT1 0x08
+#define ATA_REG_LBA3 0x09
+#define ATA_REG_LBA4 0x0A
+#define ATA_REG_LBA5 0x0B
+#define ATA_REG_CONTROL 0x0C
+#define ATA_REG_ALT_STATUS 0x0C
+#define ATA_REG_DEV_ADDRESS 0x0D
+
+#define ATA_PRIMARY_IO 0x1F0
+#define ATA_SECONDARY_IO 0x170
+#define ATA_PRIMARY_DCR_AS 0x3F6
+#define ATA_SECONDARY_DCR_AS 0x376
+
+// Irq
+#define ATA_PRIMARY_IRQ 14
+#define ATA_SECONDARY_IRQ 15
+
+// Channels
+#define ATA_PRIMARY 0x00
+#define ATA_SECONDARY 0x01
+
+// IO Direction
+#define ATA_READ 0x00
+#define ATA_WRITE 0x013
+
+#define ATA_PRIMARY_SEL 0xA0
+#define ATA_SECONDARY_SEL 0xB0
+
+// ATA Helpers
+#define ATA_ADDRESS1(x) (x + 3)
+#define ATA_ADDRESS2(x) (x + 4)
+#define ATA_ADDRESS3(x) (x + 5)
+#define ATA_COMMAND(x) (x + 7)
+
+Boolean ATAInitDriver(UInt8 bus, UInt8 drive);
+Void ATAWait(UInt16 IO);
+UInt16 ATAReadLba(UInt32 lba, UInt8 bus, Boolean master);
+Void ATAWriteLba(UInt16 byte, UInt32 lba, UInt8 bus, Boolean master);
+Boolean ATAIsDetected(Void); \ No newline at end of file
diff --git a/newBoot/Source/Arch/AMD64/BIOSAllocApi.inc b/newBoot/Source/Arch/AMD64/BIOSAllocApi.inc
new file mode 100644
index 00000000..5b007434
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/BIOSAllocApi.inc
@@ -0,0 +1,40 @@
+;; COPYRIGHT Mahrouss Logic, all rights reserved
+
+bits 32
+
+[global __BIOSLoadRegister]
+[global __BIOSAlloc]
+
+__BIOSLoadRegister:
+ cmp [ebp - 4], 0
+ jmp __LoadGDT
+ ret
+__LoadGDT:
+ lgdt [ebp - 8]
+ ret
+
+;; This memory resides in the BIOS Memory Region BMR (0x9000-0x9000 + 4096)
+;; It contains bootloader data.
+
+__BIOSAlloc:
+ push ebp
+ mov ebp, esp
+ mov eax, __bios_lookup_table
+__BIOSAllocLoop:
+ cmp eax, __end_bios_lookup_table
+ jne __BIOSAllocDone
+ add eax, 4
+ jmp $
+__BIOSAllocDone:
+ cmp eax, 0
+ je __BIOSAllocLoop
+ add esp, 12
+ mov esp, ebp
+ pop ebp
+ ret
+
+;; Allocation table.
+
+__bios_lookup_table:
+ resb 8096 * 4
+__end_bios_lookup_table: \ No newline at end of file
diff --git a/newBoot/Source/Arch/AMD64/BIOSApiGdt.inc b/newBoot/Source/Arch/AMD64/BIOSApiGdt.inc
new file mode 100644
index 00000000..be7a97e3
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/BIOSApiGdt.inc
@@ -0,0 +1,36 @@
+[BITS 32]
+
+NewBootGdtRegister:
+ dw NewBootGdtEnd - NewBootGdt - 1
+ dq NewBootGdt
+
+[BITS 32]
+
+NewBootGdt:
+ ;; Entry 0x0: Null descriptor
+ dd 0x0
+ dd 0x0
+ ;; Entry 0x8: Code segment
+NewBootGdtCode:
+ dw 0xffff ; Limit
+ dw 0x0000 ; Base 15:00
+ db 0x00 ; Base 23:16
+ dw 0xcf9a ; Flags / Limit / Type [F,L,F,Type]
+ db 0x00 ; Base 32:24
+ ;; Entry 0x10: Data segment
+NewBootGdtData:
+ dw 0xffff ; Limit
+ dw 0x0000 ; Base 15:00
+ db 0x00 ; Base 23:16
+ dw 0xcf92 ; Flags / Limit / Type [F,L,F,Type]
+ db 0x00 ;Base 32:24
+ ;; Entry 0x18: GS Data segment
+ dw 0x0100 ; Limit
+ dw 0x1000 ; Base 15:00
+ db 0x00 ; Base 23:16
+ dw 0x4092 ; Flags / Limit / Type [F,L,F,Type]
+ db 0x00 ; Base 32:24
+NewBootGdtEnd:
+
+NB_CODE: db 0x8
+NB_DATA: db 0x10 \ No newline at end of file
diff --git a/newBoot/Source/Arch/AMD64/BIOSRuntime.cxx b/newBoot/Source/Arch/AMD64/BIOSRuntime.cxx
new file mode 100644
index 00000000..b8a95560
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/BIOSRuntime.cxx
@@ -0,0 +1,8 @@
+/*
+* Copyright Mahrouss Logic, all rights reserved
+*/
+
+#include <BootKit/Boot.hpp>
+#include "ATA.hxx"
+
+extern "C" char __STACK[4096] = { 0 };
diff --git a/newBoot/Source/Arch/AMD64/BIOSRuntime0.asm b/newBoot/Source/Arch/AMD64/BIOSRuntime0.asm
new file mode 100644
index 00000000..5b5a6338
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/BIOSRuntime0.asm
@@ -0,0 +1,50 @@
+;; Copyright Mahrouss Logic, all rights reserved
+
+extern __STACK
+global NBRuntimeZero
+
+bits 16
+
+NBRuntimeZero:
+ cli
+
+ lgdt [NewBootGdtRegister]
+
+ mov ebx, cr0
+ or ebx, 1
+ mov cr0, ebx
+
+ jmp 0x8:NBProtectedMode
+
+%include "BIOSApiGdt.inc"
+
+[bits 32]
+
+NBMasterPartitionTable:
+ resb 32
+ resw 1
+ resw 1
+ resw 1
+ resb 211
+NBMasterPartitionTableEnd:
+
+NBProtectedMode:
+ mov ax, 0x10 ; 0x10 is a stand-in for your data segment
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ mov ss, ax
+
+ mov esp, __STACK
+ jmp 0x8000000
+
+NBLoopOne:
+ cli
+ hlt
+ jmp $
+
+NBMasterBootRecord:
+ times 510 - ($-$$) db 0
+ dw 0xAA55
+NBEndMasterBootRecord: \ No newline at end of file
diff --git a/newBoot/Source/Arch/AMD64/BootAMD64.cxx b/newBoot/Source/Arch/AMD64/BootAMD64.cxx
new file mode 100644
index 00000000..d25d4cf1
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/BootAMD64.cxx
@@ -0,0 +1,60 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <BootKit/Boot.hpp>
+
+#define kVGABaseAddress 0xb8000
+
+long long int BStrLen(const char* ptr)
+{
+ long long int cnt = 0;
+ while (*ptr != 0)
+ {
+ ++ptr;
+ ++cnt;
+ }
+
+ return cnt;
+}
+
+void BTextWriter::WriteString(
+ const char* str,
+ unsigned char forecolour,
+ unsigned char backcolour,
+ int x,
+ int y)
+{
+ if (*str == 0 ||
+ !str)
+ return;
+
+ for (SizeT idx = 0; idx < BStrLen(str); ++idx)
+ {
+ this->WriteCharacter(str[idx], forecolour, backcolour, x, y);
+ ++x;
+ }
+}
+
+void BTextWriter::WriteCharacter(
+ char c,
+ unsigned char forecolour,
+ unsigned char backcolour,
+ int x,
+ int y)
+{
+ UInt16 attrib = (backcolour << 4) | (forecolour & 0x0F);
+
+ // Video Graphics Array
+ // Reads at kVGABaseAddress
+ // Decodes UInt16, gets attributes (back colour, fore colour)
+ // Gets character, send it to video display with according colour in the registry.
+
+ fWhere = (volatile UInt16*)kVGABaseAddress + (y * 80 + x);
+ *fWhere = c | (attrib << 8);
+}
diff --git a/newBoot/Source/Arch/AMD64/EFIApi.hxx b/newBoot/Source/Arch/AMD64/EFIApi.hxx
new file mode 100644
index 00000000..1f779b57
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/EFIApi.hxx
@@ -0,0 +1,25 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <efi.h>
+#include <efilib.h>
+
+/// @brief auto-mount and boots from a bootable drive.
+/// does not return on success.
+void newboot_mount_drive(const char* name);
+void newboot_boot_file(const char* path);
+
+/// @brief initializes xpm library.
+void newboot_init_xpm(void);
+
+/// @brief frees the xpm library, called when newboot_auto_mount/newboot_boot_file
+/// succeeds.
+void newboot_fini_xpm(void);
diff --git a/newBoot/Source/Arch/AMD64/EFIApiCrt0.cxx b/newBoot/Source/Arch/AMD64/EFIApiCrt0.cxx
new file mode 100644
index 00000000..45fa2937
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/EFIApiCrt0.cxx
@@ -0,0 +1,33 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include "EFIApi.hxx"
+
+#define main efi_main
+
+typedef EFI_STATUS(*EfiMainType)(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable);
+
+EFI_STATUS main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
+{
+ InitializeLib(ImageHandle, SystemTable);
+ Print(L"newBoot: Booting from XPM...\r\n");
+
+ newboot_init_xpm();
+
+ //! these two should execute a program if any on it.
+ newboot_mount_drive("xpm:///system/");
+ newboot_mount_drive("xpm:///efi/");
+
+ newboot_fini_xpm();
+
+ Print(L"newBoot: No auto-mount found.\r\n");
+
+ return EFI_LOAD_ERROR;
+}
+
diff --git a/newBoot/Source/Arch/AMD64/makefile b/newBoot/Source/Arch/AMD64/makefile
new file mode 100644
index 00000000..fb4b0910
--- /dev/null
+++ b/newBoot/Source/Arch/AMD64/makefile
@@ -0,0 +1,32 @@
+ASM = nasm
+
+# The kernel entrypoint
+ENTRY = NBRuntimeZero
+
+# Where the text segment is.
+TEXT = 0x7c00
+
+# we want a flat binary
+FMT = binary
+
+ASMFLAGS = -f elf64
+
+KERNEL = hBoot.bin
+ATAMOD = ATA.bin
+
+LD = x86_64-elf-ld
+CC = x86_64-elf-gcc
+CCFLAGS = -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I./ -I../../../ -I$(HOME)/hCore/
+
+.PHONY: build-crt0-bios
+build-crt0-bios:
+ $(CC) $(CCFLAGS) BIOSRuntime.cxx
+ $(CC) $(CCFLAGS) ATA.cxx
+ $(ASM) $(ASMFLAGS) BIOSRuntime0.asm
+
+ $(LD) --oformat $(FMT) ATA.o -o $(ATAMOD)
+ $(LD) -e $(ENTRY) -Ttext $(TEXT) --oformat $(FMT) BIOSRuntime.o BIOSRuntime0.o -o $(KERNEL)
+
+.PHONY: all
+all: build-crt0-bios
+ @echo "Done (CRT-0)" \ No newline at end of file
diff --git a/newBoot/Source/Arch/NewCPU/Crt0.asm b/newBoot/Source/Arch/NewCPU/Crt0.asm
new file mode 100644
index 00000000..c918f5c1
--- /dev/null
+++ b/newBoot/Source/Arch/NewCPU/Crt0.asm
@@ -0,0 +1,29 @@
+; =====================
+;
+; newBoot (c) Mahrouss Logic.
+;
+; =====================
+
+; This file is meant to be for ARC
+
+extern __AppMain
+
+__probe_hardware_threads:
+ lea 0x8100000 ; same as before, this alters the rr.
+ ret
+
+__init_hardware_threads:
+ lea 0x8000000 ; this alters return register, do not touch it.
+ ret
+
+__start:
+ jmp __probe_hardware_threads ; Probe and register these threads.
+ jmp __init_hardware_threads ; Setup, and hang any threads.
+ jmp __AppMain
+L0:
+ spi ; stop process interrupt
+ hlt
+ jmp L0
+
+;; put this at the end, XPM header.
+%include "XPM.inc" \ No newline at end of file
diff --git a/newBoot/Source/Arch/NewCPU/XPM.inc b/newBoot/Source/Arch/NewCPU/XPM.inc
new file mode 100644
index 00000000..ac590456
--- /dev/null
+++ b/newBoot/Source/Arch/NewCPU/XPM.inc
@@ -0,0 +1,35 @@
+;*
+; * ========================================================
+; *
+; * newBoot
+; * Copyright Mahrouss Logic, all rights reserved.
+; *
+; * ========================================================
+; *
+
+;; Root directory
+
+kBootBlockIdent: db "XPMNC", 0
+kBootBlockMagic: db "bootloader", 0
+kBootBlockGUID: db "C218439A-5939-4C9D-82AC-ADED46E9243C", 0
+kBootBlockVersion: dw 1
+kBootBlockNumBlocks: dw 1
+kBootBlockSectorSz: dw 4096
+kBootBlockSectorStart: dw 512
+
+;; Boot directory
+
+kPartBlockName: db "bootloader_exec", 0
+kPartBlockMagic: dw 0xEDAD
+kPartBlockSectorEnd: dw 0
+kPartBlockSectorStart: dw 1024
+kPartBlockSize: dw 0
+kPartBlockPartType: dw 1
+kPartBlockVer: dw 1
+kPartBlockFs: db "Files32", 0
+
+kPartBlockReserved1: dq 0xFFFF
+kPartBlockReserved2: dq 0xFFFF
+kPartBlockReserved3: dq 0xFFFF
+
+;; End of directory
diff --git a/newBoot/Source/BootNotes.txt b/newBoot/Source/BootNotes.txt
new file mode 100644
index 00000000..e09e9cce
--- /dev/null
+++ b/newBoot/Source/BootNotes.txt
@@ -0,0 +1,9 @@
+bootloader roadmap:
+
+- Rom is being mapped.
+- Move boot code to link address (8M)
+- Decompress kernel using newboot_decompress_pef()
+- Find start image.
+- Run image at 8M page zero.
+
+- Amlal
diff --git a/newBoot/Source/FSKit/.hgkeep b/newBoot/Source/FSKit/.hgkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/newBoot/Source/FSKit/.hgkeep
diff --git a/newBoot/Source/FSKit/FileType.hxx b/newBoot/Source/FSKit/FileType.hxx
new file mode 100644
index 00000000..26beb114
--- /dev/null
+++ b/newBoot/Source/FSKit/FileType.hxx
@@ -0,0 +1,30 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+// @brief this file purpose is to read/write files.
+
+#include <NewKit/Defines.hpp>
+
+/// \brief File buffer class
+/// \tparam _Manager The disk manager
+template <typename _Manager>
+class FileType
+{
+public:
+ hCore::SizeT DiskId{ 0 };
+ hCore::VoidPtr DiskSpace{ nullptr };
+ hCore::SizeT DiskSize{ 0 };
+ hCore::Int32 DiskError{ 0 };
+
+ FileType* Read(const char* path) { return _Manager::Read(path); }
+ FileType* Write(FileType* path) { return _Manager::Write(path); }
+
+}; \ No newline at end of file
diff --git a/newBoot/Source/FSKit/Files32.cxx b/newBoot/Source/FSKit/Files32.cxx
new file mode 100644
index 00000000..e7ba96f9
--- /dev/null
+++ b/newBoot/Source/FSKit/Files32.cxx
@@ -0,0 +1,10 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include "Files32.hxx"
diff --git a/newBoot/Source/FSKit/Files32.hxx b/newBoot/Source/FSKit/Files32.hxx
new file mode 100644
index 00000000..9e940f6d
--- /dev/null
+++ b/newBoot/Source/FSKit/Files32.hxx
@@ -0,0 +1,36 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+struct Files32FileHdr
+{
+ char Filename[32];
+ char Ext[3];
+ char Attr;
+ char Case;
+ char CreateMs;
+ unsigned short Create;
+ unsigned short CreateDate;
+ unsigned short LastAccess;
+ unsigned short Timestamp;
+ unsigned short Datestamp;
+ unsigned short StartLba;
+ unsigned int SizeFile;
+};
+
+#define kFilesR 0x01 /* read-only */
+#define kFilesH 0x02 /* hidden */
+#define kFilesS 0x04 /* system */
+#define kFilesL 0x08 /* volume label */
+#define kFilesD 0x10 /* directory */
+#define kFilesZ 0x20 /* archive */
+
+// @brief Array of unused bits.
+#define kFilesU { 0x40, 0x80 }
diff --git a/newBoot/Source/FSKit/MPT.hxx b/newBoot/Source/FSKit/MPT.hxx
new file mode 100644
index 00000000..e2a548e4
--- /dev/null
+++ b/newBoot/Source/FSKit/MPT.hxx
@@ -0,0 +1,29 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+// @brief 255 size partiton header.
+// we use that to gather information about this hard drive.
+
+struct MasterPartitionTable final
+{
+ char fPartName[32];
+ int fPartType;
+ int fPartSectorSz;
+ int fPartSectorCnt;
+ char fReserved[211];
+};
+
+enum
+{
+ kPartEfi = 'efi',
+ kPartXpm = 'xpm',
+ kPartEbr = 'ebr',
+}; \ No newline at end of file
diff --git a/newBoot/Source/Start.cxx b/newBoot/Source/Start.cxx
new file mode 100644
index 00000000..462708ca
--- /dev/null
+++ b/newBoot/Source/Start.cxx
@@ -0,0 +1,19 @@
+/*
+ * ========================================================
+ *
+ * newBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <BootKit/Boot.hpp>
+
+extern "C" void __AppMain(void)
+{
+ BTextWriter writer;
+ writer.WriteString("Starting hCore...", kBlack, kWhite, 0, 0);
+
+ const char* args[] = { "/hCore.bin" };
+ const char* envp[] = { "/" };
+}
diff --git a/newBoot/Source/makefile b/newBoot/Source/makefile
new file mode 100644
index 00000000..81bb2096
--- /dev/null
+++ b/newBoot/Source/makefile
@@ -0,0 +1,23 @@
+CC=fcc
+CCFLAGS=-I ../ -ffreestanding -nostdlib
+ASM=fasm
+ASMFLAGS=/ARC /PEF
+
+.PHONY: arch-arc
+arch-arc:
+ ${CC} ${CCFLAGS} Boot.cpp Start.cpp -c
+ ${ASM} ${ASMFLAGS} Arch/ARC/XPM.asm
+ ${ASM} ${ASMFLAGS} Arch/ARC/Crt0.asm
+
+CC_GNU=x86_64-elf-gcc
+LD_GNU=x86_64-elf-ld
+FLAG_GNU=-I../ -I../../../efiSDK/inc -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__hCore__ -I./ -I$(HOME)/
+
+.PHONY: arch-amd64
+arch-amd64:
+ $(CC_GNU) $(FLAG_GNU) Arch/AMD64/BootAMD64.cxx *.cxx
+ $(LD_GNU) *.o -e __AppMain -Ttext 0x000 --oformat binary -o BootloaderStage2.bin
+
+.PHONY: clean
+clean:
+ rm -f *.o
diff --git a/newBoot/cxxKitModule/__cxxkit_unwind.cxx b/newBoot/cxxKitModule/__cxxkit_unwind.cxx
new file mode 100644
index 00000000..2935e9bf
--- /dev/null
+++ b/newBoot/cxxKitModule/__cxxkit_unwind.cxx
@@ -0,0 +1,11 @@
+namespace cxxkit
+{
+ ///! @brief C++ ABI pushes
+ ///! finis array (r1)
+ ///! n of finis (r2)
+ void __unwind(void(**finis)(void), int cnt)
+ {
+ for (int i = 0; i < cnt; ++i)
+ (finis[i])();
+ }
+}
diff --git a/newBoot/cxxKitModule/manifest.json b/newBoot/cxxKitModule/manifest.json
new file mode 100644
index 00000000..42b5d166
--- /dev/null
+++ b/newBoot/cxxKitModule/manifest.json
@@ -0,0 +1,3 @@
+{
+ "pluginName": "C++Kit"
+} \ No newline at end of file
diff --git a/newBoot/netBootModule/.hgkeep b/newBoot/netBootModule/.hgkeep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/newBoot/netBootModule/.hgkeep
diff --git a/newBoot/netBootModule/manifest.json b/newBoot/netBootModule/manifest.json
new file mode 100644
index 00000000..ffe5873e
--- /dev/null
+++ b/newBoot/netBootModule/manifest.json
@@ -0,0 +1,4 @@
+{
+ "pluginName": "NetBoot",
+ "description": "Use NetBoot to boot your phone from the network."
+} \ No newline at end of file
diff --git a/newBoot/netBootModule/module.cxx b/newBoot/netBootModule/module.cxx
new file mode 100644
index 00000000..286d9c50
--- /dev/null
+++ b/newBoot/netBootModule/module.cxx
@@ -0,0 +1,13 @@
+/*
+ * ========================================================
+ *
+ * NetBoot
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+extern "C" void __dmain(const char* ip, long iplen)
+{
+
+}