summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 10:17:13 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-29 10:17:13 +0100
commit28817e6dbb31b4004e2fd1a5be2c85bcbfe0a5ec (patch)
tree8368dc726aa85d4eae27db487224e2e956b39a2e
parent2529c8722d6d3491a3e19aa728f4bfce099bcc91 (diff)
NewBoot: Getting BootServices implemented.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Private/EFIKit/EFI.hxx122
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx2
-rw-r--r--Private/NewKit/Defines.hpp124
-rw-r--r--TODO_LIST.TXT1
4 files changed, 183 insertions, 66 deletions
diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx
index 17f2da48..fac59f8b 100644
--- a/Private/EFIKit/EFI.hxx
+++ b/Private/EFIKit/EFI.hxx
@@ -9,10 +9,113 @@
#pragma once
+/**
+@brief HCore Implementation of UEFI protocols.
+*/
+
#include <NewKit/Defines.hpp>
using namespace hCore;
+struct EfiTableHeader;
+struct EfiLoadFileProtocol;
+struct EfiSimpleTextOutputProtocol;
+struct EfiDevicePathProtocol;
+
+/// What's boot policy?
+/// If TRUE, indicates that the request originates from the boot manager, and that the boot manager is attempting to
+/// load FilePath as a boot selection. If FALSE, then FilePath must match an exact file to be loaded.
+
+typedef UInt64 (*EfiTextString)(struct EfiSimpleTextOutputProtocol *This, const WideChar *OutputString);
+typedef UInt64 (*EfiLoadFile)(EfiLoadFileProtocol *This, EfiDevicePathProtocol *FilePath, Boolean BootPolicy,
+ UInt32 *BufferSize, Void *Buffer);
+
+/// EFI pool helpers
+
+typedef enum EfiMemoryType
+{
+ ///
+ /// Not used.
+ ///
+ EfiReservedMemoryType,
+ ///
+ /// The code portions of a loaded application.
+ /// (Note that UEFI OS loaders are UEFI applications.)
+ ///
+ EfiLoaderCode,
+ ///
+ /// The data portions of a loaded application and the default data allocation
+ /// type used by an application to allocate pool memory.
+ ///
+ EfiLoaderData,
+ ///
+ /// The code portions of a loaded Boot Services Driver.
+ ///
+ EfiBootServicesCode,
+ ///
+ /// The data portions of a loaded Boot Serves Driver, and the default data
+ /// allocation type used by a Boot Services Driver to allocate pool memory.
+ ///
+ EfiBootServicesData,
+ ///
+ /// The code portions of a loaded Runtime Services Driver.
+ ///
+ EfiRuntimeServicesCode,
+ ///
+ /// The data portions of a loaded Runtime Services Driver and the default
+ /// data allocation type used by a Runtime Services Driver to allocate pool memory.
+ ///
+ EfiRuntimeServicesData,
+ ///
+ /// Free (unallocated) memory.
+ ///
+ EfiConventionalMemory,
+ ///
+ /// Memory in which errors have been detected.
+ ///
+ EfiUnusableMemory,
+ ///
+ /// Memory that holds the ACPI tables.
+ ///
+ EfiACPIReclaimMemory,
+ ///
+ /// Address space reserved for use by the firmware.
+ ///
+ EfiACPIMemoryNVS,
+ ///
+ /// Used by system firmware to request that a memory-mapped IO region
+ /// be mapped by the OS to a virtual address so it can be accessed by EFI runtime services.
+ ///
+ EfiMemoryMappedIO,
+ ///
+ /// System memory-mapped IO region that is used to translate memory
+ /// cycles to IO cycles by the processor.
+ ///
+ EfiMemoryMappedIOPortSpace,
+ ///
+ /// Address space reserved by the firmware for code that is part of the processor.
+ ///
+ EfiPalCode,
+ ///
+ /// A memory region that operates as EfiConventionalMemory,
+ /// however it happens to also support byte-addressable non-volatility.
+ ///
+ EfiPersistentMemory,
+ ///
+ /// A memory region that describes system memory that has not been accepted
+ /// by a corresponding call to the underlying isolation architecture.
+ ///
+ EfiUnacceptedMemoryType,
+ ///
+ /// The last type of memory.
+ /// Not a real type.
+ ///
+ EfiMaxMemoryType,
+} EfiMemoryType;
+
+typedef UInt64 (*EfiAllocatePool)(EfiMemoryType PoolType, UInt32 Size, Void **Buffer);
+typedef UInt64 (*EfiFreePool)(Void *Buffer);
+
typedef struct EfiTableHeader
{
UInt64 signature;
@@ -22,9 +125,20 @@ typedef struct EfiTableHeader
UInt32 reserved;
} EfiTableHeader;
-struct EfiSimpleTextOutputProtocol;
+typedef struct EfiLoadFileProtocol
+{
+ EfiLoadFile loadFile;
+} EfiLoadFileProtocol;
-typedef UInt64 (*EfiTextString)(struct EfiSimpleTextOutputProtocol *self, const wchar_t *string);
+typedef struct EfiDevicePathProtocol
+{
+ UInt8 type;
+ UInt8 subType;
+ UInt8 lenData[2];
+} EfiDevicePathProtocol;
+
+#define kEntireDevPath 0xFF
+#define kThisInstancePath 0x01
typedef struct EfiSimpleTextOutputProtocol
{
@@ -43,7 +157,7 @@ typedef struct EfiSimpleTextOutputProtocol
typedef struct EfiSystemTable
{
EfiTableHeader hdr;
- wchar_t *firmwareVendor;
+ WideChar *firmwareVendor;
UInt32 firmwareRevision;
VoidPtr consoleInHandle;
UInt64 conIn;
@@ -58,3 +172,5 @@ typedef struct EfiSystemTable
} EfiSystemTable;
#define EfiMain efi_main
+
+#define kEfiOk 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx
index 9b00a6a9..a6b80fc1 100644
--- a/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/EfiMain.cxx
@@ -21,5 +21,5 @@ extern "C" int EfiMain(void *ImageHandle, EfiSystemTable *SystemTable)
rt_halt();
}
- return 0;
+ return kEfiOk;
}
diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp
index 164bdc9e..50668376 100644
--- a/Private/NewKit/Defines.hpp
+++ b/Private/NewKit/Defines.hpp
@@ -11,83 +11,83 @@
#include <NewKit/Macros.hpp>
-#define NEWKIT_VERSION "v1.00"
+#define NEWKIT_VERSION "1.0.0"
#if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__)
-# include <CRT/__cxxkit_defines.h>
+#include <CRT/__cxxkit_defines.h>
#endif
#ifdef __has_feature
#if !__has_feature(cxx_nullptr)
-# error You must at least have nullptr featured on your C++ compiler.
+#error You must at least have nullptr featured on your C++ compiler.
#endif
#endif
namespace hCore
{
- using voidPtr = void*;
- using VoidPtr = void*;
- using nullPtr = decltype(nullptr);
- using NullPtr = decltype(nullptr);
-
- using Int = int;
- using Int32 = int;
- using UShort = unsigned short;
- using UInt16 = unsigned short;
- using Short = short;
- using Int16 = short;
- using UInt = unsigned int;
- using UInt32 = unsigned int;
- using Long = long int;
- using Int64 = long int;
- using ULong = unsigned long int;
- using UInt64 = unsigned long int;
- using Boolean = bool;
- using Bool = bool;
- using Char = char;
- using UChar = unsigned char;
- using UInt8 = unsigned char;
-
- using SSize = Int64;
- using SSizeT = Int64;
- using Size = __SIZE_TYPE__;
- using SizeT = __SIZE_TYPE__;
- using IntPtr = __INTPTR_TYPE__;
- using UIntPtr = __UINTPTR_TYPE__;
- using IntFast = __INT_FAST32_TYPE__;
- using IntFast64 = __INT_FAST64_TYPE__;
- using PtrDiff = __PTRDIFF_TYPE__;
-
- using Utf8Char = char8_t;
- using Utf16Char = char16_t;
- using Utf32Char = char32_t;
-
- using Void = void;
-
- using Lba = SSizeT;
-
- enum class Endian : UChar
- {
- kLittle,
- kBig
- };
-
- template <typename Args> Args &&forward(Args &arg)
- {
- return static_cast<Args &&>(arg);
- }
-
- template <typename Args> Args &&move(Args &&arg)
- {
- return static_cast<Args &&>(arg);
- }
+using voidPtr = void *;
+using VoidPtr = void *;
+using nullPtr = decltype(nullptr);
+using NullPtr = decltype(nullptr);
+
+using Int = int;
+using Int32 = int;
+using UShort = unsigned short;
+using UInt16 = unsigned short;
+using Short = short;
+using Int16 = short;
+using UInt = unsigned int;
+using UInt32 = unsigned int;
+using Long = long int;
+using Int64 = long int;
+using ULong = unsigned long int;
+using UInt64 = unsigned long int;
+using Boolean = bool;
+using Bool = bool;
+using Char = char;
+using UChar = unsigned char;
+using UInt8 = unsigned char;
+
+using SSize = Int64;
+using SSizeT = Int64;
+using Size = __SIZE_TYPE__;
+using SizeT = __SIZE_TYPE__;
+using IntPtr = __INTPTR_TYPE__;
+using UIntPtr = __UINTPTR_TYPE__;
+using IntFast = __INT_FAST32_TYPE__;
+using IntFast64 = __INT_FAST64_TYPE__;
+using PtrDiff = __PTRDIFF_TYPE__;
+
+using Utf8Char = char8_t;
+using Utf16Char = char16_t;
+using WideChar = wchar_t;
+using Utf32Char = char32_t;
+
+using Void = void;
+
+using Lba = SSizeT;
+
+enum class Endian : UChar
+{
+ kLittle,
+ kBig
+};
+
+template <typename Args> Args &&forward(Args &arg)
+{
+ return static_cast<Args &&>(arg);
+}
+
+template <typename Args> Args &&move(Args &&arg)
+{
+ return static_cast<Args &&>(arg);
+}
} // namespace hCore
#define DEDUCE_ENDIAN(address, value) \
- (((reinterpret_cast<hCore::Char*>(address)[0]) == (value)) ? (hCore::Endian::kBig) \
- : (hCore::Endian::kLittle))
+ (((reinterpret_cast<hCore::Char *>(address)[0]) == (value)) ? (hCore::Endian::kBig) : (hCore::Endian::kLittle))
#define Yes (true)
#define No (false)
-#define VoidStar hCore::voidPtr \ No newline at end of file
+#define VoidStar hCore::voidPtr
diff --git a/TODO_LIST.TXT b/TODO_LIST.TXT
index f6085f65..1d29f1be 100644
--- a/TODO_LIST.TXT
+++ b/TODO_LIST.TXT
@@ -2,5 +2,6 @@
- We then need sync primitives. [ X ]
- We also need a system library for the OS. [ X ]
- We need a bootloader for AMD64 [ X ]
+ - Implement Boot Services [ WiP ]
- Load Handover and kernel into memory [ ]
- Jump to kernel [ ]