diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-26 10:20:01 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-04-26 10:20:01 +0200 |
| commit | ba80f513dd5cd82feae0b8f794b3367caf9ce8bb (patch) | |
| tree | 7c41759e590047c60cec4c571f3e3b3819cb5797 /Private/NewBoot/Source | |
| parent | 4afe2bd4c6e95f2ca4a5b9bdacf51ef5f91fd0d7 (diff) | |
MHR-16: a lot of fixes. Regarding the disk driver and the filesystem
class BDiskFormatFactory.
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 | 67 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 13 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 2 |
3 files changed, 40 insertions, 42 deletions
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index bb634fbf..41ea04ac 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -88,44 +88,13 @@ ATAInit_Retry: boot_ata_wait_io(IO); for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { - kATAData[indexData] = In16(IO + ATA_REG_DATA); + kATAData[indexData] = In8(IO + ATA_REG_DATA); } OutBus = (Bus == ATA_PRIMARY_IO) ? BootDeviceATA::kPrimary : BootDeviceATA::kSecondary; - OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; - - Out8(Bus + ATA_REG_HDDEVSEL, 0xA0 | ATA_MASTER << 4); - - In8(Bus + ATA_REG_CONTROL); - In8(Bus + ATA_REG_CONTROL); - In8(Bus + ATA_REG_CONTROL); - In8(Bus + ATA_REG_CONTROL); - - unsigned cl = In8(Bus + ATA_CYL_LOW); /* get the "signature bytes" */ - unsigned ch = In8(Bus + ATA_CYL_HIGH); - - /* differentiate ATA, ATAPI, SATA and SATAPI */ - if (cl == 0x14 && ch == 0xEB) { - writer.Write(L"New Boot: PATAPI drive detected.\r\n"); - kATADeviceType = kATADevicePATA_PI; - } - if (cl == 0x69 && ch == 0x96) { - writer.Write(L"New Boot: SATAPI drive detected.\r\n"); - kATADeviceType = kATADeviceSATA_PI; - } - - if (cl == 0x0 && ch == 0x0) { - writer.Write(L"New Boot: PATA drive detected.\r\n"); - kATADeviceType = kATADevicePATA; - } - - if (cl == 0x3c && ch == 0xc3) { - writer.Write(L"New Boot: SATA drive detected.\r\n"); - kATADeviceType = kATADeviceSATA; - } - Out8(IO + ATA_REG_CONTROL, 0x02); + OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; return true; } @@ -137,12 +106,13 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, boot_ata_wait_io(IO); boot_ata_select(IO); - Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF)); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); Out8(IO + ATA_REG_SEC_COUNT0, 1); 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_COMMAND, ATA_CMD_READ_PIO); @@ -159,12 +129,13 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, boot_ata_wait_io(IO); boot_ata_select(IO); - Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF)); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0x0F)); Out8(IO + ATA_REG_SEC_COUNT0, 1); 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_COMMAND, ATA_CMD_WRITE_PIO); @@ -217,7 +188,9 @@ BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz if (!Buf || SectorSz < 1) return *this; - boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, + auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize; + + boot_ata_read(lba, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, this->Leak().mSize); return *this; @@ -238,7 +211,9 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS if (!Buf || SectorSz < 1) return *this; - boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, + auto lba = this->Leak().mBase / BootDeviceATA::kSectorSize; + + boot_ata_write(lba, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, this->Leak().mSize); return *this; @@ -256,3 +231,21 @@ BootDeviceATA::ATATrait& BootDeviceATA::Leak() { return mTrait; } SizeT BootDeviceATA::GetSectorsCount() noexcept { return kATAData[60] + kATAData[61]; } + +SizeT BootDeviceATA::GetDiskSize() noexcept { + Out8(this->Leak().mBus + ATA_REG_COMMAND, 0xF8); + + boot_ata_wait_io(this->Leak().mBus); + + SizeT result = 0; + + result += In8(this->Leak().mBus + ATA_CYL_LOW); + result += In8(this->Leak().mBus + ATA_CYL_MID) << 8; + result += In8(this->Leak().mBus + ATA_CYL_HIGH) << 16; + result += In8(this->Leak().mBus + ATA_CYL_HIGH) << 24; + + BTextWriter writer; + writer.Write(L"Disk-Size: ").Write(result).Write(L"\r\n"); + + return result; +} diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index 5e9e2355..a928a41a 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -193,9 +193,11 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, memcpy(rootDesc.fFileName, "/", strlen("/")); memcpy(rootDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork)); - rootDesc.fBlobSz = strlen(kMachineModel " startup disk."); + rootDesc.fBlobSz = BootDeviceATA::kSectorSize; rootDesc.fBlob = new Char[rootDesc.fBlobSz]; + memset(rootDesc.fBlob, 0, rootDesc.fBlobSz); + memcpy(rootDesc.fBlob, kMachineModel " startup disk.", strlen(kMachineModel " startup disk.")); @@ -207,12 +209,15 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, memcpy(bootDesc.fFileName, "/Boot", strlen("/Boot")); memcpy(bootDesc.fForkName, kNewFSResourceFork, strlen(kNewFSResourceFork)); + + bootDesc.fBlobSz = BootDeviceATA::kSectorSize; + bootDesc.fBlob = new Char[rootDesc.fBlobSz]; + + memset(bootDesc.fBlob, 0, bootDesc.fBlobSz); + 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; diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 92128b02..4d8e1100 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -70,7 +70,7 @@ run-efi-amd64: .PHONY: epm-img epm-img: - qemu-img create -f qcow2 $(IMG) 512M + qemu-img create -f qcow2 $(IMG) 1G qemu-img create -f qcow2 $(IMG_2) 512M .PHONY: download-edk |
