From 14f26421cc6ebd678c2b5a2a04fe6cdc63ee5d38 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 25 Apr 2024 13:44:36 +0200 Subject: MHR-16: Adding BDiskFormatFactory according to MHR-16, bug fixes and improvements as well. Signed-off-by: Amlal El Mahrouss --- Private/NewBoot/Source/HEL/AMD64/BootATA.cxx | 11 +- Private/NewBoot/Source/HEL/AMD64/Support.cxx | 14 +++ Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S | 34 ------ Private/NewBoot/Source/HEL/POWER/BootEPM.cxx | 118 --------------------- Private/NewBoot/Source/HEL/POWER/CoreBootStartup.S | 34 ++++++ Private/NewBoot/Source/makefile | 5 +- 6 files changed, 59 insertions(+), 157 deletions(-) delete mode 100644 Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S delete mode 100644 Private/NewBoot/Source/HEL/POWER/BootEPM.cxx create mode 100644 Private/NewBoot/Source/HEL/POWER/CoreBootStartup.S (limited to 'Private/NewBoot/Source') diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index d3573064..10d4272d 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -25,7 +25,7 @@ static Boolean kATADetected = false; static Int32 kATADeviceType = kATADeviceCount; -static CharacterTypeUTF8 kATAData[kATADataLen] = {0}; +static UInt16 kATAData[kATADataLen] = {0}; Boolean boot_ata_detected(Void); @@ -82,8 +82,6 @@ ATAInit_Retry: Out8(IO + ATA_REG_COMMAND, ATA_CMD_IDENTIFY); - BSetMem(kATAData, 0, kATADataLen); - /// fetch serial info /// model, speed, number of sectors... @@ -269,3 +267,10 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS * @return BootDeviceATA::ATATrait& the drive config. */ BootDeviceATA::ATATrait& BootDeviceATA::Leak() { return mTrait; } + +/*** + @brief Getter, gets the number of sectors inside the drive. +*/ +SizeT BootDeviceATA::GetSectorsCount() noexcept { + return kATAData[60] + kATAData[61]; +} diff --git a/Private/NewBoot/Source/HEL/AMD64/Support.cxx b/Private/NewBoot/Source/HEL/AMD64/Support.cxx index c6b62630..0508d491 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Support.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Support.cxx @@ -28,5 +28,19 @@ EXTERN_C VoidPtr memcpy(void *dst, const void *src, return dst; } +/// @brief strlen definition in C++. +EXTERN_C size_t strlen(const char *whatToCheck) { + if (!whatToCheck || *whatToCheck == 0) return 0; + + SizeT len = 0; + + while (whatToCheck[len] != 0) { + ++len; + } + + return len; +} + + /// @brief somthing specific to the microsoft ABI, regarding checking the stack. EXTERN_C void ___chkstk_ms(void) {} diff --git a/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S b/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S deleted file mode 100644 index c611467d..00000000 --- a/Private/NewBoot/Source/HEL/POWER/BootCoreBoot.S +++ /dev/null @@ -1,34 +0,0 @@ -/* ------------------------------------------- - - 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 deleted file mode 100644 index 72276ef9..00000000 --- a/Private/NewBoot/Source/HEL/POWER/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/POWER/CoreBootStartup.S b/Private/NewBoot/Source/HEL/POWER/CoreBootStartup.S new file mode 100644 index 00000000..41fc6ae2 --- /dev/null +++ b/Private/NewBoot/Source/HEL/POWER/CoreBootStartup.S @@ -0,0 +1,34 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +.section .boot_hdr +.align 4 + +/* NewBoot boot header begin */ + +boot_hdr_mag: + .ascii "CB" +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/makefile b/Private/NewBoot/Source/makefile index 11c1da75..7ed42abd 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -51,6 +51,7 @@ all: compile-amd64 $(DD) if=$(KERNEL_OBJ) of=$(BOOT_LOADER) bs=1 seek=0 conv=notrunc $(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/BOOTX64.EFI $(COPY) $(BOOT_LOADER) CDROM/EFI/BOOT/NEWBOOT.EFI + $(COPY) ../../$(KERNEL) CDROM/$(KERNEL) $(COPY) $(BOOT_LOADER) ../../Root/Boot/$(BOOT_LOADER) ifneq ($(DEBUG_SUPPORT), ) @@ -68,8 +69,8 @@ run-efi-amd64: .PHONY: epm-img epm-img: - qemu-img create -f raw $(IMG) 256M - qemu-img create -f raw $(IMG_2) 512M + qemu-img create -f qcow2 $(IMG) 256M + qemu-img create -f qcow2 $(IMG_2) 512M .PHONY: download-edk download-edk: -- cgit v1.2.3