summaryrefslogtreecommitdiffhomepage
path: root/Private/NewBoot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-06 01:45:03 +0200
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-04-06 01:45:10 +0200
commite47a33d7d4f70c54a27e96df437e6d9ac4e829cf (patch)
tree51a9f9f5019006e705444aa5f628fdae0d8dfb66 /Private/NewBoot
parent5152c2282a1a680a272322f0bd3275fdf43e1530 (diff)
Add boot_write_epm_partition for PowerPC, update start location for AMD64 EPM.
Remove HCFS support, fully focusing on NewFS. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/NewBoot')
-rw-r--r--Private/NewBoot/BootKit/BootKit.hxx11
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx13
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootMain.cxx78
-rw-r--r--Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx12
-rw-r--r--Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx119
-rw-r--r--Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S2
-rw-r--r--Private/NewBoot/Source/makefile1
-rw-r--r--Private/NewBoot/Source/ovmf.ps1 (renamed from Private/NewBoot/Source/download-edk.ps1)0
8 files changed, 174 insertions, 62 deletions
diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx
index 66a9aa67..1fbd0aef 100644
--- a/Private/NewBoot/BootKit/BootKit.hxx
+++ b/Private/NewBoot/BootKit/BootKit.hxx
@@ -167,7 +167,15 @@ inline UInt32 In32(UInt16 port) {
return value;
}
-inline Void rt_hlt() { asm volatile("hlt"); }
+/***
+ * Common processor instructions.
+*/
+
+EXTERN_C void rt_hlt();
+EXTERN_C void rt_cli();
+EXTERN_C void rt_sti();
+EXTERN_C void rt_cld();
+EXTERN_C void rt_std();
#endif // __EFI_x86_64__
@@ -217,3 +225,4 @@ class BVersionString final {
EXTERN_C Boolean boot_write_epm_partition(const Char *namePart,
SizeT namePartLength,
BootDevice *bootDev);
+
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
index cca9a6ca..b474cb72 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx
@@ -8,6 +8,7 @@
#include <FSKit/NewFS.hxx>
#define kSwapSize MIB(16)
+#define kEPMGPTStartLba 30
// {310E1FC7-2060-425D-BE7B-75A37CC679BC}
STATIC const BlockGUID kEPMGuid = {
@@ -26,7 +27,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
if (namePartLength > kEPMNameLength || !namePart) return No;
if (!bootDev) return No;
- bootDev->Leak().mBase = kEPMStartPartitionBlk;
+ bootDev->Leak().mBase = kEPMGPTStartLba;
bootDev->Leak().mSize = kATASectorSize;
Char buf[kATASectorSize] = {0};
@@ -63,7 +64,7 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
PartitionBlock* partBlock = (PartitionBlock*)(buf + sizeof(BootBlock));
- char* fsName = "NewFS";
+ const char* fsName = "NewFS";
int fsNameLength = 6;
for (SizeT i = 0; i < fsNameLength; ++i) {
@@ -72,11 +73,11 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
partBlock->Version = kEPMNewOS;
- char* partName = "System HD";
+ const char* partNameSystem = "System HD";
int partNameLength = 10;
for (SizeT i = 0; i < partNameLength; ++i) {
- partBlock->Name[i] = partName[i];
+ partBlock->Name[i] = partNameSystem[i];
}
partBlock->SectorSz = kATASectorSize;
@@ -93,11 +94,11 @@ EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLe
swapBlock->Version = kEPMNewOS;
- partName = "Swap HD";
+ const char *partNameSwap = "Swap HD";
partNameLength = 8;
for (SizeT i = 0; i < partNameLength; ++i) {
- swapBlock->Name[i] = partName[i];
+ swapBlock->Name[i] = partNameSwap[i];
}
swapBlock->SectorSz = kATASectorSize;
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
index f2d893c2..dd973d0c 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx
@@ -32,40 +32,28 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
BTextWriter writer;
/// Splash screen stuff
- writer.Write(L"Mahrouss-Logic (R) NewOS: ")
- .Write(BVersionString::Shared());
+ writer.Write(L"Mahrouss-Logic (R) NewOS: ").Write(BVersionString::Shared());
writer.Write(L"\r\nNewBoot.exe: Firmware Vendor: ")
.Write(SystemTable->FirmwareVendor)
.Write(L"\r\n");
- BootDeviceATA ataDrv;
- Boolean isIniNotFound = No;
+ BootDeviceATA ataDev;
+ Boolean isEpmFound = No;
-#ifndef __DEBUG__
/// if ATA drive is initialized and EFI vendor supports an EPM scheme.
/// @EDK tells our OS that it supports EPM scheme as well.
- if (ataDrv &&
- SystemTable->FirmwareVendor[0] == '@') {
- Char namePart[kEPMNameLength] = {"BootBlock"};
-
+ if (ataDev) {
+ Char namePart[kEPMNameLength] = {"NewBoot"};
/// tries to read an EPM block, or writes one if it fails.
- isIniNotFound =
- boot_write_epm_partition(namePart, kEPMNameLength, &ataDrv);
- } else if (SystemTable->FirmwareVendor[0] != '@') {
- writer.Write(L"NewOS: This firmware can't understand NewOS, please use Mahrouss Logic products instead\r\nNewBoot.exe: Our website: www.el-mahrouss-logic.com\r\n");
- return kEfiFail;
- } else if (!ataDrv) {
- writer.Write(L"NewOS: This computer can't work with NewOS, please use Mahrouss Logic products instead\r\nNewBoot.exe: Our website: www.el-mahrouss-logic.com\r\n");
+ isEpmFound = boot_write_epm_partition(namePart, kEPMNameLength, &ataDev);
+ } else {
+ writer.Write(
+ L"NewOS: This computer can't work with NewOS, please use Mahrouss-"
+ L"Logic products instead\r\nNewBoot.exe: Our website: "
+ L"www.el-mahrouss-logic.com\r\n");
return kEfiFail;
}
-#else
- Char namePart[kEPMNameLength] = {"BootBlock"};
-
- /// tries to read an EPM block, or writes one if it fails.
- isIniNotFound =
- boot_write_epm_partition(namePart, kEPMNameLength, &ataDrv);
-#endif // !__DEBUG__
/// Read Kernel blob.
@@ -76,16 +64,16 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
if (kernelImg.Error() == BFileReader::kOperationOkay) {
UInt32 MapKey = 0;
- UInt32* Size;
- EfiMemoryDescriptor* Descriptor;
+ UInt32* SizePtr = nullptr;
+ EfiMemoryDescriptor* Descriptor = nullptr;
UInt32 SzDesc = 0;
UInt32 RevDesc = 0;
- if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&Size) !=
+ if (BS->AllocatePool(EfiLoaderData, sizeof(UInt32), (VoidPtr*)&SizePtr) !=
kEfiOk) {
EFI::RaiseHardError(
- L"NewBoot-BadAlloc",
- L"NewBoot ran out of memory! Please check your specs.");
+ L"__bad_alloc",
+ L"NewBoot ran out of memory!");
}
/****
@@ -94,13 +82,13 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
*
*/
- *Size = sizeof(EfiMemoryDescriptor);
+ *SizePtr = sizeof(EfiMemoryDescriptor);
if (BS->AllocatePool(EfiLoaderData, sizeof(EfiMemoryDescriptor),
(VoidPtr*)&Descriptor) != kEfiOk) {
EFI::RaiseHardError(
- L"NewBoot-BadAlloc",
- L"NewBoot ran out of memory! Please check your specs.");
+ L"__bad_alloc",
+ L"NewBoot ran out of memory!");
}
/****
@@ -109,11 +97,8 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
*
*/
- if (BS->GetMemoryMap(Size, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
- kEfiOk) {
- EFI::RaiseHardError(L"NewBoot-GetMemoryMap",
- L"GetMemoryMap returned a value which isn't kEfiOk!");
- }
+ while (BS->GetMemoryMap(SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc) !=
+ kEfiOk);
HEL::HandoverInformationHeader* handoverHdrPtr = nullptr;
@@ -157,9 +142,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
handoverHdrPtr->f_HardwareTables.f_RsdPtr = (VoidPtr)vendorTable;
#ifdef __DEBUG__
- writer
- .Write(
- L"NewOS: Found ACPI's 'RSD PTR' table on this machine.")
+ writer.Write(L"NewOS: Found ACPI's 'RSD PTR' table on this machine.")
.Write(L"\r\n");
#endif
@@ -167,22 +150,19 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
}
}
- if (!isIniNotFound) {
+ if (!isEpmFound) {
writer.Write(L"NewOS: No partition found for NewOS. (HCR-1000)\r\n");
- } else {
- handoverHdrPtr->f_Magic = kHandoverMagic;
- handoverHdrPtr->f_Version = kHandoverVersion;
+ }
- writer.Write(L"NewOS: Starting kernel...\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);
- EFI::Stop();
+ /// TODO: Read catalog and read NewKernel.exe
- return kEfiOk;
} else {
writer.Write(L"NewOS: Error-Code: HLDR-0003\r\n");
}
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
index 08a6979f..b27654cb 100644
--- a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
+++ b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx
@@ -4,12 +4,14 @@
------------------------------------------- */
-extern "C" void rt_halt() { asm volatile("hlt"); }
+#include <BootKit/BootKit.hxx>
-extern "C" void rt_cli() { asm volatile("cli"); }
+EXTERN_C void rt_hlt() { asm volatile("hlt"); }
-extern "C" void rt_sti() { asm volatile("sti"); }
+EXTERN_C void rt_cli() { asm volatile("cli"); }
-extern "C" void rt_cld() { asm volatile("cld"); }
+EXTERN_C void rt_sti() { asm volatile("sti"); }
-extern "C" void rt_std() { asm volatile("std"); } \ No newline at end of file
+EXTERN_C void rt_cld() { asm volatile("cld"); }
+
+EXTERN_C void rt_std() { asm volatile("std"); } \ No newline at end of file
diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx b/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
new file mode 100644
index 00000000..55e334f7
--- /dev/null
+++ b/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx
@@ -0,0 +1,119 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <BootKit/BootKit.hxx>
+#include <FSKit/NewFS.hxx>
+
+#define kEPMSectorSize 1024
+
+#define kSwapSize MIB(16)
+
+// {310E1FC7-2060-425D-BE7B-75A37CC679BC}
+STATIC const BlockGUID kEPMGuid = {
+ 0x310e1fc7,
+ 0x2060,
+ 0x425d,
+ {0xbe, 0x7b, 0x75, 0xa3, 0x7c, 0xc6, 0x79, 0xbc}};
+
+/// @brief Write epm partition to disk.
+/// @param namePart partition name
+/// @param namePartLength length of name
+/// @param bootDev disk interface.
+/// @return
+EXTERN_C Boolean boot_write_epm_partition(const Char* namePart, SizeT namePartLength,
+ BootDevice* bootDev) {
+ if (namePartLength > kEPMNameLength || !namePart) return No;
+ if (!bootDev) return No;
+
+ bootDev->Leak().mBase = kEPMStartPartitionBlk;
+ bootDev->Leak().mSize = kEPMSectorSize;
+
+ Char buf[kEPMSectorSize] = {0};
+
+ bootDev->Read(buf, 1);
+
+ BTextWriter writer;
+
+ writer.Write(L"NewOS: Checking for a NewFS partition...\r\n");
+
+ for (SizeT index = 0; index < kEPMMagicLength; ++index) {
+ if (buf[index] != kEPMMagic[index]) {
+ writer.Write(L"NewOS: Writing a NewFS partition...\r\n");
+
+ BootBlockType* bootBlock = (BootBlockType*)buf;
+
+ bootBlock->Version = kEPMRevision;
+ bootBlock->NumBlocks = 2;
+
+ for (SizeT i = 0; i < kEPMNameLength; ++i) {
+ bootBlock->Magic[i] = kEPMMagic[i];
+ }
+
+ for (SizeT i = 0; i < namePartLength; ++i) {
+ bootBlock->Name[i] = namePart[i];
+ }
+
+ bootBlock->LbaStart =
+ sizeof(BootBlockType) + (sizeof(PartitionBlockType) * kEPMMaxBlks);
+
+ bootBlock->SectorSz = kEPMSectorSize;
+
+ bootBlock->Uuid = kEPMGuid;
+
+ PartitionBlock* partBlock = (PartitionBlock*)(buf + sizeof(BootBlock));
+
+ char* fsName = "NewFS";
+ int fsNameLength = 6;
+
+ for (SizeT i = 0; i < fsNameLength; ++i) {
+ partBlock->Fs[i] = fsName[i];
+ }
+
+ partBlock->Version = kEPMNewOS;
+
+ char* partName = "System HD";
+ int partNameLength = 10;
+
+ for (SizeT i = 0; i < partNameLength; ++i) {
+ partBlock->Name[i] = partName[i];
+ }
+
+ partBlock->SectorSz = kEPMSectorSize;
+ partBlock->LbaStart = kEPMStartPartitionBlk + kSwapSize;
+ partBlock->Version = kNewFSVersionInteger;
+ partBlock->Kind = kNewFSPartitionTypeStandard;
+ partBlock->LbaEnd = 0UL; ///! grows on the disk.
+
+ PartitionBlock* swapBlock = (PartitionBlock*)(buf + sizeof(BootBlock) + sizeof(PartitionBlock));
+
+ for (SizeT i = 0; i < fsNameLength; ++i) {
+ swapBlock->Fs[i] = fsName[i];
+ }
+
+ swapBlock->Version = kEPMNewOS;
+
+ partName = "Swap HD";
+ partNameLength = 8;
+
+ for (SizeT i = 0; i < partNameLength; ++i) {
+ swapBlock->Name[i] = partName[i];
+ }
+
+ swapBlock->SectorSz = kEPMSectorSize;
+ swapBlock->LbaStart = kEPMStartPartitionBlk;
+ swapBlock->Version = kNewFSVersionInteger;
+ swapBlock->Kind = kNewFSPartitionTypePage;
+ swapBlock->LbaEnd = kSwapSize; /// 4 MIB swap partition.
+
+ bootDev->Write(buf, 1);
+
+ return No;
+ }
+ }
+
+ writer.Write(L"NewOS: Partition found, everything's OK.\r\n");
+ return Yes;
+} \ No newline at end of file
diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S b/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
index 87b87bab..876a29fe 100644
--- a/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
+++ b/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S
@@ -19,4 +19,4 @@ k_hdr_ver:
k_hdr_proc:
.long __bootloader_start
-/* end */ \ No newline at end of file
+/* NewOS kernel header end */ \ No newline at end of file
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 4f076580..7fc566b6 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -37,6 +37,7 @@ all: compile-amd64
$(LD_GNU) $(OBJ) $(LD_FLAGS) -o NewBoot.exe
$(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI
$(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI
+ $(COPY) ../../Root/Boot/NewKernel.exe CDROM/
ifneq ($(DEBUG_SUPPORT), )
DEBUG = -D__DEBUG__
diff --git a/Private/NewBoot/Source/download-edk.ps1 b/Private/NewBoot/Source/ovmf.ps1
index 5a2c5f0e..5a2c5f0e 100644
--- a/Private/NewBoot/Source/download-edk.ps1
+++ b/Private/NewBoot/Source/ovmf.ps1