summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-02 22:19:08 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-02 22:19:08 +0100
commit275c162c7c270499408ee4cbdd8f24b6d0240117 (patch)
tree74e995363b2bf98659848d6e99b176a2876f28cc
parent1b7cde24b45bb9cb8335767d4e50101867d21a37 (diff)
Bootloader: Fix code that isn't supposed to be there, EFI wrapper
improvements. Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Private/EFIKit/Api.hxx16
-rw-r--r--Private/EFIKit/EFI.hxx10
-rw-r--r--Private/EFIKit/Handover.hxx (renamed from Private/EFIKit/BootProtocol.hxx)2
-rw-r--r--Private/KernelKit/PE.hpp20
-rw-r--r--Private/NewBoot/BootKit/Protocol.hxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx28
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx3
7 files changed, 48 insertions, 33 deletions
diff --git a/Private/EFIKit/Api.hxx b/Private/EFIKit/Api.hxx
index dea09425..031c38e7 100644
--- a/Private/EFIKit/Api.hxx
+++ b/Private/EFIKit/Api.hxx
@@ -12,8 +12,8 @@
#include <EFIKit/EFI.hxx>
-inline EfiSystemTable* ST = nullptr;
-inline EfiBootServices* BS = nullptr;
+inline EfiSystemTable *ST = nullptr;
+inline EfiBootServices *BS = nullptr;
namespace EFI {
/**
@@ -30,7 +30,7 @@ inline Void Stop() noexcept {
@brief Exit EFI API to let the OS load correctly.
Bascially frees everything we have in the EFI side.
*/
-inline void ExitBootServices(EfiSystemTable* SystemTable, UInt64 MapKey,
+inline void ExitBootServices(EfiSystemTable *SystemTable, UInt64 MapKey,
EfiHandlePtr ImageHandle) noexcept {
if (!SystemTable) return;
@@ -38,7 +38,7 @@ inline void ExitBootServices(EfiSystemTable* SystemTable, UInt64 MapKey,
}
} // namespace EFI
-inline void KeInitEFI(EfiSystemTable* SystemTable) noexcept {
+inline void KeInitEFI(EfiSystemTable *SystemTable) noexcept {
if (!SystemTable) return;
ST = SystemTable;
@@ -48,8 +48,8 @@ inline void KeInitEFI(EfiSystemTable* SystemTable) noexcept {
ST->ConOut->SetAttribute(SystemTable->ConOut, kEFIYellow);
}
-inline void KeRuntimeStop(const EfiCharType* ErrorCode,
- const EfiCharType* Reason) noexcept {
+inline void KeRuntimeStop(const EfiCharType *ErrorCode,
+ const EfiCharType *Reason) noexcept {
ST->ConOut->OutputString(ST->ConOut, L"*** STOP ***\r\n");
ST->ConOut->OutputString(ST->ConOut, L"*** ErrorCode: ");
@@ -69,7 +69,9 @@ enum {
};
#ifdef __BOOTLOADER__
+
#include <BootKit/Platform.hxx>
-#endif // IF TARGET=BOOTLOADER
+
+#endif // ifdef __BOOTLOADER__
#endif /* ifndef __EFI_API__ */
diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx
index 243211e9..f59917f2 100644
--- a/Private/EFIKit/EFI.hxx
+++ b/Private/EFIKit/EFI.hxx
@@ -59,8 +59,8 @@ typedef UInt64(EFI_API *EfiTextClear)(struct EfiSimpleTextOutputProtocol *This);
typedef UInt64(EFI_API *EfiLoadFile)(EfiLoadFileProtocol *This,
EfiFileDevicePathProtocol *FilePath,
- Boolean BootPolicy, UInt32 **BufferSize,
- VoidPtr *Buffer);
+ Boolean BootPolicy, UInt32 *BufferSize,
+ VoidPtr Buffer);
typedef UInt64(EFI_API *EfiCopyMem)(VoidPtr DstBuf, VoidPtr SrcBuf,
SizeT Length);
@@ -472,4 +472,10 @@ enum {
kEFICount = 6,
};
+#define END_DEVICE_PATH_TYPE 0x7f
+#define END_ENTIRE_DEVICE_PATH_SUBTYPE 0xFF
+#define END_INSTANCE_DEVICE_PATH_SUBTYPE 0x01
+
+#define kEfiOffsetOf(T, F) __builtin_offsetof(T, F)
+
#endif // __EFI__
diff --git a/Private/EFIKit/BootProtocol.hxx b/Private/EFIKit/Handover.hxx
index 1acfcc18..07a3bc51 100644
--- a/Private/EFIKit/BootProtocol.hxx
+++ b/Private/EFIKit/Handover.hxx
@@ -8,7 +8,7 @@
*/
/**
- * @file BootProtocol.hxx
+ * @file Handover.hxx
* @author Amlal El Mahrouss (amlalelmahrouss@icloud.com)
* @brief Handover protocol.
* @version 0.1
diff --git a/Private/KernelKit/PE.hpp b/Private/KernelKit/PE.hpp
index 9c975108..88ee319a 100644
--- a/Private/KernelKit/PE.hpp
+++ b/Private/KernelKit/PE.hpp
@@ -26,7 +26,7 @@ typedef char CHAR;
#define kPeMagic 0x00004550
-typedef struct PACKED ExecHeader final {
+typedef struct ExecHeader final {
U32 mMagic; // PE\0\0 or 0x00004550
U16 mMachine;
U16 mNumberOfSections;
@@ -35,12 +35,12 @@ typedef struct PACKED ExecHeader final {
U32 mNumberOfSymbols;
U16 mSizeOfOptionalHeader;
U16 mCharacteristics;
-} ExecHeader, *ExecHeaderPtr;
+} PACKED ExecHeader, *ExecHeaderPtr;
#define kMagPE32 0x010b
#define kMagPE64 0x020b
-typedef PACKED struct ExecOptionalHeader final {
+typedef struct ExecOptionalHeader final {
U16 mMagic; // 0x010b - PE32, 0x020b - PE32+ (64 bit)
U8 mMajorLinkerVersion;
U8 mMinorLinkerVersion;
@@ -71,9 +71,9 @@ typedef PACKED struct ExecOptionalHeader final {
U32 mSizeOfHeapCommit;
U32 mLoaderFlags;
U32 mNumberOfRvaAndSizes;
-} ExecOptionalHeader, *ExecOptionalHeaderPtr;
+} PACKED ExecOptionalHeader, *ExecOptionalHeaderPtr;
-typedef PACKED struct ExecSectionHeader final {
+typedef struct ExecSectionHeader final {
CHAR mName[8];
U32 mVirtualSize;
U32 mVirtualAddress;
@@ -84,7 +84,7 @@ typedef PACKED struct ExecSectionHeader final {
U16 mNumberOfRelocations;
U16 mNumberOfLinenumbers;
U32 mCharacteristics;
-} ExecSectionHeader, *ExecSectionHeaderPtr;
+} PACKED ExecSectionHeader, *ExecSectionHeaderPtr;
enum kExecDataDirParams {
kExecExport,
@@ -92,7 +92,7 @@ enum kExecDataDirParams {
kExecCnt,
};
-typedef PACKED struct ExecExportDirectory {
+typedef struct ExecExportDirectory {
U32 mCharacteristics;
U32 mTimeDateStamp;
U16 mMajorVersion;
@@ -104,9 +104,9 @@ typedef PACKED struct ExecExportDirectory {
U32 mAddressOfFunctions; // export table rva
U32 mAddressOfNames;
U32 mAddressOfNameOrdinal; // ordinal table rva
-} ExecExportDirectory, *ExecExportDirectoryPtr;
+} PACKED ExecExportDirectory, *ExecExportDirectoryPtr;
-typedef PACKED struct ExecImportDirectory {
+typedef struct ExecImportDirectory {
union {
U32 mCharacteristics;
U32 mOriginalFirstThunk;
@@ -115,6 +115,6 @@ typedef PACKED struct ExecImportDirectory {
U32 mForwarderChain;
U32 mNameRva;
U32 mThunkTableRva;
-} ExecImportDirectory, *ExecImportDirectoryPtr;
+} PACKED ExecImportDirectory, *ExecImportDirectoryPtr;
#endif /* ifndef __PE__ */
diff --git a/Private/NewBoot/BootKit/Protocol.hxx b/Private/NewBoot/BootKit/Protocol.hxx
index b2725794..055858a8 100644
--- a/Private/NewBoot/BootKit/Protocol.hxx
+++ b/Private/NewBoot/BootKit/Protocol.hxx
@@ -9,5 +9,5 @@
#pragma once
-#include <EFIKit/BootProtocol.hxx>
#include <EFIKit/EFI.hxx>
+#include <EFIKit/Handover.hxx>
diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
index 8ca7737d..328e7bc9 100644
--- a/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-BootKit.cxx
@@ -11,9 +11,6 @@
#include <EFIKit/Api.hxx>
#include <FSKit/NewFS.hxx>
-#include "EFIKit/EFI.hxx"
-#include "NewKit/Macros.hpp"
-
/// bugs 0
/////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -113,7 +110,7 @@ HCore::VoidPtr BFileReader::ReadAll(SizeT &size) {
EfiHandlePtr handleFile = nullptr;
EfiLoadFileProtocol *loadFile = nullptr;
- EfiGUID loadFileGUID = EfiGUID(EFI_LOAD_FILE2_PROTOCOL_GUID);
+ EfiGUID loadFileGUID = EfiGUID(EFI_LOAD_FILE_PROTOCOL_GUID);
BS->LocateProtocol(&loadFileGUID, nullptr, (VoidPtr *)&loadFile);
@@ -128,21 +125,30 @@ HCore::VoidPtr BFileReader::ReadAll(SizeT &size) {
BS->AllocatePool(EfiLoaderCode, sizeof(UInt32), (VoidPtr *)&bufSz);
*bufSz = KIB(324);
+ if (!bufSz) {
+ return nullptr;
+ }
+
BS->AllocatePool(EfiLoaderCode, *bufSz, &buf);
- if (!buf) return nullptr;
+ if (!buf) {
+ BS->FreePool(bufSz);
+ bufSz = nullptr;
+
+ return nullptr;
+ }
EfiFileDevicePathProtocol filePath{0};
- filePath.Proto.Length[0] = sizeof(EfiDevicePathProtocol);
- filePath.Proto.Length[1] = BStrLen(mPath);
+ filePath.Proto.Length[0] = sizeof(EfiDevicePathProtocol) + BStrLen(mPath);
+ filePath.Proto.Length[1] = 0;
filePath.Proto.Type = kEFIMediaDevicePath;
filePath.Proto.SubType = kEFIMediaDevicePath; // from all drives.
BCopyMem(filePath.Path, mPath, BStrLen(mPath));
- auto err = loadFile->LoadFile(loadFile, &filePath, false, &bufSz, &buf);
+ auto err = loadFile->LoadFile(loadFile, &filePath, true, bufSz, buf);
size = *bufSz;
@@ -158,7 +164,7 @@ HCore::VoidPtr BFileReader::ReadAll(SizeT &size) {
case 2: {
writer.WriteString(L"HCoreLdr: Error: ")
.WriteString(mPath)
- .WriteString(L", Code: Invalid-Parameter")
+ .WriteString(L", EFI-Code: Invalid-Parameter")
.WriteString(L"\r\n");
break;
@@ -166,7 +172,7 @@ HCore::VoidPtr BFileReader::ReadAll(SizeT &size) {
case 14: {
writer.WriteString(L"HCoreLdr: Error: ")
.WriteString(mPath)
- .WriteString(L" , EFI-Code: Not-Found")
+ .WriteString(L", EFI-Code: Not-Found")
.WriteString(L"\r\n");
break;
@@ -174,7 +180,7 @@ HCore::VoidPtr BFileReader::ReadAll(SizeT &size) {
default: {
writer.WriteString(L"HCoreLdr: Error: ")
.WriteString(mPath)
- .WriteString(L" , EFI-Code: Unknown-Error")
+ .WriteString(L", EFI-Code: Unknown-Error")
.WriteString(L"\r\n");
break;
diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
index 663d4bcb..20dd3125 100644
--- a/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-Platform.cxx
@@ -14,6 +14,7 @@
*
*/
+#include <BootKit/BootKit.hxx>
#include <BootKit/Platform.hxx>
#include <EFIKit/Api.hxx>
@@ -27,6 +28,6 @@ extern "C" void rt_cld() { asm volatile("cld"); }
extern "C" void rt_std() { asm volatile("std"); }
-/// @brief Stack check
+/// @brief Stack Checker, leave empty.
extern "C" void ___chkstk_ms(void) {}