diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-22 03:47:51 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-22 03:47:51 +0100 |
| commit | bc9b63a3dbc63d818e90237beb019f584acfe133 (patch) | |
| tree | 8c95e0dbfbbe5fce9ca8e10f6ce9b84236fa756c /Private/NewBoot/Source | |
| parent | 6f1aa4288c62580afb876fb9e35a45d022027d1d (diff) | |
NewBoot: Working ATA driver, and new drive scheme, each data has a
padding of 1 byte.
Example:
{ "H", "\0", "e", "\0", "y" }
So that the drive doesnt skip any bytes.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Private/NewBoot/Source')
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootATA.cxx | 114 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx | 7 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootMain.cxx | 9 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootString.cxx | 26 | ||||
| -rw-r--r-- | Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx | 6 | ||||
| -rw-r--r-- | Private/NewBoot/Source/makefile | 7 |
7 files changed, 102 insertions, 69 deletions
diff --git a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx index 0ee16d82..e55b2121 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootATA.cxx @@ -24,7 +24,7 @@ static Boolean kATADetected = false; static Int32 kATADeviceType = kATADeviceCount; -static CharacterType kATAData[kATADataLen] = {0}; +static CharacterTypeUTF8 kATAData[kATADataLen] = {0}; Boolean boot_ata_detected(Void); @@ -46,7 +46,7 @@ ATAWaitForIO_Retry2: return true; } -Void ATASelect(UInt16 Bus) { +Void boot_ata_select(UInt16 Bus) { if (Bus == ATA_PRIMARY_IO) Out8(Bus + ATA_REG_HDDEVSEL, ATA_PRIMARY_SEL); else @@ -61,7 +61,7 @@ Boolean boot_ata_init(UInt16 Bus, UInt8 Drive, UInt16& OutBus, UInt16 IO = Bus; - ATASelect(IO); + boot_ata_select(IO); // Bus init, NEIN bit. Out8(IO + ATA_REG_NEIN, 1); @@ -86,21 +86,25 @@ ATAInit_Retry: /// fetch serial info /// model, speed, number of sectors... + boot_ata_wait_io(IO); + for (SizeT indexData = 0ul; indexData < kATADataLen; ++indexData) { kATAData[indexData] = In16(IO + ATA_REG_DATA); } - writer.Write(L"NewBoot: Model: "); + writer.Write(L"NewBoot: Drive Model: "); for (SizeT indexData = 0; indexData < kATADataLen; indexData += 1) { - writer.WriteCharacter(kATAData[indexData + ATA_IDENT_MODEL + 1]) - .WriteCharacter(kATAData[indexData + ATA_IDENT_MODEL]); + writer.WriteCharacter(kATAData[indexData]); } writer.Write(L"\r\n"); - OutBus = (Bus == ATA_PRIMARY) ? BDeviceATA::kPrimary : BDeviceATA::kSecondary; - OutMaster = (Bus == ATA_PRIMARY) ? ATA_MASTER : ATA_SLAVE; + writer.Write(L"\r\n"); + + OutBus = + (Bus == ATA_PRIMARY_IO) ? BDeviceATA::kPrimary : BDeviceATA::kSecondary; + OutMaster = (Bus == ATA_PRIMARY_IO) ? ATA_MASTER : ATA_SLAVE; Out8(Bus + ATA_REG_HDDEVSEL, 0xA0 | ATA_MASTER << 4); @@ -122,7 +126,7 @@ ATAInit_Retry: kATADeviceType = kATADeviceSATA_PI; } - if (cl == 0 && ch == 0) { + if (cl == 0x0 && ch == 0x0) { writer.Write(L"NewBoot: PATA drive detected.\r\n"); kATADeviceType = kATADevicePATA; } @@ -137,47 +141,51 @@ ATAInit_Retry: return true; } -Void boot_ata_read(UInt32 Lba, UInt8 IO, UInt8 Master, CharacterType* Buf, - SizeT Offset) { - UInt8 Command = (Master ? 0xE0 : 0xF0); +Void boot_ata_read(UInt32 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, + SizeT SectorSz, SizeT Size) { + UInt8 Command = (!Master ? 0xE0 : 0xF0); - Out8(IO + ATA_REG_HDDEVSEL, - (Command << 4) | (((Lba & 0x0f000000) >> 24) & 0x0f)); - Out8(IO + ATA_REG_SEC_COUNT0, 0x1); - Out8(IO + ATA_REG_FEATURES, 0); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF)); + Out8(IO + ATA_REG_SEC_COUNT0, SectorSz); - Out8(IO + ATA_REG_LBA0, (UInt8)(Lba & 0x000000ff)); - Out8(IO + ATA_REG_LBA1, (UInt8)(Lba & 0x0000ff00) >> 8); - Out8(IO + ATA_REG_LBA2, (UInt8)(Lba & 0x00ff0000) >> 16); + Out8(IO + ATA_REG_LBA0, (UInt8)(Lba)); + Out8(IO + ATA_REG_LBA1, (UInt8)(Lba) >> 8); + Out8(IO + ATA_REG_LBA2, (UInt8)(Lba) >> 16); Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); - boot_ata_wait_io(IO); + BTextWriter writer; + + writer.Write(L"NewBoot: Port: ").Write(IO).Write(L"\r\n"); - for (SizeT IndexOff = 0; IndexOff < 256; ++IndexOff) { - Buf[Offset + IndexOff] = In16(IO + ATA_REG_DATA); + for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { + WideChar chr = In16(IO + ATA_REG_DATA); + + Buf[IndexOff] = chr; + + boot_ata_wait_io(IO); } } -Void boot_ata_write(UInt32 Lba, UInt8 IO, UInt8 Master, CharacterType* Buf, - SizeT Offset) { - UInt8 Command = (Master ? 0xE0 : 0xF0); +Void boot_ata_write(UInt32 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, + SizeT SectorSz, SizeT Size) { + UInt8 Command = (!Master ? 0xE0 : 0xF0); - Out8(IO + ATA_REG_HDDEVSEL, - (Command << 4) | (((Lba & 0x0f000000) >> 24) & 0x0f)); - Out8(IO + ATA_REG_SEC_COUNT0, 0x1); - Out8(IO + ATA_REG_FEATURES, 0); + Out8(IO + ATA_REG_HDDEVSEL, (Command) | (((Lba) >> 24) & 0xF)); + Out8(IO + ATA_REG_SEC_COUNT0, SectorSz); - Out8(IO + ATA_REG_LBA0, (UInt8)(Lba & 0x000000ff)); - Out8(IO + ATA_REG_LBA1, (UInt8)(Lba & 0x0000ff00) >> 8); - Out8(IO + ATA_REG_LBA2, (UInt8)(Lba & 0x00ff0000) >> 16); + Out8(IO + ATA_REG_LBA0, (UInt8)(Lba)); + Out8(IO + ATA_REG_LBA1, (UInt8)(Lba) >> 8); + Out8(IO + ATA_REG_LBA2, (UInt8)(Lba) >> 16); Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); - boot_ata_wait_io(IO); - - for (SizeT IndexOff = 0; IndexOff < 256; ++IndexOff) { - Out16(IO + ATA_REG_DATA, Buf[Offset + IndexOff]); + for (SizeT IndexOff = 0; IndexOff < Size; ++IndexOff) { + // Send it two + Out16(IO + ATA_REG_DATA, Buf[IndexOff]); + Out16(IO + ATA_REG_DATA, '\0'); + + boot_ata_wait_io(IO); } } @@ -201,21 +209,22 @@ BDeviceATA::BDeviceATA() noexcept { if (boot_ata_init(ATA_PRIMARY_IO, true, this->Leak().mBus, this->Leak().mMaster) || - boot_ata_init(ATA_PRIMARY_IO, false, this->Leak().mBus, - this->Leak().mMaster) || boot_ata_init(ATA_SECONDARY_IO, true, this->Leak().mBus, - this->Leak().mMaster) || - boot_ata_init(ATA_SECONDARY_IO, false, this->Leak().mBus, this->Leak().mMaster)) { kATADetected = true; BTextWriter writer; - writer.Write(L"NewBoot: Driver: OnLine.\r\n"); + writer.Write(L"NewBoot: Drive is OnLine.\r\n"); + writer.Write(L"NewBoot: IO: ") + .Write(this->Leak().mBus) + .Write(L" Master: ") + .Write(this->Leak().mMaster) + .Write(L"\r\n"); } } /** * @brief Is ATA detected? -*/ + */ BDeviceATA::operator bool() { return boot_ata_detected(); } /** @@ -223,7 +232,7 @@ BDeviceATA::operator bool() { return boot_ata_detected(); } @param Sz Sector size @param Buf buffer */ -BDeviceATA& BDeviceATA::Read(CharacterType* Buf, const SizeT& SectorSz) { +BDeviceATA& BDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz) { if (!boot_ata_detected()) { Leak().mErr = true; return *this; @@ -233,11 +242,8 @@ BDeviceATA& BDeviceATA::Read(CharacterType* Buf, const SizeT& SectorSz) { if (!Buf || SectorSz < 1) return *this; - for (SizeT i = 0UL; i < SectorSz; ++i) { - boot_ata_read(this->Leak().mBase + i, - this->Leak().mBus, this->Leak().mMaster, - Buf, i); - } + boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, + Buf, SectorSz, this->Leak().mSize); return *this; } @@ -247,7 +253,7 @@ BDeviceATA& BDeviceATA::Read(CharacterType* Buf, const SizeT& SectorSz) { @param Sz Sector size @param Buf buffer */ -BDeviceATA& BDeviceATA::Write(CharacterType* Buf, const SizeT& SectorSz) { +BDeviceATA& BDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorSz) { if (!boot_ata_detected()) { Leak().mErr = true; return *this; @@ -257,14 +263,8 @@ BDeviceATA& BDeviceATA::Write(CharacterType* Buf, const SizeT& SectorSz) { if (!Buf || SectorSz < 1) return *this; - SizeT Off = 0UL; - - for (SizeT i = 0UL; i < SectorSz; ++i) { - boot_ata_write(this->Leak().mBase + i, this->Leak().mBus, this->Leak().mMaster, - Buf, Off); - - Off += kATASectorSize; - } + boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, + Buf, SectorSz, this->Leak().mSize); return *this; } diff --git a/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx new file mode 100644 index 00000000..a4edfa57 --- /dev/null +++ b/Private/NewBoot/Source/HEL/AMD64/BootEPM.cxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <BootKit/BootKit.hxx> diff --git a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx index 350ea0e7..b9cc7527 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootFileReader.cxx @@ -25,7 +25,7 @@ /*** @brief File Reader constructor. */ -BFileReader::BFileReader(const CharacterType* path, EfiHandlePtr ImageHandle) { +BFileReader::BFileReader(const CharacterTypeUTF16* path, EfiHandlePtr ImageHandle) { if (path != nullptr) { SizeT index = 0UL; for (; path[index] != L'\0'; ++index) { diff --git a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx index 572e8f5e..b90d9d60 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootMain.cxx @@ -17,15 +17,15 @@ #define kMaxBufSize 256 -EXTERN_C void Main(HEL::HandoverInformationHeader* HIH); +EXTERN_C void Main(HEL::HandoverInformationHeader* handoverInfo); -typedef void (*bt_main_type)(HEL::HandoverInformationHeader* HIH); +typedef void (*bt_main_type)(HEL::HandoverInformationHeader* handoverInfo); EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, EfiSystemTable* SystemTable) { InitEFI(SystemTable); // Init the efi library. InitGOP(); // Quick Toolkit for UI - + BTextWriter writer; /// Splash screen stuff @@ -38,6 +38,9 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, .Write(SystemTable->FirmwareVendor) .Write(L"\r\n"); + /// Init ATA driver. + BDeviceATA ataDrv; + /// Read Kernel blob. BFileReader kernelImg(L".HCORE", ImageHandle); diff --git a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx index 9fbe1a11..52633fe2 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootString.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootString.cxx @@ -17,7 +17,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////// -HCore::SizeT BCopyMem(CharacterType *dest, CharacterType *src, +HCore::SizeT BCopyMem(CharacterTypeUTF16 *dest, CharacterTypeUTF16 *src, const HCore::SizeT len) { if (!dest || !src) return 0; @@ -29,12 +29,12 @@ HCore::SizeT BCopyMem(CharacterType *dest, CharacterType *src, return index; } -HCore::SizeT BStrLen(const CharacterType *ptr) { +HCore::SizeT BStrLen(const CharacterTypeUTF16 *ptr) { if (!ptr) return 0; HCore::SizeT cnt = 0; - while (*ptr != (CharacterType)0) { + while (*ptr != (CharacterTypeUTF16)0) { ++ptr; ++cnt; } @@ -42,7 +42,25 @@ HCore::SizeT BStrLen(const CharacterType *ptr) { return cnt; } -HCore::SizeT BSetMem(CharacterType *src, const CharacterType byte, +HCore::SizeT BSetMem(CharacterTypeUTF16 *src, const CharacterTypeUTF16 byte, + const HCore::SizeT len) { + if (!src) return 0; + + HCore::SizeT cnt = 0UL; + + while (*src != 0) { + if (cnt > len) break; + + *src = byte; + ++src; + + ++cnt; + } + + return cnt; +} + +HCore::SizeT BSetMem(CharacterTypeUTF8 *src, const CharacterTypeUTF8 byte, const HCore::SizeT len) { if (!src) return 0; diff --git a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx index b363d80b..7ccc37aa 100644 --- a/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx +++ b/Private/NewBoot/Source/HEL/AMD64/BootTextWriter.cxx @@ -20,7 +20,7 @@ /** @brief puts wrapper over EFI ConOut. */ -BTextWriter &BTextWriter::Write(const CharacterType *str) { +BTextWriter &BTextWriter::Write(const CharacterTypeUTF16 *str) { if (*str == 0 || !str) return *this; ST->ConOut->OutputString(ST->ConOut, str); @@ -31,7 +31,7 @@ BTextWriter &BTextWriter::Write(const CharacterType *str) { BTextWriter &BTextWriter::Write(const UChar *str) { if (*str == 0 || !str) return *this; - CharacterType strTmp[2]; + CharacterTypeUTF16 strTmp[2]; strTmp[1] = 0; for (size_t i = 0; str[i] != 0; i++) { @@ -45,7 +45,7 @@ BTextWriter &BTextWriter::Write(const UChar *str) { /** @brief putc wrapper over EFI ConOut. */ -BTextWriter &BTextWriter::WriteCharacter(CharacterType c) { +BTextWriter &BTextWriter::WriteCharacter(CharacterTypeUTF16 c) { EfiCharType str[2]; str[0] = c; str[1] = 0; diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 631550c9..948a6519 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -16,7 +16,8 @@ else EMU=qemu-system-x86_64w.exe endif -EMU_FLAGS=-net none -smp 2 -m 4G -M q35 -bios OVMF.fd -drive file=fat:rw:CDROM,index=1,format=raw -serial stdio +IMG=epm.img +EMU_FLAGS=-net none -smp 2 -m 4G -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 -serial stdio LD_FLAGS=-e efi_main --subsystem=10 OBJ=$(wildcard *.o) $(wildcard ../../Objects/*.obj) $(wildcard HEL/AMD64/*.obj) @@ -45,6 +46,10 @@ compile-amd64: run-efi-amd64: $(EMU) $(EMU_FLAGS) +.PHONY: epm-img +epm-img: + qemu-img create -f raw $(IMG) 256M + .PHONY: download-edk download-edk: $(HTTP_GET) https://retrage.github.io/edk2-nightly/bin/DEBUGX64_OVMF.fd -O OVMF.fd |
