summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-05 15:50:15 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-05 15:50:15 +0100
commite1d27e30997b45acf9dade9c03278b02f1021e98 (patch)
treed0d291a43e8dcd0f664f552ad017555447a3d7d8
parentb3666c011a512d7758a8c095872241e8f3964850 (diff)
Bootloader: can load files now!
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx4
-rw-r--r--Private/NewBoot/Source/Entrypoint.cxx12
-rw-r--r--Private/NewBoot/Source/FileReader.cxx70
-rw-r--r--Private/NewKit/Macros.hpp8
4 files changed, 51 insertions, 43 deletions
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index c768ca9c..09ce712a 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -61,10 +61,10 @@ HCore::SizeT BSetMem(CharacterType *src, const CharacterType byte,
*/
class BFileReader final {
public:
- explicit BFileReader(const CharacterType *path);
+ explicit BFileReader(const CharacterType *path, EfiHandlePtr ImageHandle);
~BFileReader();
- Void ReadAll(EfiHandlePtr ImageHandle);
+ Void ReadAll();
enum {
kOperationOkay,
diff --git a/Private/NewBoot/Source/Entrypoint.cxx b/Private/NewBoot/Source/Entrypoint.cxx
index 2ef057ba..2fdf3d0b 100644
--- a/Private/NewBoot/Source/Entrypoint.cxx
+++ b/Private/NewBoot/Source/Entrypoint.cxx
@@ -25,16 +25,20 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
.WriteString(SystemTable->FirmwareVendor)
.WriteString(L"\r\n");
- BFileReader img(L"HCOREKRNL.EXE");
- img.ReadAll(ImageHandle);
+ BFileReader img(L"HCOREKRNL.EXE", ImageHandle);
- VoidPtr blob = img.Blob();
+ UInt8 buf[1024] = {0};
+ UInt32 bufSz = 1024;
- if (!blob) {
+ img.File()->Read(img.File(), &bufSz, buf);
+
+ if (buf[0] != kMagMz0 || buf[1] != kMagMz1) {
EFI::RaiseHardError(L"HCoreLdr_NoBlob", L"No Such blob.");
return kEfiFail;
}
+ writer.WriteString(L"MZ header found... Loading HCOREKRNL.EXE...\r\n");
+
UInt64 MapKey = 0;
EFI::ExitBootServices(MapKey, ImageHandle);
diff --git a/Private/NewBoot/Source/FileReader.cxx b/Private/NewBoot/Source/FileReader.cxx
index 8ee59237..54e59dde 100644
--- a/Private/NewBoot/Source/FileReader.cxx
+++ b/Private/NewBoot/Source/FileReader.cxx
@@ -17,6 +17,7 @@
#include <EFIKit/Handover.hxx>
#include "EFIKit/EFI.hxx"
+#include "NewKit/Defines.hpp"
#include "NewKit/Macros.hpp"
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -30,7 +31,7 @@
/***
@brief File Reader constructor.
*/
-BFileReader::BFileReader(const CharacterType* path) {
+BFileReader::BFileReader(const CharacterType* path, EfiHandlePtr ImageHandle) {
if (path != nullptr) {
SizeT index = 0UL;
for (; path[index] != L'\0'; ++index) {
@@ -39,29 +40,6 @@ BFileReader::BFileReader(const CharacterType* path) {
mPath[index] = 0;
}
-}
-
-BFileReader::~BFileReader() {
- if (this->mBlob) {
- BS->FreePool(this->mBlob);
- }
-
- if (this->mFile) {
- this->mFile->Close(this->mFile);
- this->mFile = nullptr;
- }
-
- BSetMem(this->mPath, 0, kPathLen);
-}
-
-/**
- @brief this reads all of the buffer.
- @param ImageHandle used internally.
-*/
-Void BFileReader::ReadAll(EfiHandlePtr ImageHandle) {
- mWriter.WriteString(L"HCoreLdr: ReadAll: ")
- .WriteString(mPath)
- .WriteString(L"\r\n");
/// Load protocols with their GUIDs.
@@ -108,27 +86,53 @@ Void BFileReader::ReadAll(EfiHandlePtr ImageHandle) {
rootFs->Close(rootFs);
- /// File FAT info.
+ mSizeFile = 0;
+ mFile = kernelFile;
+ mErrorCode = kNotSupported;
+}
+
+BFileReader::~BFileReader() {
+ if (this->mBlob) {
+ BS->FreePool(this->mBlob);
+ }
+
+ if (this->mFile) {
+ this->mFile->Close(this->mFile);
+ this->mFile = nullptr;
+ }
+
+ BSetMem(this->mPath, 0, kPathLen);
+}
+
+/**
+ @brief this reads all of the buffer.
+ @param ImageHandle used internally.
+*/
+Void BFileReader::ReadAll() {
+ mWriter.WriteString(L"HCoreLdr: ReadAll: ")
+ .WriteString(mPath)
+ .WriteString(L"\r\n");
+
+ mWriter.WriteString(L"HCoreLdr: ReadAll: FETCH: ")
+ .WriteString(mPath)
+ .WriteString(L"\r\n");
/// Allocate Handover page.
- VoidPtr blob = (VoidPtr)kHandoverStartKernel;
+ UInt8* blob = (UInt8*)kHandoverStartKernel;
if (BS->AllocatePages(AllocateAnyPages, EfiLoaderData, 1,
(EfiPhysicalAddress*)&blob) != kEfiOk) {
EFI::RaiseHardError(L"HCoreLdr_PageError", L"Allocation error.");
}
- mSizeFile = KIB(kMaxReadSize);
- mFile = kernelFile;
- mErrorCode = kOperationOkay;
mBlob = blob;
+ mSizeFile = KIB(kMaxReadSize);
- mWriter.WriteString(L"HCoreLdr: ReadAll: FETCH: ")
- .WriteString(mPath)
- .WriteString(L"\r\n");
+ if (mFile->Read(mFile, &mSizeFile, mBlob) != kEfiOk) return;
- mFile->Read(mFile, &mSizeFile, mBlob);
+ mSizeFile = KIB(kMaxReadSize);
+ mErrorCode = kOperationOkay;
mWriter.WriteString(L"HCoreLdr: ReadAll: OK: ")
.WriteString(mPath)
diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp
index 8b974fc2..b717dee8 100644
--- a/Private/NewKit/Macros.hpp
+++ b/Private/NewKit/Macros.hpp
@@ -10,19 +10,19 @@
#pragma once
#ifndef KIB
-#define KIB(X) ((X) * 1024)
+#define KIB(X) ((X) << 10)
#endif
#ifndef MIB
-#define MIB(X) (KIB(X) * 1024)
+#define MIB(X) (KIB(X) << 20)
#endif
#ifndef GIB
-#define GIB(X) (MIB(X) * 1024)
+#define GIB(X) (MIB(X) << 30)
#endif
#ifndef TIB
-#define TIB(X) (GIB(X) * 1024)
+#define TIB(X) (GIB(X) << 40)
#endif
#ifndef ARRAY_SIZE