diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-04-28 15:13:03 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-04-28 15:13:03 +0000 |
| commit | 14f10cc0b35155ddb19ec9069ebb884246e61dcf (patch) | |
| tree | a988617d1c511cf04eb2c2392829a37d82a59e2e /Private/NewBoot/Source | |
| parent | db0681412191dcceb5aa99cf31fb8339d6bc4adb (diff) | |
| parent | 346558208d39a036effe3a4ec232fa5df5a3c8e7 (diff) | |
Merged in MHR-18 (pull request #8)
MHR-18: A lot of fixes and improvements, mostly related to disk I/O and kernel stability.
Diffstat (limited to 'Private/NewBoot/Source')
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootATA.cxx | 22 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 28 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/Support.cxx | 16 | ||||
| -rw-r--r-- | Private/NewBoot/Source/compile_flags.txt | 1 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 4 |
7 files changed, 44 insertions, 31 deletions
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index 8ab7dc20..d6b5542c 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -88,7 +88,7 @@ ATAInit_Retry: boot_ata_wait_io(IO); for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { - kATAData[indexData] = In8(IO + ATA_REG_DATA); + kATAData[indexData] = In16(IO + ATA_REG_DATA); } OutBus = @@ -107,18 +107,22 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, boot_ata_select(IO); Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, 1); + + Out8(IO + ATA_REG_SEC_COUNT0, 2); Out8(IO + ATA_REG_LBA0, (Lba)); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA4, (Lba) >> 24); + Out8(IO + ATA_REG_LBA3, (Lba) >> 24); Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); + boot_ata_wait_io(IO); + for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { boot_ata_wait_io(IO); Buf[IndexOff] = In16(IO + ATA_REG_DATA); + boot_ata_wait_io(IO); } } @@ -130,18 +134,22 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, boot_ata_select(IO); Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); - Out8(IO + ATA_REG_SEC_COUNT0, 1); + + Out8(IO + ATA_REG_SEC_COUNT0, 2); Out8(IO + ATA_REG_LBA0, (Lba)); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA4, (Lba) >> 24); + Out8(IO + ATA_REG_LBA3, (Lba) >> 24); Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); + boot_ata_wait_io(IO); + for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { boot_ata_wait_io(IO); Out16(IO + ATA_REG_DATA, Buf[IndexOff]); + boot_ata_wait_io(IO); } } @@ -188,7 +196,7 @@ BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz if (!Buf || SectorSz < 1) return *this; - auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize; + auto lba = this->Leak().mBase / SectorSz; boot_ata_read(lba, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, this->Leak().mSize); @@ -211,7 +219,7 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS if (!Buf || SectorSz < 1) return *this; - auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize; + auto lba = this->Leak().mBase / SectorSz; boot_ata_write(lba, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, this->Leak().mSize); diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index 558bf001..2939c182 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -12,6 +12,7 @@ #include <NewKit/Macros.hpp> #include <BootKit/BootKit.hxx> #include <NewKit/Ref.hpp> +#include <FirmwareKit/Handover.hxx> #include <cstring> /// make the compiler shut up. @@ -21,13 +22,11 @@ /** Graphics related. */ -EXTERN_C Void hal_init_platform(HEL::HandoverInformationHeader* HIH); - STATIC EfiGraphicsOutputProtocol* kGop = nullptr; STATIC UInt16 kStride = 0U; STATIC EfiGUID kGopGuid; -EXTERN_C Void rt_jump_to_address(VoidPtr blob); +EXTERN_C Void hal_init_platform(HEL::HandoverInformationHeader* HIH); /** @brief Finds and stores the GOP. @@ -66,7 +65,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, writer.Write(L"Mahrouss-Logic (R) New Boot: ") .Write(BVersionString::Shared()); - writer.Write(L"\r\nNewBoot: Firmware Vendor: ") + writer.Write(L"\r\nNew Boot: Firmware Vendor: ") .Write(SystemTable->FirmwareVendor) .Write(L"\r\n"); @@ -76,6 +75,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, UInt32* SzDesc = new UInt32(); UInt32* RevDesc = new UInt32(); + *MapKey = 0; *SizePtr = sizeof(EfiMemoryDescriptor); HEL::HandoverInformationHeader* handoverHdrPtr = new HEL::HandoverInformationHeader(); @@ -125,19 +125,12 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, ToolboxClearRsrc(); - EfiPhysicalAddress* whereAddress = - reinterpret_cast<EfiPhysicalAddress*>(kBootVirtualAddress); - BS->GetMemoryMap(SizePtr, Descriptor, MapKey, SzDesc, RevDesc); handoverHdrPtr->f_PhysicalStart = (VoidPtr)Descriptor->PhysicalStart; - handoverHdrPtr->f_FirmwareSpecific[0] = Descriptor->Attribute; - handoverHdrPtr->f_FirmwareSpecific[1] = Descriptor->Kind; - - - BS->AllocatePages(EfiAllocateType::AllocateAnyPages, - EfiMemoryType::EfiConventionalMemory, 1, whereAddress); + handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificAttrib] = Descriptor->Attribute; + handoverHdrPtr->f_FirmwareSpecific[HEL::kHandoverSpecificKind] = Descriptor->Kind; handoverHdrPtr->f_VirtualStart = (VoidPtr)Descriptor->VirtualStart; handoverHdrPtr->f_VirtualSize = Descriptor->NumberOfPages; /* # of pages */ @@ -170,7 +163,9 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, BDiskFormatFactory<BootDeviceATA> diskFormatter; - if (!diskFormatter) { + /// if not formated yet, then format it with the following folders: + /// /, /Boot, /Applications. + if (!diskFormatter.IsPartitionValid()) { BDiskFormatFactory<BootDeviceATA>::BFileDescriptor rootDesc{0}; memcpy(rootDesc.fFileName, "/", strlen("/")); @@ -178,6 +173,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, rootDesc.fBlobSz = BootDeviceATA::kSectorSize; rootDesc.fBlob = new Char[rootDesc.fBlobSz]; + rootDesc.fParent = &rootDesc; memset(rootDesc.fBlob, 0, rootDesc.fBlobSz); @@ -195,6 +191,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, bootDesc.fBlobSz = BootDeviceATA::kSectorSize; bootDesc.fBlob = new Char[bootDesc.fBlobSz]; + bootDesc.fParent = &rootDesc; memset(bootDesc.fBlob, 0, bootDesc.fBlobSz); @@ -213,6 +210,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, appDesc.fBlobSz = BootDeviceATA::kSectorSize; appDesc.fBlob = new Char[appDesc.fBlobSz]; + appDesc.fParent = &rootDesc; memset(appDesc.fBlob, 0, appDesc.fBlobSz); @@ -229,7 +227,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, EFI::ExitBootServices(*MapKey, ImageHandle); - hal_init_platform(kHandoverHeader); + hal_init_platform(handoverHdrPtr); EFI::Stop(); diff --git a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx index 2ac90dd8..fa735142 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootPlatform.cxx @@ -9,7 +9,7 @@ #include <BootKit/BootKit.hxx> #include "HALKit/AMD64/Processor.hpp" -#if 0 +#ifdef __STANDALONE__ EXTERN_C void rt_hlt() { asm volatile("hlt"); } diff --git a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx index 909ccca6..8d811bd9 100644 --- a/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/New+Delete.cxx @@ -9,7 +9,7 @@ #include <BootKit/BootKit.hxx> #include <cstddef> /* Since we're using GCC for this EFI program. */ -#if 0 +#ifdef __STANDALONE__ /// @brief Allocates a new object. /// @param sz the size. diff --git a/Private/NewBoot/Source/HEL/AMD64/Support.cxx b/Private/NewBoot/Source/HEL/AMD64/Support.cxx index a8e2c275..3a6974bb 100644 --- a/Private/NewBoot/Source/HEL/AMD64/Support.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/Support.cxx @@ -8,7 +8,7 @@ #include <FirmwareKit/Handover.hxx> #include <BootKit/Vendor/Support.hxx> -#if 0 +#ifdef __STANDALONE__ /// @brief memset definition in C++. /// @param dst destination pointer. @@ -16,8 +16,11 @@ /// @param len length of of src. EXTERN_C VoidPtr memset(void *dst, int byte, long long unsigned int len) { - SetMem(dst, byte, len); - return dst; + for (size_t i = 0UL; i < len; ++i) { + ((int*)dst)[i] = byte; + } + + return dst; } /// @brief memcpy definition in C++. @@ -26,8 +29,11 @@ EXTERN_C VoidPtr memset(void *dst, int byte, /// @param len length of of src. EXTERN_C VoidPtr memcpy(void *dst, const void *src, long long unsigned int len) { - CopyMem(dst, src, len); - return dst; + for (size_t i = 0UL; i < len; ++i){ + ((int*)dst)[i] = ((int*)src)[i]; + } + + return dst; } /// @brief strlen definition in C++. diff --git a/Private/NewBoot/Source/compile_flags.txt b/Private/NewBoot/Source/compile_flags.txt index e58d7ab9..c74d22b2 100644 --- a/Private/NewBoot/Source/compile_flags.txt +++ b/Private/NewBoot/Source/compile_flags.txt @@ -1,3 +1,4 @@ -std=c++20 -I../ -I../../ +-D__NEWOS_AMD64__ diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index f3a292c5..9f70d903 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -75,8 +75,8 @@ run-efi-amd64: .PHONY: epm-img epm-img: - qemu-img create -f qcow2 $(IMG) 512M - qemu-img create -f qcow2 $(IMG_2) 512M + qemu-img create -f raw $(IMG) 512M + qemu-img create -f raw $(IMG_2) 512M .PHONY: download-edk download-edk: |
