From e548e79578d692dce885e7ef3cb38d993e90e07f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 22 Apr 2024 08:19:02 +0200 Subject: MHR-5: A new part of the porting has been done. - Separate makefiles for each targets. - New Toolbox calls as well. - Check for platform to deduce __kernelDispatchCall. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/Source/CDROM/.NEWDEV | 2 - Private/NewBoot/Source/CDROM/.gitkeep | 0 Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep | 0 Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 4 +- Private/NewBoot/Source/HEL/POWER/.gitkeep | 0 Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S | 34 +++++++ Private/NewBoot/Source/HEL/POWER/BootEPM.cxx | 118 +++++++++++++++++++++++ Private/NewBoot/Source/HEL/PowerPC/.gitkeep | 0 Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx | 118 ----------------------- Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S | 34 ------- Private/NewBoot/Source/makefile | 4 +- 11 files changed, 157 insertions(+), 157 deletions(-) delete mode 100644 Private/NewBoot/Source/CDROM/.NEWDEV delete mode 100644 Private/NewBoot/Source/CDROM/.gitkeep delete mode 100644 Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep create mode 100644 Private/NewBoot/Source/HEL/POWER/.gitkeep create mode 100644 Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S create mode 100644 Private/NewBoot/Source/HEL/POWER/BootEPM.cxx delete mode 100644 Private/NewBoot/Source/HEL/PowerPC/.gitkeep delete mode 100644 Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx delete mode 100644 Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S (limited to 'Private/NewBoot/Source') diff --git a/Private/NewBoot/Source/CDROM/.NEWDEV b/Private/NewBoot/Source/CDROM/.NEWDEV deleted file mode 100644 index d5d2badf..00000000 --- a/Private/NewBoot/Source/CDROM/.NEWDEV +++ /dev/null @@ -1,2 +0,0 @@ -[POWER_MANAGEMENT] -ENFORCE_ACPI=YES \ No newline at end of file diff --git a/Private/NewBoot/Source/CDROM/.gitkeep b/Private/NewBoot/Source/CDROM/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep b/Private/NewBoot/Source/CDROM/EFI/BOOT/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index e0d5d8c9..21b1505a 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -59,7 +59,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, .Write(L"\r\n"); BootDeviceATA ataDev; - Boolean isEpmFound = No; + Boolean isGptFound = No; UInt32 MapKey = 0; UInt32* SizePtr = nullptr; @@ -121,7 +121,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, ToolboxInitRsrc(); - ToolboxDrawZone(RGB(20, 20, 20), handoverHdrPtr->f_GOP.f_Height, handoverHdrPtr->f_GOP.f_Width, 0, 0); + ToolboxDrawZone(RGB(FF, FF, FF), handoverHdrPtr->f_GOP.f_Height, handoverHdrPtr->f_GOP.f_Width, 0, 0); ToolboxClearRsrc(); diff --git a/Private/NewBoot/Source/HEL/POWER/.gitkeep b/Private/NewBoot/Source/HEL/POWER/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S b/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S new file mode 100644 index 00000000..c611467d --- /dev/null +++ b/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S @@ -0,0 +1,34 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +.section .boot_hdr +.align 4 + +/* NewBoot boot header begin */ + +boot_hdr_mag: + .ascii "LX" +boot_hdr_name: + // it has to match ten bytes. + .asciz "NewBoot\0\0\0" +boot_hdr_ver: + .word 0x104 +boot_hdr_proc: + .long bootloader_start + +/* NewOS boot header end */ + +.extern bootloader_main +.extern bootloader_stack + +.globl bootloader_start +bootloader_start: + mflr 4 /* real address of .Laddr */ + lwz 0,(bootloader_stack-bootloader_start)(4) /* stack address location */ + mr 1,0 /* use user defined stack */ + + bl bootloader_main + blr diff --git a/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx b/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx new file mode 100644 index 00000000..72276ef9 --- /dev/null +++ b/Private/NewBoot/Source/HEL/POWER/BootEPM.cxx @@ -0,0 +1,118 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include +#include + +#define kEPMSectorSize (1024U) +#define kEPMSwapSize 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"NewBoot: Checking for an EPM partition...\r\n"); + + for (SizeT index = 0; index < kEPMMagicLength; ++index) { + if (buf[index] != kEPMMagic[index]) { + writer.Write(L"NewBoot: Writing an EPM 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 + kEPMSwapSize; + 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 = kEPMSwapSize; /// 4 MIB swap partition. + + bootDev->Write(buf, 1); + + return No; + } + } + + writer.Write(L"NewBoot: Partition found, everything's OK.\r\n"); + return Yes; +} diff --git a/Private/NewBoot/Source/HEL/PowerPC/.gitkeep b/Private/NewBoot/Source/HEL/PowerPC/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx b/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx deleted file mode 100644 index 72276ef9..00000000 --- a/Private/NewBoot/Source/HEL/PowerPC/BootEPM.cxx +++ /dev/null @@ -1,118 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include -#include - -#define kEPMSectorSize (1024U) -#define kEPMSwapSize 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"NewBoot: Checking for an EPM partition...\r\n"); - - for (SizeT index = 0; index < kEPMMagicLength; ++index) { - if (buf[index] != kEPMMagic[index]) { - writer.Write(L"NewBoot: Writing an EPM 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 + kEPMSwapSize; - 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 = kEPMSwapSize; /// 4 MIB swap partition. - - bootDev->Write(buf, 1); - - return No; - } - } - - writer.Write(L"NewBoot: Partition found, everything's OK.\r\n"); - return Yes; -} diff --git a/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S b/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S deleted file mode 100644 index 53d9d4f2..00000000 --- a/Private/NewBoot/Source/HEL/PowerPC/BootPowerPC.S +++ /dev/null @@ -1,34 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -.section .init -.align 4 - -/* NewOS kernel header begin */ - -boot_hdr_mag: - .ascii "LX" -boot_hdr_name: - // it has to match ten bytes. - .asciz "NewBoot\0\0\0" -boot_hdr_ver: - .word 0x104 -boot_hdr_proc: - .long bootloader_start - -/* NewOS kernel header end */ - -.extern bootloader_main -.extern bootloader_stack - -.globl bootloader_start -bootloader_start: - mflr 4 /* real address of .Laddr */ - lwz 0,(bootloader_stack-bootloader_start)(4) /* stack address location */ - mr 1,0 /* use user defined stack */ - - bl bootloader_main - blr diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 25eb04c0..530abea8 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -38,6 +38,7 @@ invalid-recipe: .PHONY: all all: compile-amd64 + mkdir -p CDROM/EFI/BOOT $(LD_GNU) $(OBJ) $(LD_FLAGS) -o NewBoot.exe $(COPY) NewBoot.exe CDROM/EFI/BOOT/BOOTX64.EFI $(COPY) NewBoot.exe CDROM/EFI/BOOT/NEWBOOT.EFI @@ -72,7 +73,8 @@ clean: .PHONY: help help: @echo "=== HELP ===" - @echo "epm-img: Format a disk using the Explicit Partition Map/GPT." + @echo "epm-img: Format a disk using the Explicit Partition Map." + @echo "gpt-img: Format a disk using the Explicit Partition Map." @echo "clean: clean bootloader." @echo "bootloader-amd64: Build bootloader. (PC AMD64)" @echo "run-efi-amd64: Run bootloader. (PC AMD64)" -- cgit v1.2.3