summaryrefslogtreecommitdiffhomepage
path: root/Private
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-04 19:46:31 +0200
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-04 19:46:31 +0200
commita45872967f07906297782cd04223706cfc326219 (patch)
treef48d43749e4a1536d34e6c7dbb5b25defb8656fa /Private
parentc33efb3e8a31435b37ed2c55375eec80c9b23155 (diff)
NewBoot: Major bootloader improvements, use __EFI_x86_64__ on EFI platforms, add common device class.
Meta: Upate specs and kernel-design. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private')
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx27
-rw-r--r--Private/NewBoot/BootKit/Device.hxx34
-rw-r--r--Private/NewBoot/BootKit/HW/ATA.hxx (renamed from Private/NewBoot/BootKit/Arch/ATA.hxx)16
-rw-r--r--Private/NewBoot/BootKit/HW/SATA.hxx (renamed from Private/NewBoot/BootKit/Arch/SATA.hxx)0
-rw-r--r--Private/NewBoot/NetBoot/Module.cxx (renamed from Private/NewBoot/NetBoot/EfiModule.cxx)11
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootATA.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx16
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx33
-rw-r--r--Private/NewBoot/Source/makefile6
11 files changed, 112 insertions, 37 deletions
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index be46f64c..66a9aa67 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -16,11 +16,13 @@ class BFileReader;
class BFileRunner;
class BVersionString;
-#include <BootKit/Arch/ATA.hxx>
+#include <BootKit/HW/ATA.hxx>
#include <CompilerKit/Version.hxx>
+#ifdef __EFI_x86_64__
#include <FirmwareKit/EFI.hxx>
-#include <NewKit/Defines.hpp>
+#endif // ifdef __EFI_x86_64__
#include <FirmwareKit/EPM.hxx>
+#include <NewKit/Defines.hpp>
using namespace NewOS;
@@ -42,6 +44,7 @@ typedef Char CharacterTypeUTF8;
*/
class BTextWriter final {
BTextWriter &_Write(const Long &num);
+
public:
BTextWriter &Write(const Long &num);
BTextWriter &Write(const UChar *str);
@@ -76,7 +79,8 @@ NewOS::SizeT BSetMem(CharacterTypeUTF16 *src, const CharacterTypeUTF16 byte,
*/
class BFileReader final {
public:
- explicit BFileReader(const CharacterTypeUTF16 *path, EfiHandlePtr ImageHandle);
+ explicit BFileReader(const CharacterTypeUTF16 *path,
+ EfiHandlePtr ImageHandle);
~BFileReader();
Void ReadAll();
@@ -163,9 +167,7 @@ inline UInt32 In32(UInt16 port) {
return value;
}
-inline Void rt_hlt() {
- asm volatile("hlt");
-}
+inline Void rt_hlt() { asm volatile("hlt"); }
#endif // __EFI_x86_64__
@@ -181,7 +183,8 @@ const UInt32 kRgbBlue = 0x00FF0000;
const UInt32 kRgbBlack = 0x00000000;
const UInt32 kRgbWhite = 0x00FFFFFF;
-/** QT GOP and related. */
+#ifdef __EFI_x86_64__
+/** GOP and related. */
inline EfiGraphicsOutputProtocol *kGop;
inline UInt16 kStride;
inline EfiGUID kGopGuid;
@@ -199,10 +202,18 @@ inline Void InitGOP() noexcept {
kStride = 4;
}
+#endif // __EFI_x86_64__
class BVersionString final {
public:
static const CharacterTypeUTF16 *Shared() { return BOOTLOADER_VERSION; }
};
-EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLength, BootDeviceATA* ataInterface);
+/// @brief Writes an EPM partition on the main disk.
+/// @param namePart the partition's name
+/// @param namePartLength the partition name's length
+/// @param bootDev the disk interface.
+/// @return
+EXTERN_C Boolean boot_write_epm_partition(const Char *namePart,
+ SizeT namePartLength,
+ BootDevice *bootDev);
diff --git a/Private/NewBoot/BootKit/Device.hxx b/Private/NewBoot/BootKit/Device.hxx
new file mode 100644
index 00000000..bc50a576
--- /dev/null
+++ b/Private/NewBoot/BootKit/Device.hxx
@@ -0,0 +1,34 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+#include <Builtins/ATA/Defines.hxx>
+
+using namespace NewOS;
+
+/// @brief Device type.
+class Device {
+ public:
+ Device() = default;
+ virtual ~Device() = default;
+
+ HCORE_MOVE_DEFAULT(Device);
+
+ struct Trait {
+ SizeT mBase{1024};
+ SizeT mSize{1024};
+};
+
+ virtual Trait& Leak() = 0;
+
+ virtual Device& Read(Char* Buf, const SizeT& SecCount) = 0;
+ virtual Device& Write(Char* Buf, const SizeT& SecCount) = 0;
+};
+
+typedef Device BootDevice;
+typedef Device NetworkDevice;
+typedef Device DiskDevice;
diff --git a/Private/NewBoot/BootKit/Arch/ATA.hxx b/Private/NewBoot/BootKit/HW/ATA.hxx
index 5501f947..40402a86 100644
--- a/Private/NewBoot/BootKit/Arch/ATA.hxx
+++ b/Private/NewBoot/BootKit/HW/ATA.hxx
@@ -7,10 +7,11 @@
#pragma once
#include <Builtins/ATA/Defines.hxx>
+#include <BootKit/Device.hxx>
using namespace NewOS;
-class BootDeviceATA final {
+class BootDeviceATA final : public Device {
public:
enum {
kPrimary = ATA_PRIMARY_IO,
@@ -22,9 +23,7 @@ class BootDeviceATA final {
HCORE_COPY_DEFAULT(BootDeviceATA);
- struct ATATrait final {
- SizeT mBase{1024};
- SizeT mSize{1024};
+ struct ATATrait final : public Device::Trait {
UInt16 mBus{kPrimary};
UInt8 mMaster{0};
Boolean mErr{false};
@@ -32,13 +31,14 @@ class BootDeviceATA final {
operator bool() { return !mErr; }
};
+ public:
operator bool();
- BootDeviceATA& Read(Char* Buf, const SizeT& SecCount);
- BootDeviceATA& Write(Char* Buf, const SizeT& SecCount);
+ BootDeviceATA& Read(Char* Buf, const SizeT& SecCount) override;
+ BootDeviceATA& Write(Char* Buf, const SizeT& SecCount) override;
- ATATrait& Leak();
+ ATATrait& Leak() override;
private:
ATATrait mTrait;
-};
+}; \ No newline at end of file
diff --git a/Private/NewBoot/BootKit/Arch/SATA.hxx b/Private/NewBoot/BootKit/HW/SATA.hxx
index cbaeb404..cbaeb404 100644
--- a/Private/NewBoot/BootKit/Arch/SATA.hxx
+++ b/Private/NewBoot/BootKit/HW/SATA.hxx
diff --git a/Private/NewBoot/NetBoot/EfiModule.cxx b/Private/NewBoot/NetBoot/Module.cxx
index e5df4a3e..c89d0a5f 100644
--- a/Private/NewBoot/NetBoot/EfiModule.cxx
+++ b/Private/NewBoot/NetBoot/Module.cxx
@@ -7,20 +7,13 @@
* ========================================================
*/
-#include <FirmwareKit/EFI.hxx>
#include <BootKit/BootKit.hxx>
-EXTERN_C Int32 EfiMain(EfiHandlePtr handle, EfiSystemTable* SystemTable)
+EXTERN_C Int32 EfiMain(Void)
{
- InitEFI(ST);
- InitGOP();
-
- /// - Find a network drive called "/OnlineInstall"
+ /// - Find a network drive called "/OnlineBoot"
/// - Download our image
/// - Boot from it.
- BTextWriter writer;
- writer.Write(L"NetBoot.exe: Updating from OTP...\r\n");
-
return kEfiOk;
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
index be7010a8..d736ac59 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootAHCI.cxx
@@ -15,4 +15,4 @@
*
*/
-#include <BootKit/Arch/SATA.hxx>
+#include <BootKit/HW/SATA.hxx>
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
index 3f309f31..2a2852fb 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx
@@ -15,7 +15,7 @@
*
*/
-#include <BootKit/Arch/ATA.hxx>
+#include <BootKit/HW/ATA.hxx>
#include <BootKit/BootKit.hxx>
/// bugs: 0
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
index e767cb2d..cca9a6ca 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
@@ -19,19 +19,19 @@ STATIC const BlockGUID kEPMGuid = {
/// @brief Write epm partition to disk.
/// @param namePart partition name
/// @param namePartLength length of name
-/// @param ataInterface disk interface, here ATA.
+/// @param bootDev disk interface.
/// @return
EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLength,
- BootDeviceATA* ataInterface) {
+ BootDevice* bootDev) {
if (namePartLength > kEPMNameLength || !namePart) return No;
- if (!ataInterface) return No;
+ if (!bootDev) return No;
- ataInterface->Leak().mBase = kEPMStartPartitionBlk;
- ataInterface->Leak().mSize = kATASectorSize;
+ bootDev->Leak().mBase = kEPMStartPartitionBlk;
+ bootDev->Leak().mSize = kATASectorSize;
- Char buf[512] = {0};
+ Char buf[kATASectorSize] = {0};
- ataInterface->Read(buf, 1);
+ bootDev->Read(buf, 1);
BTextWriter writer;
@@ -106,7 +106,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
swapBlock->Kind = kNewFSPartitionTypePage;
swapBlock->LbaEnd = kSwapSize; /// 4 MIB swap partition.
- ataInterface->Write(buf, 1);
+ bootDev->Write(buf, 1);
return No;
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index f4eaee33..f2d893c2 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -173,7 +173,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_Magic = kHandoverMagic;
handoverHdrPtr->f_Version = kHandoverVersion;
- writer.Write(L"NewOS: Running NewOS...\r\n");
+ writer.Write(L"NewOS: Starting kernel...\r\n");
EFI::ExitBootServices(MapKey, ImageHandle);
diff --git a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
new file mode 100644
index 00000000..af7f2f00
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx
@@ -0,0 +1,33 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <BootKit/BootKit.hxx>
+
+/// @brief Allocates a new object.
+/// @param sz the size.
+/// @return
+void* operator new(size_t sz)
+{
+ void* buf = nullptr;
+ BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf);
+
+ return buf;
+}
+
+/// @brief Deletes the object.
+/// @param buf the object.
+void operator delete(void* buf)
+{
+ BS->FreePool(buf);
+}
+
+/// @brief Deletes the object (array specific).
+/// @param buf the object.
+/// @param size it's size.
+void operator delete(void* buf, size_t size)
+{
+ BS->FreePool(buf);
+} \ No newline at end of file
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index b9413bb4..4f076580 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -26,7 +26,7 @@ REM=rm
REM_FLAG=-f
FLAG_ASM=-f win64
-FLAG_GNU=-fshort-wchar -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./
+FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -D__BOOTLOADER__ -I./
.PHONY: invalid-recipe
invalid-recipe:
@@ -38,6 +38,10 @@ all: compile-amd64
$(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI
$(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI
+ifneq ($(DEBUG_SUPPORT), )
+DEBUG = -D__DEBUG__
+endif
+
.PHONY: compile-amd64
compile-amd64:
windres BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o