summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-25 16:12:36 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-25 16:12:36 +0100
commit2bd2e28868d50a2f3ced8b1bfea68216ed35622a (patch)
tree4bf376821d13f005d72cbf5feca5cb1f18ae60cd /Private/NewBoot
parent9be51d883414584db0926ab854d6026e1785048b (diff)
WiP: See below.
- Reworking bootloader to adapt if kernel and programs are already here or not for HCoreLdr. - Working on IDT support for HCoreKrnl. - Add Award and Mahrouss Logic logo in recovery-mode for HCoreKrnl. - Working on reading .NewBoot section in HCoreLdr. Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot')
-rw-r--r--Private/NewBoot/Source/BootMain.cxx55
-rw-r--r--Private/NewBoot/Source/CDROM/MAHROUSS/.keep0
-rw-r--r--Private/NewBoot/Source/FileReader.cxx4
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx46
-rw-r--r--Private/NewBoot/Source/bundle.mk34
-rw-r--r--Private/NewBoot/Source/makefile (renamed from Private/NewBoot/Source/standard.mk)6
6 files changed, 26 insertions, 119 deletions
diff --git a/Private/NewBoot/Source/BootMain.cxx b/Private/NewBoot/Source/BootMain.cxx
index fa8eb46c..62639b18 100644
--- a/Private/NewBoot/Source/BootMain.cxx
+++ b/Private/NewBoot/Source/BootMain.cxx
@@ -21,12 +21,10 @@
#error This CPU is unknown.
#endif // ifdef __x86_64__
-#define kHeadersSz \
+#define kBootReadSize \
(sizeof(DosHeader) + sizeof(ExecHeader) + sizeof(ExecOptionalHeader))
-#ifdef __BUNDLE_KERNEL__
-EXTERN_C EFI_API void RuntimeMain(HEL::HandoverInformationHeader* HIH);
-#endif
+EXTERN_C EFI_API void Main(HEL::HandoverInformationHeader* HIH);
EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
@@ -35,11 +33,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
BTextWriter writer;
-#ifdef __BUNDLE_KERNEL__
- writer.WriteString(L"HCoreLite: ");
-#else
writer.WriteString(L"HCoreLdr: ");
-#endif
#ifndef __DEBUG__
@@ -53,27 +47,17 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
const char strDate[] = __DATE__;
-#ifdef __BUNDLE_KERNEL__
- writer.WriteString(L"HCoreLite: Build: ");
-#else
writer.WriteString(L"HCoreLdr: Build: ");
-#endif
for (auto& ch : strDate) writer.WriteCharacter(ch);
-#ifdef __BUNDLE_KERNEL__
- writer.WriteString(L"\r\nHCoreLite: Firmware Vendor: ")
- .WriteString(SystemTable->FirmwareVendor)
- .WriteString(L"\r\n");
-#else
writer.WriteString(L"\r\nHCoreLdr: Firmware Vendor: ")
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
-#endif
BFileReader img(L"HCOREKRNL.DLL", ImageHandle);
- img.Size(kHeadersSz);
+ img.Size(kBootReadSize);
img.ReadAll();
if (img.Error() == BFileReader::kOperationOkay) {
@@ -148,28 +132,29 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
SystemTable->FirmwareVendor,
handoverHdrPtr->f_FirmwareVendorLen);
-#ifdef __BUNDLE_KERNEL__
- handoverHdrPtr->f_Magic = 0x55DDFF;
- handoverHdrPtr->f_Version = 0x1011;
- handoverHdrPtr->f_Bootloader = 0x11; // HCoreLite
+ BFileReader systemIni(L"SYSTEM.INI", ImageHandle);
- writer.WriteString(L"HCoreLite: Exit Boot...").WriteString(L"\r\n");
-#else
- handoverHdrPtr->f_Magic = 0xFF55DD;
- handoverHdrPtr->f_Version = 0x1011;
- handoverHdrPtr->f_Bootloader = 0xDD; // HCoreLdr
+ systemIni.Size(4096);
+ systemIni.ReadAll();
- writer.WriteString(L"HCoreLdr: Exit Boot...").WriteString(L"\r\n");
-#endif
+ bool isIniNotFound = (systemIni.Blob() == nullptr);
EFI::ExitBootServices(MapKey, ImageHandle);
-#ifdef __BUNDLE_KERNEL__
- RuntimeMain(handoverHdrPtr);
-#else
- // Load HCoreKrnl.dll (TODO)
+ if (isIniNotFound) {
+ handoverHdrPtr->f_Magic = 0x55DDFF;
+ handoverHdrPtr->f_Version = 0x1011;
+ handoverHdrPtr->f_Bootloader = 0x11; // Installer
-#endif // ifdef __BUNDLE_KERNEL__
+ Main(handoverHdrPtr);
+
+ } else {
+ handoverHdrPtr->f_Magic = 0xFF55DD;
+ handoverHdrPtr->f_Version = 0x1011;
+ handoverHdrPtr->f_Bootloader = 0xDD; // System present
+
+ // TODO: read .NewBoot section.
+ }
EFI::Stop();
diff --git a/Private/NewBoot/Source/CDROM/MAHROUSS/.keep b/Private/NewBoot/Source/CDROM/MAHROUSS/.keep
deleted file mode 100644
index e69de29b..00000000
--- a/Private/NewBoot/Source/CDROM/MAHROUSS/.keep
+++ /dev/null
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index 193184c4..16197164 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -86,7 +86,7 @@ BFileReader::BFileReader(const CharacterType* path, EfiHandlePtr ImageHandle) {
mSizeFile = 0;
mFile = kernelFile;
- mErrorCode = kNotSupported;
+ mErrorCode = kOperationOkay;
}
BFileReader::~BFileReader() {
@@ -107,6 +107,8 @@ BFileReader::~BFileReader() {
Void BFileReader::ReadAll() {
/// Allocate Handover page.
+ if (this->mErrorCode != kOperationOkay) return;
+
if (mBlob == nullptr) {
UInt8* blob = (UInt8*)hTransferBufferAddress;
diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
deleted file mode 100644
index ff07b4c7..00000000
--- a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ========================================================
- *
- * NewBoot
- * Copyright Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
-
-/*
- *
- * @file Platform.cxx
- * @brief Platform Specific Functions.
- *
- */
-
-#include <BootKit/BootKit.hxx>
-#include <BootKit/Platform.hxx>
-
-#ifndef __BUNDLE_KERNEL__
-
-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"); }
-
-extern "C" void rt_std() { asm volatile("std"); }
-
-/// @brief Stack Checker, leave empty.
-
-extern "C" void ___chkstk_ms(void) {}
-
-#endif
-
-namespace EFI {
-Void Stop() noexcept {
- while (true) {
- rt_cli();
- rt_halt();
- }
-}
-
-} // namespace EFI
diff --git a/Private/NewBoot/Source/bundle.mk b/Private/NewBoot/Source/bundle.mk
deleted file mode 100644
index 23bf570e..00000000
--- a/Private/NewBoot/Source/bundle.mk
+++ /dev/null
@@ -1,34 +0,0 @@
-##################################################
-# ; (C) Mahrouss Logic, 2024, all rights reserved.
-# This is the bootloader makefile.
-##################################################
-
-CC_GNU=x86_64-w64-mingw32-g++
-LD_GNU=x86_64-w64-mingw32-ld
-LD_FLAGS=-e efi_main -shared --subsystem=10 -ffreestanding
-ASM=nasm
-OBJ=$(wildcard *.obj) $(wildcard *.o) $(wildcard ../../Obj/*.obj) $(wildcard HEL/AMD64/*.obj) $(wildcard HEL/AMD64/*.o)
-
-FLAG_ASM=-f win64
-FLAG_GNU=-fshort-wchar -O0 -D__BUNDLE_KERNEL__ -D__DEBUG__ -fPIC -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/
-
-.PHONY: invalid-recipe
-invalid-recipe:
- @echo "invalid-recipe: Use make bootloader-<arch> all instead."
-
-.PHONY: bootloader-amd64
-bootloader-amd64:
- $(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx
- $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm
- $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreKrnl.exe
- cp HCoreKrnl.exe CDROM/EFI/BOOT/BOOTX64.EFI
- cp ../../HCoreKrnl.dll CDROM/HCOREKRNL.DLL
-
-.PHONY: run-efi-amd64
-run-efi-amd64:
- wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
- qemu-system-x86_64 -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -d int
-
-.PHONY: clean
-clean:
- rm -f $(OBJ) HCoreLdr.exe OVMF.fd
diff --git a/Private/NewBoot/Source/standard.mk b/Private/NewBoot/Source/makefile
index 1177a437..0e9cd4d2 100644
--- a/Private/NewBoot/Source/standard.mk
+++ b/Private/NewBoot/Source/makefile
@@ -7,7 +7,7 @@ CC_GNU=x86_64-w64-mingw32-g++
LD_GNU=x86_64-w64-mingw32-ld
LD_FLAGS=-e efi_main -shared --subsystem=10 -ffreestanding
ASM=nasm
-OBJ=$(wildcard *.obj) $(wildcard *.o) $(wildcard HEL/AMD64/*.obj) $(wildcard HEL/AMD64/*.o)
+OBJ=$(wildcard *.obj) $(wildcard *.o) $(wildcard ../../Obj/*.obj) $(wildcard HEL/AMD64/*.obj) $(wildcard HEL/AMD64/*.o)
FLAG_ASM=-f win64
FLAG_GNU=-fshort-wchar -O0 -D__DEBUG__ -fPIC -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -I./ -I$(HOME)/
@@ -20,8 +20,8 @@ invalid-recipe:
bootloader-amd64:
$(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx
$(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm
- $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreLdr.exe
- cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI
+ $(LD_GNU) $(OBJ) $(LD_FLAGS) -o HCoreKrnl.exe
+ cp HCoreKrnl.exe CDROM/EFI/BOOT/BOOTX64.EFI
cp ../../HCoreKrnl.dll CDROM/HCOREKRNL.DLL
.PHONY: run-efi-amd64