diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-26 08:13:03 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-26 08:13:03 +0200 |
| commit | 3b4a4a290b32fdb4a749b3e581afae450eb543c8 (patch) | |
| tree | fc9278f51212e73f75f02942ad05abfaee64ca68 /Private/NewBoot/Source | |
| parent | 9679735cb60011490c92fd8d3b13d337120a22ea (diff) | |
MHR-16: NewBoot - BDiskFormatter and QR.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewBoot/Source')
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootATA.cxx | 26 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootJump.S | 9 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 94 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx | 11 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 13 |
6 files changed, 95 insertions, 60 deletions
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index 10d4272d..8d923a50 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -132,7 +132,7 @@ ATAInit_Retry: Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size) { - UInt8 Command = (!Master ? 0xE0 : 0xF0); + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); boot_ata_wait_io(IO); @@ -146,27 +146,15 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - while ((In8(ATA_COMMAND(IO))) & ATA_SR_BSY) boot_ata_wait_io(IO); - - UInt16 byte = In16(IO + ATA_REG_DATA); - SizeT IndexOff = 0UL; - Buf[IndexOff] = byte; - - while (byte != 0xFF) { - if (IndexOff > Size) break; - - ++IndexOff; - - while ((In8(ATA_COMMAND(IO))) & ATA_SR_BSY) boot_ata_wait_io(IO); - - byte = In16(IO + ATA_REG_DATA); - Buf[IndexOff] = byte; + for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { + boot_ata_wait_io(IO); + Buf[IndexOff] = In16(IO + ATA_REG_DATA); } } Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size) { - UInt8 Command = (!Master ? 0xE0 : 0xF0); + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); boot_ata_wait_io(IO); @@ -209,10 +197,6 @@ BootDeviceATA::BootDeviceATA() noexcept { boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, this->Leak().mMaster)) { kATADetected = true; - - BTextWriter writer; - - writer.Write(L"New Boot: Drive is OnLine.\r\n"); } } /** diff --git a/Private/NewBoot/Source/HEL/AMD64/BootJump.S b/Private/NewBoot/Source/HEL/AMD64/BootJump.S new file mode 100644 index 00000000..af278cc7 --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/BootJump.S @@ -0,0 +1,9 @@ +.global rt_jump_to_address +.text + +.code64 +.intel_syntax noprefix + +rt_jump_to_address: + jmp rcx + ret diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index 356db88b..ea3fcbf0 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -9,8 +9,15 @@ #include <FirmwareKit/EFI.hxx> #include <KernelKit/MSDOS.hpp> #include <KernelKit/PEF.hpp> -#include <NewKit/Ref.hpp> +#include <NewKit/Macros.hpp> #include <BootKit/BootKit.hxx> +#include <NewKit/Ref.hpp> +#include <cstring> + +/// make the compiler shut up. +#ifndef kMachineModel +#define kMachineModel "NeWS HD" +#endif // !kMachineModel /** Graphics related. */ @@ -18,6 +25,8 @@ STATIC EfiGraphicsOutputProtocol* kGop = nullptr; STATIC UInt16 kStride = 0U; STATIC EfiGUID kGopGuid; +EXTERN_C Void rt_jump_to_address(VoidPtr blob); + /** @brief Finds and stores the GOP. */ @@ -166,45 +175,66 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, } } - BFileReader kernelFile(L"NewLoader.exe", ImageHandle); - kernelFile.ReadAll(MIB(1), 4096); + /// + /// The following checks for an exisiting partition + /// inside the disk, if it doesn't have one, + /// format the disk. + // - if (kernelFile.Blob()) { - PEFContainer* containerKind = - reinterpret_cast<PEFContainer*>(kernelFile.Blob()); + /// need this as well, to invoke BExecutableLoader. + BFileReader readerKernel(L"NewKernel.exe", ImageHandle); + readerKernel.ReadAll(MIB(1), 4096); - if (containerKind->Magic[0] == kPefMagic[0] && - containerKind->Magic[1] == kPefMagic[1] && - containerKind->Magic[2] == kPefMagic[2] && - containerKind->Magic[3] == kPefMagic[3] && - containerKind->Magic[4] == kPefMagic[4]) { - if (containerKind->Abi != kPefAbi || - containerKind->Cpu != kPefArchAMD64) { - EFI::ThrowError(L"Bad-Architecture", - L"New Boot can't run this architecture."); - } + BDiskFormatFactory<BootDeviceATA> diskFormatter; - NewOS::HEL::BootMainKind main = - reinterpret_cast<NewOS::HEL::BootMainKind>(containerKind + - containerKind->Start); + BDiskFormatFactory<BootDeviceATA>::BFileDescriptor rootDesc{0}; - if (!main) { - EFI::ThrowError(L"Bad-Exec", - L"New Boot can't recognize this executable."); - } + memcpy(rootDesc.fFileName, "/", strlen("/")); + memcpy(rootDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork)); - EFI::ExitBootServices(MapKey, ImageHandle); + rootDesc.fBlobSz = strlen(kMachineModel " startup disk."); + rootDesc.fBlob = new Char[rootDesc.fBlobSz]; - main(handoverHdrPtr); + memcpy(rootDesc.fBlob, kMachineModel " startup disk.", + strlen(kMachineModel " startup disk.")); - EFI::Stop(); + rootDesc.fKind = kNewFSCatalogKindDir; - CANT_REACH(); - } - } + BDiskFormatFactory<BootDeviceATA>::BFileDescriptor bootDesc{0}; + + bootDesc.fKind = kNewFSCatalogKindDir; + + memcpy(bootDesc.fFileName, "/Boot", strlen("/Boot")); + memcpy(bootDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork)); + memcpy(bootDesc.fBlob, kMachineModel " startup folder.", + strlen(kMachineModel " startup folder.")); + + bootDesc.fBlobSz = strlen(kMachineModel " startup folder."); + bootDesc.fBlob = new Char[bootDesc.fBlobSz]; + + BDiskFormatFactory<BootDeviceATA>::BFileDescriptor kernelDesc{0}; + + kernelDesc.fKind = kNewFSCatalogKindFile; + + memcpy(kernelDesc.fFileName, "/Boot/NewKernel", strlen("/Boot/NewKernel")); + memcpy(kernelDesc.fForkName, kNewFSDataFork, strlen(kNewFSDataFork)); + + kernelDesc.fBlob = readerKernel.Blob(); + kernelDesc.fBlobSz = readerKernel.Size(); + + rootDesc.fNext = &bootDesc; + rootDesc.fNext->fPrev = &rootDesc; + + rootDesc.fNext->fNext = &kernelDesc; + rootDesc.fNext->fNext->fPrev = &bootDesc; + + diskFormatter.Format(kMachineModel, &rootDesc, 3); + + EFI::ExitBootServices(MapKey, ImageHandle); + + rt_jump_to_address(readerKernel.Blob()); - EFI::ThrowError(L"Invalid-PEF-Executable", - L"PEF executable expected. Got something else."); + EFI::Stop(); - return kEfiFail; + CANT_REACH(); } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx index 81aa6c9d..ff30ff95 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx @@ -32,7 +32,7 @@ BTextWriter &BTextWriter::Write(const CharacterTypeUTF16 *str) { return *this; } -BTextWriter &BTextWriter::Write(const UChar *str) { +BTextWriter &BTextWriter::Write(const Char *str) { #ifdef __DEBUG__ if (!str || *str == 0) return *this; diff --git a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx index 77552ef8..01911c43 100644 --- a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx @@ -20,6 +20,17 @@ void* operator new(size_t sz) return buf; } +/// @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) diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 93bb5e28..92128b02 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -18,6 +18,10 @@ else EMU=qemu-system-x86_64 endif +ifeq ($(NEWS_MODEL), ) +NEWOS_MODEL=-DkMachineModel="\"Generic NeWS HD\"" +endif + IMG=epm.img IMG_2=epm-slave.img EMU_FLAGS=-net none -smp 4 -m 8G -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 @@ -46,13 +50,10 @@ KERNEL=NewKernel.exe .PHONY: all all: compile-amd64 mkdir -p CDROM/EFI/BOOT - $(LD_GNU) $(OBJ) $(LD_FLAGS) -o $(KERNEL_OBJ) - $(IMG_CREATE) create -f raw $(BOOT_LOADER) $(MAX_KERNEL_SIZE) - $(DD) if=$(KERNEL_OBJ) of=$(BOOT_LOADER) bs=1 seek=0 conv=notrunc + $(LD_GNU) $(OBJ) $(LD_FLAGS) -o $(BOOT_LOADER) $(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), ) DEBUG = -D__DEBUG__ @@ -61,7 +62,7 @@ endif .PHONY: compile-amd64 compile-amd64: $(WINDRES) BootloaderRsrc.rsrc -O coff -o BootloaderRsrc.o - $(CC_GNU) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard *.cxx) + $(CC_GNU) $(NEWOS_MODEL) $(FLAG_GNU) $(DEBUG) $(wildcard HEL/AMD64/*.cxx) $(wildcard HEL/AMD64/*.S) $(wildcard *.cxx) .PHONY: run-efi-amd64 run-efi-amd64: @@ -69,7 +70,7 @@ run-efi-amd64: .PHONY: epm-img epm-img: - qemu-img create -f qcow2 $(IMG) 256M + qemu-img create -f qcow2 $(IMG) 512M qemu-img create -f qcow2 $(IMG_2) 512M .PHONY: download-edk |
