diff options
Diffstat (limited to 'Private/NewBoot')
| -rw-r--r-- | Private/NewBoot/BootKit/Arch/AHCI.hxx | 38 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/Arch/ATA.hxx | 4 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/Arch/SATA.hxx | 38 | ||||
| -rw-r--r-- | Private/NewBoot/Source/BootMain.cxx | 38 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/AMD64-AHCI.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx | 49 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 2 |
7 files changed, 78 insertions, 93 deletions
diff --git a/Private/NewBoot/BootKit/Arch/AHCI.hxx b/Private/NewBoot/BootKit/Arch/AHCI.hxx deleted file mode 100644 index 9505377b..00000000 --- a/Private/NewBoot/BootKit/Arch/AHCI.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <CompilerKit/CompilerKit.hxx> -#include <Drivers/AHCI/Defines.hxx> - -class BDeviceAHCI final { - public: - explicit BDeviceAHCI() noexcept; - ~BDeviceAHCI() = default; - - HCORE_COPY_DEFAULT(BDeviceAHCI); - - struct AHCITraits final { - HCore::SizeT fBase{1024}; - HCore::Boolean fError{false}; - HCore::Boolean fDetected{false}; - - operator bool() { return !this->fError; } - }; - - operator bool() { return this->Leak().fDetected; } - - BDeviceAHCI& Read(HCore::WideChar* Buf, const HCore::SizeT& SecCount); - BDeviceAHCI& Write(HCore::WideChar* Buf, const HCore::SizeT& SecCount); - - AHCITraits& Leak(); - - private: - AHCITraits mTraits; -}; - -#define kAHCISectorSz 512 diff --git a/Private/NewBoot/BootKit/Arch/ATA.hxx b/Private/NewBoot/BootKit/Arch/ATA.hxx index 3370fdba..15d36317 100644 --- a/Private/NewBoot/BootKit/Arch/ATA.hxx +++ b/Private/NewBoot/BootKit/Arch/ATA.hxx @@ -8,8 +8,6 @@ #include <Drivers/ATA/Defines.hxx> -Boolean IsATADetected(Void); - class BDeviceATA final { public: enum { @@ -31,7 +29,7 @@ class BDeviceATA final { operator bool() { return !mErr; } }; - operator bool() { return IsATADetected(); } + operator bool(); BDeviceATA& Read(WideChar* Buf, const SizeT& SecCount); BDeviceATA& Write(WideChar* Buf, const SizeT& SecCount); diff --git a/Private/NewBoot/BootKit/Arch/SATA.hxx b/Private/NewBoot/BootKit/Arch/SATA.hxx new file mode 100644 index 00000000..3e37be19 --- /dev/null +++ b/Private/NewBoot/BootKit/Arch/SATA.hxx @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <CompilerKit/CompilerKit.hxx> +#include <Drivers/AHCI/Defines.hxx> + +class BDeviceSATA final { + public: + explicit BDeviceSATA() noexcept; + ~BDeviceSATA() = default; + + HCORE_COPY_DEFAULT(BDeviceSATA); + + struct AHCITraits final { + HCore::SizeT mBase{1024}; + HCore::Boolean mErr{false}; + HCore::Boolean mDetected{false}; + + operator bool() { return !this->mErr; } + }; + + operator bool() { return this->Leak().mDetected; } + + BDeviceSATA& Read(HCore::WideChar* Buf, const HCore::SizeT& SecCount); + BDeviceSATA& Write(HCore::WideChar* Buf, const HCore::SizeT& SecCount); + + AHCITraits& Leak(); + + private: + AHCITraits mTraits; +}; + +#define kAHCISectorSz 512 diff --git a/Private/NewBoot/Source/BootMain.cxx b/Private/NewBoot/Source/BootMain.cxx index 829c98ad..650196f6 100644 --- a/Private/NewBoot/Source/BootMain.cxx +++ b/Private/NewBoot/Source/BootMain.cxx @@ -35,9 +35,8 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, /// Splash screen stuff - writer.Write(L"MahroussLogic (R) HCoreLdr: "); - - writer.Write(BVersionString::Shared()).Write(L"\r\n"); + writer.Write(L"MahroussLogic (R) HCoreLdr: ") + .Write(BVersionString::Shared()).Write(L"\r\n"); const char strDate[] = __DATE__; @@ -98,34 +97,11 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, .Write(ptrHdr->mNumberOfSections * sizeof(ExecSectionHeader)) .Write(L"\r\n"); - volatile ALIGN(kPTEAlign) ExecSectionHeader* blobKrnl = - (ExecSectionHeader*)(reinterpret_cast<DosHeaderPtr>(blob) + - reinterpret_cast<DosHeaderPtr>(blob)->eLfanew + - ptrHdr->mSizeOfOptionalHeader + - (sizeof(ExecHeader) + - sizeof(ExecOptionalHeader) + sizeof(UInt32))); - - while (blobKrnl->mCharacteristics != 0x00000020) { - blobKrnl = blobKrnl + sizeof(ExecSectionHeader); - } - - writer.Write(L"HCoreLdr: Exec Timestamp: ") - .Write(ptrHdr->mTimeDateStamp) - .Write(L"\r\n"); + ExecSectionHeader* blobKrnl = + (ExecSectionHeader*)(&optHdr + sizeof(ExecOptionalHeader) + sizeof(UInt32)); for (size_t i = 0; i < ptrHdr->mNumberOfSections; i++) { - writer.Write(L"HCoreLdr: Virtual-Size: ") - .Write(blobKrnl[i].mVirtualSize) - .Write(L"\r\n"); - writer.Write(L"HCoreLdr: Virtual-Address: ") - .Write(blobKrnl[i].mVirtualAddress) - .Write(L"\r\n"); - writer.Write(L"HCoreLdr: Raw-Address: ") - .Write(blobKrnl[i].mPointerToRawData) - .Write(L"\r\n"); - writer.Write(L"HCoreLdr: Raw-Size: ") - .Write(blobKrnl[i].mSizeOfRawData) - .Write(L"\r\n"); + // TODO: parse PE information here. } UInt32 MapKey = 0; @@ -143,7 +119,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, /**** * - * LOAD KERNEL CODE + * Load kernel into memory. * */ @@ -158,7 +134,7 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, /**** * - * GET MEMORY MAP OF COMPUTER. + * Get machine memory map. * */ diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-AHCI.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-AHCI.cxx index dbb0bde4..be7010a8 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-AHCI.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-AHCI.cxx @@ -15,4 +15,4 @@ * */ -#include <BootKit/Arch/AHCI.hxx> +#include <BootKit/Arch/SATA.hxx> diff --git a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx index 551b0200..145976c1 100644 --- a/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/AMD64-ATA.cxx @@ -26,7 +26,9 @@ static Boolean kATADetected = false; static Int32 kATADeviceType = kATADeviceCount; static CharacterType kATAData[kATADataLen] = {0}; -STATIC Boolean ATAWaitForIO(UInt16 IO) { +Boolean boot_ata_detected(Void); + +STATIC Boolean boot_ata_wait_io(UInt16 IO) { for (int i = 0; i < 4; i++) In8(IO + ATA_REG_STATUS); ATAWaitForIO_Retry: @@ -51,9 +53,9 @@ Void ATASelect(UInt16 Bus) { Out8(Bus + ATA_REG_HDDEVSEL, ATA_SECONDARY_SEL); } -Boolean ATAInitDriver(UInt16 Bus, UInt8 Drive, UInt16& OutBus, +Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt8& OutMaster) { - if (IsATADetected()) return false; + if (boot_ata_detected()) return false; BTextWriter writer; @@ -135,7 +137,7 @@ ATAInit_Retry: return true; } -Void ATAReadLba(UInt32 Lba, UInt8 IO, UInt8 Master, CharacterType* Buf, +Void boot_ata_read(UInt32 Lba, UInt8 IO, UInt8 Master, CharacterType* Buf, SizeT Offset) { UInt8 Command = (Master ? 0xE0 : 0xF0); @@ -150,12 +152,12 @@ Void ATAReadLba(UInt32 Lba, UInt8 IO, UInt8 Master, CharacterType* Buf, Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - for (SizeT i = 0; i < 256; ++i) { - Buf[Offset + i] = In16(IO + ATA_REG_DATA); + for (SizeT IndexOff = 0; IndexOff < 256; ++IndexOff) { + Buf[Offset + IndexOff] = In16(IO + ATA_REG_DATA); } } -Void ATAWriteLba(UInt32 Lba, UInt8 IO, UInt8 Master, wchar_t* Buf, +Void boot_ata_write(UInt32 Lba, UInt8 IO, UInt8 Master, CharacterType* Buf, SizeT Offset) { UInt8 Command = (Master ? 0xE0 : 0xF0); @@ -170,13 +172,13 @@ Void ATAWriteLba(UInt32 Lba, UInt8 IO, UInt8 Master, wchar_t* Buf, Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - for (SizeT i = 0; i < 256; ++i) { - Out16(IO + ATA_REG_DATA, Buf[Offset + i]); + for (SizeT IndexOff = 0; IndexOff < 256; ++IndexOff) { + Out16(IO + ATA_REG_DATA, Buf[Offset + IndexOff]); } } /// @check is ATA detected? -Boolean IsATADetected(Void) { return kATADetected; } +Boolean boot_ata_detected(Void) { return kATADetected; } /*** * @@ -191,15 +193,15 @@ Boolean IsATADetected(Void) { return kATADetected; } * @param void none. */ BDeviceATA::BDeviceATA() noexcept { - if (IsATADetected()) return; + if (boot_ata_detected()) return; - if (ATAInitDriver(ATA_PRIMARY_IO, true, this->Leak().mBus, + if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus, this->Leak().mMaster) || - ATAInitDriver(ATA_PRIMARY_IO, false, this->Leak().mBus, + boot_ata_init(ATA_PRIMARY_IO, false, this->Leak().mBus, this->Leak().mMaster) || - ATAInitDriver(ATA_SECONDARY_IO, true, this->Leak().mBus, + boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, this->Leak().mMaster) || - ATAInitDriver(ATA_SECONDARY_IO, false, this->Leak().mBus, + boot_ata_init(ATA_SECONDARY_IO, false, this->Leak().mBus, this->Leak().mMaster)) { kATADetected = true; @@ -207,6 +209,10 @@ BDeviceATA::BDeviceATA() noexcept { writer.Write(L"HCoreLdr: Driver: OnLine.\r\n"); } } +/** + * @brief Is ATA detected? +*/ +BDeviceATA::operator bool() { return boot_ata_detected(); } /** @brief Read Buf from disk @@ -214,7 +220,7 @@ BDeviceATA::BDeviceATA() noexcept { @param Buf buffer */ BDeviceATA& BDeviceATA::Read(CharacterType* Buf, const SizeT& SectorSz) { - if (!IsATADetected()) { + if (!boot_ata_detected()) { Leak().mErr = true; return *this; } @@ -224,8 +230,11 @@ BDeviceATA& BDeviceATA::Read(CharacterType* Buf, const SizeT& SectorSz) { if (!Buf || SectorSz < 1) return *this; for (SizeT i = 0UL; i < SectorSz; ++i) { - ATAReadLba(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster, + boot_ata_read(this->Leak().mBase + i, + this->Leak().mBus, this->Leak().mMaster, Buf, i); + + boot_ata_wait_io(this->Leak().mBus); } return *this; @@ -237,7 +246,7 @@ BDeviceATA& BDeviceATA::Read(CharacterType* Buf, const SizeT& SectorSz) { @param Buf buffer */ BDeviceATA& BDeviceATA::Write(CharacterType* Buf, const SizeT& SectorSz) { - if (!IsATADetected()) { + if (!boot_ata_detected()) { Leak().mErr = true; return *this; } @@ -249,10 +258,12 @@ BDeviceATA& BDeviceATA::Write(CharacterType* Buf, const SizeT& SectorSz) { SizeT Off = 0UL; for (SizeT i = 0UL; i < SectorSz; ++i) { - ATAWriteLba(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster, + boot_ata_write(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster, Buf, Off); Off += kATASectorSz; + + boot_ata_wait_io(this->Leak().mBus); } return *this; diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 5e25496b..511a4894 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -35,7 +35,7 @@ bootloader-amd64: .PHONY: run-efi-amd64 run-efi-amd64: - $(EMU) -net none -smp 2 -m 4G -M pc -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio + $(EMU) -net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio .PHONY: download-edk download-edk: |
