summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-17 11:11:11 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-04-17 11:11:11 +0200
commit762ba62476b3cfc54ffe84f4861cca5f432c8d6a (patch)
treed610eb6603402e56257f6cedc8138cfd6f0abf51
parentc0099ab36bf9606c5503ceb0fa0d5b64f71c7203 (diff)
kernel: cleanup AMD64 bootloader, update icons.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
-rw-r--r--Private/FirmwareKit/EPM.hxx9
-rw-r--r--Private/NewBoot/Source/BootloaderRsrc.rsrc2
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx148
-rw-r--r--Private/NewBoot/Source/makefile11
-rw-r--r--Private/Root/Boot/kernel-logo.icobin150570 -> 2238 bytes
-rw-r--r--Public/Developer/SystemLib/Headers/Math.h1
6 files changed, 80 insertions, 91 deletions
diff --git a/Private/FirmwareKit/EPM.hxx b/Private/FirmwareKit/EPM.hxx
index 048324f5..5cc743be 100644
--- a/Private/FirmwareKit/EPM.hxx
+++ b/Private/FirmwareKit/EPM.hxx
@@ -33,7 +33,7 @@ typedef struct BlockGUID {
struct PACKED BootBlock {
NewOS::Char Magic[kEPMMagicLength];
NewOS::Char Name[kEPMNameLength];
- BlockGUID Uuid;
+ BlockGUID Uuid;
NewOS::Int32 Version;
NewOS::Int64 NumBlocks;
NewOS::Int64 SectorSz;
@@ -104,11 +104,12 @@ typedef struct PartitionBlock PartitionBlockType;
#endif
#endif
-///! @brief partition must start after this address.
-#define kEPMStartPartitionBlk 0
+///! @brief partition must start at this address.
+///! Anything below is reserved for Data backup by the Main OS.
+#define kEPMStartPartitionBlk (0)
///! @brief Current EPM revision (2)
-#define kEPMRevision 2
+#define kEPMRevision (21)
/// END SPECS
diff --git a/Private/NewBoot/Source/BootloaderRsrc.rsrc b/Private/NewBoot/Source/BootloaderRsrc.rsrc
index e8fa0c9a..2a04219e 100644
--- a/Private/NewBoot/Source/BootloaderRsrc.rsrc
+++ b/Private/NewBoot/Source/BootloaderRsrc.rsrc
@@ -24,4 +24,4 @@ BEGIN
BEGIN
VALUE "Translation", 0x809, 1252
END
-END \ No newline at end of file
+END
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index f9ebcbbc..f5bb3ce8 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -43,7 +43,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
/// if ATA drive is initialized and EFI vendor supports an EPM scheme.
/// @EDK tells our OS that it supports EPM scheme as well.
- if (ataDev && SystemTable->FirmwareVendor[0] == '@') {
+ if (ataDev) {
Char namePart[kEPMNameLength] = {"NewBoot"};
/// tries to read an EPM block, or writes one if it fails.
isEpmFound = boot_write_epm_partition(namePart, kEPMNameLength, &ataDev);
@@ -52,114 +52,102 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
return kEfiFail;
}
- /// Read Kernel blob.
+ UInt32 MapKey = 0;
+ UInt32* SizePtr = nullptr;
+ EfiMemoryDescriptor* Descriptor = nullptr;
+ UInt32 SzDesc = 0;
+ UInt32 RevDesc = 0;
- BFileReader kernelImg(L".NEWDEV", ImageHandle);
-
- kernelImg.Size(kMaxBufSize);
- kernelImg.ReadAll();
-
- if (kernelImg.Error() == BFileReader::kOperationOkay) {
- UInt32 MapKey = 0;
- UInt32* SizePtr = nullptr;
- EfiMemoryDescriptor* Descriptor = nullptr;
- UInt32 SzDesc = 0;
- UInt32 RevDesc = 0;
-
- if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&SizePtr) !=
- kEfiOk) {
- EFI::RaiseHardError(L"__bad_alloc", L"NewBoot ran out of memory!");
- }
+ if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&SizePtr) !=
+ kEfiOk) {
+ EFI::RaiseHardError(L"__bad_alloc", L"NewBoot ran out of memory!");
+ }
- /****
- *
- * Load kernel into memory.
- *
- */
+ /****
+ *
+ * Load kernel into memory.
+ *
+ */
- *SizePtr = sizeof(EfiMemoryDescriptor);
+ *SizePtr = sizeof(EfiMemoryDescriptor);
- if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
- (VoidPtr*)&Descriptor) != kEfiOk) {
- EFI::RaiseHardError(L"__bad_alloc", L"NewBoot ran out of memory!");
- }
+ if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
+ (VoidPtr*)&Descriptor) != kEfiOk) {
+ EFI::RaiseHardError(L"__bad_alloc", L"NewBoot ran out of memory!");
+ }
- /****
- *
- * Get machine memory map.
- *
- */
+ /****
+ *
+ * Get machine memory map.
+ *
+ */
- while (BS->GetMemoryMap(SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
- kEfiOk)
- ;
+ while (BS->GetMemoryMap(SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
+ kEfiOk)
+ ;
- HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
+ HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
- BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
- (VoidPtr*)&handoverHdrPtr);
+ BS->AllocatePool(EfiLoaderData, sizeof(HEL::HandoverInformationHeader),
+ (VoidPtr*)&handoverHdrPtr);
- handoverHdrPtr->f_GOP.f_The = kGop->Mode->FrameBufferBase;
- handoverHdrPtr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution;
- handoverHdrPtr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution;
- handoverHdrPtr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine;
- handoverHdrPtr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat;
- handoverHdrPtr->f_GOP.f_Size = kGop->Mode->FrameBufferSize;
+ handoverHdrPtr->f_GOP.f_The = kGop->Mode->FrameBufferBase;
+ handoverHdrPtr->f_GOP.f_Width = kGop->Mode->Info->VerticalResolution;
+ handoverHdrPtr->f_GOP.f_Height = kGop->Mode->Info->HorizontalResolution;
+ handoverHdrPtr->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine;
+ handoverHdrPtr->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat;
+ handoverHdrPtr->f_GOP.f_Size = kGop->Mode->FrameBufferSize;
- handoverHdrPtr->f_PhysicalStart =
- reinterpret_cast<voidPtr>(Descriptor->PhysicalStart);
- handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages;
+ handoverHdrPtr->f_PhysicalStart =
+ reinterpret_cast<voidPtr>(Descriptor->PhysicalStart);
+ handoverHdrPtr->f_PhysicalSize = Descriptor->NumberOfPages;
- handoverHdrPtr->f_VirtualStart =
- reinterpret_cast<voidPtr>(Descriptor->VirtualStart);
+ handoverHdrPtr->f_VirtualStart =
+ reinterpret_cast<voidPtr>(Descriptor->VirtualStart);
- handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */
+ handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */
- handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
+ handoverHdrPtr->f_FirmwareVendorLen = BStrLen(SystemTable->FirmwareVendor);
- BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
- handoverHdrPtr->f_FirmwareVendorLen);
+ BCopyMem(handoverHdrPtr->f_FirmwareVendorName, SystemTable->FirmwareVendor,
+ handoverHdrPtr->f_FirmwareVendorLen);
#ifdef __DEBUG__
- writer.Write(L"NewOS: Fetching ACPI's 'RSD PTR'...").Write(L"\r\n");
+ writer.Write(L"NewOS: Fetching ACPI's 'RSD PTR'...").Write(L"\r\n");
#endif
- for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries;
- ++indexVT) {
- volatile Char* vendorTable = reinterpret_cast<volatile Char*>(
- SystemTable->ConfigurationTable[indexVT].VendorTable);
+ for (SizeT indexVT = 0; indexVT < SystemTable->NumberOfTableEntries;
+ ++indexVT) {
+ volatile Char* vendorTable = reinterpret_cast<volatile Char*>(
+ SystemTable->ConfigurationTable[indexVT].VendorTable);
- if (vendorTable[0] == 'R' && vendorTable[1] == 'S' &&
- vendorTable[2] == 'D' && vendorTable[3] == ' ' &&
- vendorTable[4] == 'P' && vendorTable[5] == 'T' &&
- vendorTable[6] == 'R' && vendorTable[7] == ' ') {
- handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable;
+ if (vendorTable[0] == 'R' && vendorTable[1] == 'S' &&
+ vendorTable[2] == 'D' && vendorTable[3] == ' ' &&
+ vendorTable[4] == 'P' && vendorTable[5] == 'T' &&
+ vendorTable[6] == 'R' && vendorTable[7] == ' ') {
+ handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable;
#ifdef __DEBUG__
- writer.Write(L"NewOS: Found ACPI's 'RSD PTR' table on this machine.")
- .Write(L"\r\n");
+ writer.Write(L"NewOS: Found ACPI's 'RSD PTR' table on this machine.")
+ .Write(L"\r\n");
#endif
- break;
- }
- }
-
- if (!isEpmFound) {
- writer.Write(L"NewOS: No partition found for NewOS. (HCR-1000)\r\n");
+ break;
}
+ }
- handoverHdrPtr->f_Magic = kHandoverMagic;
- handoverHdrPtr->f_Version = kHandoverVersion;
+ if (!isEpmFound) {
+ writer.Write(L"NewOS: No partition found for NewOS. (HCR-1000)\r\n");
+ }
- writer.Write(L"Running NewOS...\r\n");
+ handoverHdrPtr->f_Magic = kHandoverMagic;
+ handoverHdrPtr->f_Version = kHandoverVersion;
- EFI::ExitBootServices(MapKey, ImageHandle);
+ writer.Write(L"Running NewOS...\r\n");
- /// TODO: Read catalog and read NewKernel.exe
+ EFI::ExitBootServices(MapKey, ImageHandle);
- } else {
- writer.Write(L"NewOS: Error-Code: HLDR-0003\r\n");
- }
+ /// TODO: Read catalog and read NewKernel.exe
EFI::Stop();
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 50259398..4016e3a8 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -20,7 +20,7 @@ endif
IMG=epm.img
IMG_2=epm-slave.img
-EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int
+EMU_FLAGS=-net none -smp 4 -m 4G -M q35 -bios OVMF.fd -device piix3-ide,id=ide -drive id=disk,file=$(IMG),format=raw,if=none -device ide-hd,drive=disk,bus=ide.0 -drive file=fat:rw:CDROM,index=2,format=raw -d int -hdd epm-slave.img
LD_FLAGS=-e efi_main --subsystem=10
@@ -31,7 +31,7 @@ REM=rm
REM_FLAG=-f
FLAG_ASM=-f win64
-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./
+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:
@@ -43,10 +43,9 @@ all: compile-amd64
$(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI
$(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI
$(COPY) NewBoot.exe ../../Root/Boot/NewBoot.exe
- $(COPY) ../../Root/Boot/NewKernel.exe CDROM/
ifneq ($(DEBUG_SUPPORT), )
-DEBUG = -D__DEBUG__
+DEBUG = -D__DEBUG__
endif
.PHONY: compile-amd64
@@ -61,7 +60,7 @@ run-efi-amd64:
.PHONY: epm-img
epm-img:
qemu-img create -f raw $(IMG) 256M
- qemu-img create -f raw $(IMG_2) 256M
+ qemu-img create -f raw $(IMG_2) 512M
.PHONY: download-edk
download-edk:
@@ -77,4 +76,4 @@ help:
@echo "epm-img: Format a disk using the Explicit Partition Map/GPT."
@echo "clean: clean bootloader."
@echo "bootloader-amd64: Build bootloader. (PC AMD64)"
- @echo "run-efo-amd64: Run bootloader. (PC AMD64)"
+ @echo "run-efi-amd64: Run bootloader. (PC AMD64)"
diff --git a/Private/Root/Boot/kernel-logo.ico b/Private/Root/Boot/kernel-logo.ico
index 683c2137..d5ea0310 100644
--- a/Private/Root/Boot/kernel-logo.ico
+++ b/Private/Root/Boot/kernel-logo.ico
Binary files differ
diff --git a/Public/Developer/SystemLib/Headers/Math.h b/Public/Developer/SystemLib/Headers/Math.h
index f6c8f216..34738cd1 100644
--- a/Public/Developer/SystemLib/Headers/Math.h
+++ b/Public/Developer/SystemLib/Headers/Math.h
@@ -8,4 +8,5 @@
#include <Headers/Defines.h>
+/// @brief Random nubmer generator.
CA_EXTERN_C SizeType MathRand(VoidType);