summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-04 17:07:33 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-04 17:07:33 +0100
commit9fe3b6e1e2447a11644307e83df2b109b24fe0d1 (patch)
treed6eafa0dee897572554d4519b1a9cd878591254c /Private/NewBoot/Source
parenta3d92ea68a74ef3cc3d3c9a34540754869e4d014 (diff)
HCR-11: Support for EFI GOP and SFP.
- SFP stands for Simple Filesystem Protocol, it's always reading through the ESP. - Add GOP for UI code. - Did also patch kernel Virtual Memory code. Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
-rw-r--r--Private/NewBoot/Source/Entrypoint.cxx36
-rw-r--r--Private/NewBoot/Source/FileReader.cxx71
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx10
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm8
-rw-r--r--Private/NewBoot/Source/makefile3
5 files changed, 45 insertions, 83 deletions
diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx
index 7026da4d..bdcfab4d 100644
--- a/Private/NewBoot/Source/Entrypoint.cxx
+++ b/Private/NewBoot/Source/Entrypoint.cxx
@@ -1,10 +1,10 @@
/*
- * ========================================================
+ * ========================================================
*
* NewBoot
* Copyright Mahrouss Logic, all rights reserved.
*
- * ========================================================
+ * ========================================================
*/
#define __BOOTLOADER__ 1
@@ -14,25 +14,10 @@
#include <KernelKit/PE.hpp>
#include <NewKit/Ref.hpp>
-STATIC Void InitGfx() noexcept {
- EfiGUID gopGuid = EfiGUID(EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID);
- EfiGraphicsOutputProtocol* gop = nullptr;
-
- BS->LocateProtocol(&gopGuid, nullptr, (void**)&gop);
-
- for (int w = 0; w < gop->Mode->Info->VerticalResolution; ++w) {
- for (int h = 0; h < gop->Mode->Info->HorizontalResolution; ++h) {
- *((UInt32*)(gop->Mode->FrameBufferBase +
- 4 * gop->Mode->Info->PixelsPerScanLine * w + 4 * h)) =
- RGB(10, 10, 10);
- }
- }
-}
-
EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
InitEFI(SystemTable);
- InitGfx();
+ InitQT();
BTextWriter writer;
@@ -44,21 +29,14 @@ EFI_EXTERN_C Int EfiMain(EfiHandlePtr ImageHandle,
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
- UInt64 mapKey = 0;
-
BFileReader img(L"\\EFI\\BOOT\\HCOREKRNL.EXE");
+ img.Fetch(ImageHandle);
- SizeT imageSz = 0;
-
- PEImagePtr blob = (PEImagePtr)img.Fetch(ImageHandle, imageSz);
-
- if (!blob)
- EFI::RaiseHardError(L"HCoreLdr_NoSuchKernel",
- L"Couldn't find HCoreKrnl.exe!");
+ VoidPtr blob = img.Blob();
- writer.WriteString(L"HCoreLdr: Running HCoreKrnl.exe...\r\n");
+ UInt64 MapKey = 0;
- EFI::ExitBootServices(mapKey, ImageHandle);
+ EFI::ExitBootServices(MapKey, ImageHandle);
EFI::Stop();
return kEfiOk;
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index 8602114f..a66f2c71 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -14,9 +14,7 @@
#include <BootKit/BootKit.hxx>
#include <EFIKit/Api.hxx>
-
-#include "EFIKit/EFI.hxx"
-#include "NewKit/Defines.hpp"
+#include <EFIKit/Handover.hxx>
////////////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -50,7 +48,7 @@ BFileReader::~BFileReader() {
@brief this reads all of the buffer.
@param ImageHandle used internally.
*/
-HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) {
+Void BFileReader::Fetch(EfiHandlePtr ImageHandle) {
mWriter.WriteString(L"HCoreLdr: Fetch-File: ")
.WriteString(mPath)
.WriteString(L"\r\n");
@@ -75,7 +73,7 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) {
mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Protocol")
.WriteString(L"\r\n");
this->mErrorCode = kNotSupported;
- return nullptr;
+ return;
}
/// Start doing disk I/O
@@ -84,7 +82,7 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) {
mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: No-Such-Volume")
.WriteString(L"\r\n");
this->mErrorCode = kNotSupported;
- return nullptr;
+ return;
}
/// Open kernel.
@@ -97,14 +95,14 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) {
.WriteString(mPath)
.WriteString(L"\r\n");
this->mErrorCode = kNotSupported;
- return nullptr;
+ return;
}
if (kernelFile->Revision < EFI_FILE_PROTOCOL_REVISION2) {
mWriter.WriteString(L"HCoreLdr: Fetch-Protocol: Invalid-Revision: ")
.WriteString(mPath)
.WriteString(L"\r\n");
- return nullptr;
+ return;
}
/// File FAT info.
@@ -120,64 +118,31 @@ HCore::VoidPtr BFileReader::Fetch(EfiHandlePtr ImageHandle, SizeT& imageSz) {
.WriteString(mPath)
.WriteString(L"\r\n");
this->mErrorCode = kNotSupported;
- return nullptr;
+ return;
}
mWriter.WriteString(L"HCoreLdr: Fetch-Info: In-Progress...")
.WriteString(L"\r\n");
- VoidPtr blob = nullptr;
+ VoidPtr blob = (VoidPtr)kHandoverStartKernel;
mWriter.WriteString(L"HCoreLdr: Fetch-Info: OK...").WriteString(L"\r\n");
- UInt32* sz = nullptr;
-
- if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&sz) !=
- kEfiOk) {
- mWriter
- .WriteString(
- L"HCoreLdr: Fetch: Failed to call AllocatePool "
- L"correctly!")
- .WriteString(L"\r\n");
-
- kernelFile->Close(kernelFile);
-
- return nullptr;
- }
-
- *sz = info.FileSize;
- imageSz = *sz;
+ UInt32 sz = info.FileSize;
- if (BS->AllocatePool(EfiLoaderData, *sz, (VoidPtr*)&blob) != kEfiOk) {
- mWriter
- .WriteString(
- L"HCoreLdr: Fetch: Failed to call AllocatePool "
- L"correctly!")
- .WriteString(L"\r\n");
-
- kernelFile->Close(kernelFile);
-
- return nullptr;
- }
+ BSetMem((CharacterType*)blob, 0, sz);
- BSetMem((CharacterType*)blob, 0, *sz);
-
- mWriter.WriteString(L"HCoreLdr: Fetch-File: In-Progress...")
- .WriteString(info.FileName)
- .WriteString(L"\r\n");
-
- auto resultEfiRead = kernelFile->Read(kernelFile, sz, blob);
+ auto resultEfiRead = kernelFile->Read(kernelFile, &sz, blob);
kernelFile->Close(kernelFile);
- if (resultEfiRead == kEfiOk)
- mWriter.WriteString(L"HCoreLdr: Fetch-File: OK").WriteString(L"\r\n");
- else
- return nullptr;
+ if (resultEfiRead != kEfiOk) return;
+
+ mCached = true;
+ mErrorCode = kOperationOkay;
- this->mCached = true;
- this->mErrorCode = kOperationOkay;
+ mBlob = blob;
- this->mBlob = blob;
+ // We are done!
- return blob;
+ mWriter.WriteString(L"HCoreLdr: Fetch: OK.").WriteString(L"\r\n");
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
index 20dd3125..5a4a2445 100644
--- a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
@@ -31,3 +31,13 @@ extern "C" void rt_std() { asm volatile("std"); }
/// @brief Stack Checker, leave empty.
extern "C" void ___chkstk_ms(void) {}
+
+namespace EFI {
+Void Stop() noexcept {
+ while (true) {
+ rt_cli();
+ rt_halt();
+ }
+}
+
+} // namespace EFI
diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm b/Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm
new file mode 100644
index 00000000..46928cf7
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-VirtualMemory.asm
@@ -0,0 +1,8 @@
+bits 64
+global __cr3
+
+section .text
+
+__cr3:
+ mov rax, cr3
+ ret
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 05d6a9ab..cf6bb579 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -17,6 +17,7 @@ invalid-recipe:
.PHONY: bootloader-amd64
bootloader-amd64:
$(CC_GNU) $(FLAG_GNU) HEL/AMD64/*.cxx *.cxx
+ $(ASM) $(FLAG_ASM) HEl/AMD64/AMD64-VirtualMemory.asm
$(LD_GNU) *.o HEL/AMD64/*.obj -e efi_main -filealign:16 -shared --subsystem=10 -ffreestanding -o HCoreLdr.exe
cp HCoreLdr.exe CDROM/EFI/BOOT/BOOTX64.EFI
cp ../../HCoreKrnl.exe CDROM/EFI/BOOT/HCOREKRNL.EXE
@@ -28,7 +29,7 @@ make-disk:
.PHONY: run-efi-debug
run-efi-debug:
wget https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd
- qemu-system-x86_64 -m 8G -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -d int
+ qemu-system-x86_64 -m 8G -M q35 -bios OVMF.fd -drive file=os.epm,index=0,if=ide,format=qcow2 -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio
.PHONY: clean
clean: