summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot
diff options
context:
space:
mode:
Diffstat (limited to 'Private/NewBoot')
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx3
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx59
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx10
3 files changed, 60 insertions, 12 deletions
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index b0dbccd5..bbe2332e 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -15,6 +15,7 @@
#pragma once
#include <BootKit/Arch/ATA.hxx>
+#include <EFIKit/EFI.hxx>
#include <NewKit/Defines.hpp>
using namespace HCore;
@@ -63,7 +64,7 @@ class BFileReader final {
explicit BFileReader(const CharacterType *path);
~BFileReader() = default;
- HCore::VoidPtr ReadAll();
+ HCore::VoidPtr ReadAll(SizeT &size);
enum {
kOperationOkay,
diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
index 600a8fcc..b45e661f 100644
--- a/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
@@ -11,6 +11,9 @@
#include <EFIKit/Api.hxx>
#include <FSKit/NewFS.hxx>
+#include "EFIKit/EFI.hxx"
+#include "NewKit/Macros.hpp"
+
/// bugs 0
/////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -89,7 +92,7 @@ BTextWriter &BTextWriter::WriteCharacter(CharacterType c) {
BFileReader::BFileReader(const CharacterType *path) {
if (path != nullptr) {
SizeT index = 0UL;
- for (; path[index] != L'0'; ++index) {
+ for (; path[index] != L'\0'; ++index) {
mPath[index] = path[index];
}
@@ -99,21 +102,61 @@ BFileReader::BFileReader(const CharacterType *path) {
/**
@brief this reads all of the buffer.
+@param size, new buffer size.
*/
-HCore::VoidPtr BFileReader::ReadAll() {
+HCore::VoidPtr BFileReader::ReadAll(SizeT &size) {
BTextWriter writer;
writer.WriteString(L"*** BFileReader::ReadAll: Reading ")
.WriteString(mPath)
.WriteString(L" *** \r\n");
- EfiFileDevicePathProtocol loadFile{0};
- loadFile.LengthData[0] = 0xFF;
- loadFile.LengthData[1] = 0;
+ EfiHandlePtr handleFile = nullptr;
+ EfiLoadFileProtocol *loadFile = nullptr;
+
+ EfiGUID loadFileGUID = EfiGUID(EFI_LOAD_FILE_PROTOCOL_GUID);
+
+ BS->LocateProtocol(&loadFileGUID, nullptr, (VoidPtr *)&loadFile);
+
+ if (loadFile) {
+ writer.WriteString(L"HCoreLdr: Loading: ")
+ .WriteString(mPath)
+ .WriteString(L"\r\n");
+
+ UInt32 bufSz = KIB(350);
+ VoidPtr buf = nullptr;
+
+ BS->AllocatePool(EfiLoaderCode, bufSz, &buf);
+
+ if (!buf) return nullptr;
- loadFile.Type = kEFIMediaDevicePath;
- loadFile.SubType = 0; // from all drives.
+ EfiFileDevicePathProtocol filePath{0};
+ filePath.Proto.Length[0] = (sizeof(EfiDevicePathProtocol));
+ filePath.Proto.Length[1] = (sizeof(EfiDevicePathProtocol) + kPathLen) >> 8;
- BCopyMem(loadFile.Path, mPath, kPathLen);
+ filePath.Proto.Type = kEFIMediaDevicePath;
+ filePath.Proto.SubType = kEFIMediaDevicePath; // from all drives.
+
+ BCopyMem(filePath.Path, mPath, kPathLen);
+
+ auto err = loadFile->LoadFile(loadFile, &filePath, false, (UInt32 *)&bufSz,
+ (VoidPtr *)&buf);
+
+ size = bufSz;
+
+ if (buf) {
+ writer.WriteString(L"HCoreLdr: Loaded: ")
+ .WriteString(mPath)
+ .WriteString(L"\r\n");
+ } else {
+ writer.WriteString(L"HCoreLdr: Error: ")
+ .WriteString(mPath)
+ .WriteString(L" , EFI-Code: ")
+ .WriteCharacter(err + 48)
+ .WriteString(L"\r\n");
+ }
+
+ return buf;
+ }
return nullptr;
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx
index 256c7feb..7d179e42 100644
--- a/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-Main.cxx
@@ -7,6 +7,7 @@
* ========================================================
*/
+#include "EFIKit/EFI.hxx"
#define __BOOTLOADER__ 1
#include <BootKit/BootKit.hxx>
@@ -26,10 +27,13 @@ EFI_EXTERN_C int EfiMain(EfiHandlePtr ImageHandle,
UInt64 mapKey = 0;
- BFileReader reader(L"\\Root\\System\\HCoreKrnl.exe\0");
- auto blob = reader.ReadAll();
+ BFileReader reader(L"EFI\\BOOT\\HCoreKrnl.exe");
- if (!blob)
+ SizeT sz = 0UL;
+
+ auto blob = reader.ReadAll(sz);
+
+ if (!blob || sz < 1)
KeRuntimeStop(L"HCoreLdr_NoSuchKernel",
L"Couldn't find HCoreKrnl.exe! Aborting...");