diff options
Diffstat (limited to 'dev/ZBA')
| -rw-r--r-- | dev/ZBA/BootKit/BootKit.hxx | 99 | ||||
| -rw-r--r-- | dev/ZBA/Sources/HEL/AMD64/BootATA.cxx | 16 | ||||
| -rw-r--r-- | dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 3 | ||||
| -rw-r--r-- | dev/ZBA/Sources/HEL/AMD64/New+Delete.cxx | 4 | ||||
| -rw-r--r-- | dev/ZBA/amd64-efi.make | 2 |
5 files changed, 55 insertions, 69 deletions
diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx index 71d94c14..bdffb69f 100644 --- a/dev/ZBA/BootKit/BootKit.hxx +++ b/dev/ZBA/BootKit/BootKit.hxx @@ -219,7 +219,7 @@ public: /// @brief check if partition is good. Bool IsPartitionValid() noexcept { - fDiskDev.Leak().mBase = (kNewFSStartLba); + fDiskDev.Leak().mBase = (kNewFSRootCatalogStartAddress); fDiskDev.Leak().mSize = BootDev::kSectorSize; Char buf[BootDev::kSectorSize] = {0}; @@ -263,37 +263,32 @@ private: /// @param partBlock the NewFS partition block. Boolean WriteRootCatalog(BFileDescriptor* fileBlobs, SizeT blobCount, NFS_ROOT_PARTITION_BLOCK& partBlock) { - if (partBlock.SectorSize != BootDev::kSectorSize) - return false; - BFileDescriptor* blob = fileBlobs; Lba startLba = partBlock.StartCatalog; BTextWriter writer; - Char bufCatalog[sizeof(NFS_CATALOG_STRUCT)] = {0}; + NFS_CATALOG_STRUCT catalogKind{0}; constexpr auto cNewFSCatalogPadding = 4; - NFS_CATALOG_STRUCT* catalogKind = (NFS_CATALOG_STRUCT*)bufCatalog; - catalogKind->PrevSibling = startLba; - catalogKind->NextSibling = (startLba + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding)); + catalogKind.PrevSibling = startLba; + catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); /// Fill catalog kind. - catalogKind->Kind = blob->fKind; - catalogKind->Flags = kNewFSFlagCreated; + catalogKind.Kind = blob->fKind; + catalogKind.Flags = kNewFSFlagCreated; --partBlock.FreeCatalog; --partBlock.FreeSectors; - writer.Write(L"newosldr: Wrote directory: ").Write(blob->fFileName).Write(L"\r"); - writer.Write(L"newosldr: Disk formatted.\r"); - - CopyMem(catalogKind->Name, blob->fFileName, StrLen(blob->fFileName)); + CopyMem(catalogKind.Name, blob->fFileName, StrLen(blob->fFileName)); fDiskDev.Leak().mBase = startLba; fDiskDev.Leak().mSize = sizeof(NFS_CATALOG_STRUCT); - fDiskDev.Write((Char*)bufCatalog, sizeof(NFS_CATALOG_STRUCT)); + fDiskDev.Write((Char*)&catalogKind, sizeof(NFS_CATALOG_STRUCT)); + + writer.Write(L"newosldr: Wrote directory: ").Write(blob->fFileName).Write(L"\r"); return true; } @@ -318,12 +313,10 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* partName, /// convert the sector into something that the disk understands. SizeT sectorSz = BootDev::kSectorSize; - Char* buf = new Char[BootDev::kSectorSize]; + NFS_ROOT_PARTITION_BLOCK partBlock{0}; - NFS_ROOT_PARTITION_BLOCK* partBlock = reinterpret_cast<NFS_ROOT_PARTITION_BLOCK*>(buf); - - memcpy(partBlock->Ident, kNewFSIdent, kNewFSIdentLen - 1); - memcpy(partBlock->PartitionName, partName, strlen(partName)); + CopyMem(partBlock.Ident, kNewFSIdent, kNewFSIdentLen - 1); + CopyMem(partBlock.PartitionName, partName, strlen(partName)); /// @note A catalog roughly equal to a sector. @@ -333,62 +326,58 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* partName, if (GIB(fDiskDev.GetDiskSize()) < cMinimumDiskSize) { - delete buf; EFI::ThrowError(L"Disk-Too-Tiny", L"Can't format a New Filesystem partition here."); return false; } - partBlock->Version = kNewFSVersionInteger; - partBlock->CatalogCount = blobCount; - partBlock->Kind = kNewFSHardDrive; - partBlock->SectorSize = sectorSz; - partBlock->FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT); - partBlock->SectorCount = fDiskDev.GetSectorsCount(); - partBlock->FreeSectors = fDiskDev.GetSectorsCount(); - partBlock->StartCatalog = kNewFSCatalogStartAddress; - partBlock->DiskSize = fDiskDev.GetDiskSize(); - partBlock->Flags |= kNewFSPartitionTypeBoot; + partBlock.Version = kNewFSVersionInteger; + partBlock.CatalogCount = blobCount; + partBlock.Kind = kNewFSHardDrive; + partBlock.SectorSize = sectorSz; + partBlock.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT); + partBlock.SectorCount = fDiskDev.GetSectorsCount(); + partBlock.FreeSectors = fDiskDev.GetSectorsCount(); + partBlock.StartCatalog = kNewFSCatalogStartAddress; + partBlock.DiskSize = fDiskDev.GetDiskSize(); + partBlock.Flags |= kNewFSPartitionTypeBoot | kNewFSPartitionTypeStandard; - /// if we can write a root catalog, then write the partition block. - if (this->WriteRootCatalog(fileBlobs, blobCount, *partBlock)) - { - fDiskDev.Leak().mBase = kNewFSStartLba; - fDiskDev.Leak().mSize = sectorSz; + fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress; + fDiskDev.Leak().mSize = sectorSz; - fDiskDev.Write(buf, sectorSz); + fDiskDev.Write((Char*)&partBlock, sectorSz); - /// Reset buffer. - SetMem(buf, 0, sectorSz); + BOOT_BLOCK_STRUCT epmBoot{0}; - BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)buf; + constexpr auto cFsName = "NewFS"; + constexpr auto cBlockName = "ZKA:"; - constexpr auto cFsName = "NewFS"; - constexpr auto cBlockName = "ZKA:"; + CopyMem(epmBoot.Fs, reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), StrLen(cFsName)); - CopyMem(reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), epmBoot->Fs, StrLen(cFsName)); + epmBoot.FsVersion = kNewFSVersionInteger; + epmBoot.LbaStart = kNewFSRootCatalogStartAddress; + epmBoot.SectorSz = partBlock.SectorSize; + epmBoot.NumBlocks = partBlock.CatalogCount; - epmBoot->FsVersion = kNewFSVersionInteger; - epmBoot->LbaStart = kNewFSStartLba; - epmBoot->SectorSz = partBlock->SectorSize; - epmBoot->NumBlocks = partBlock->CatalogCount; + CopyMem(epmBoot.Name, reinterpret_cast<VoidPtr>(const_cast<Char*>(cBlockName)), StrLen(cBlockName)); + CopyMem(epmBoot.Magic, reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), StrLen(kEPMMagic)); - CopyMem(epmBoot->Name, reinterpret_cast<VoidPtr>(const_cast<Char*>(cBlockName)), StrLen(cBlockName)); - CopyMem(epmBoot->Magic, reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), StrLen(kEPMMagic)); + fDiskDev.Leak().mBase = 1; // always always resies at zero block. + fDiskDev.Leak().mSize = BootDev::kSectorSize; - fDiskDev.Leak().mBase = kEpmBase; - fDiskDev.Leak().mSize = sectorSz; + fDiskDev.Write((Char*)&epmBoot, sectorSz); - fDiskDev.Write(buf, sectorSz); + /// if we can write a root catalog, then write the partition block. + if (this->WriteRootCatalog(fileBlobs, blobCount, partBlock)) + { + BTextWriter writer; + writer.Write(L"newosldr: Disk formatted.\r"); - delete buf; return true; } else { - delete buf; EFI::ThrowError(L"Filesystem-Failure-Part", L"Filesystem couldn't be partitioned."); } - delete buf; return false; } diff --git a/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx b/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx index 4beed241..0c2e557d 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootATA.cxx @@ -111,6 +111,8 @@ ATAInit_Retry: Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size) { + Lba /= SectorSz; + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); boot_ata_wait_io(IO); @@ -120,7 +122,7 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, Out8(IO + ATA_REG_SEC_COUNT0, 2); - Out8(IO + ATA_REG_LBA0, (Lba)); + Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); Out8(IO + ATA_REG_LBA3, (Lba) >> 24); @@ -139,6 +141,8 @@ Void boot_ata_read(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, SizeT SectorSz, SizeT Size) { + Lba /= SectorSz; + UInt8 Command = ((!Master) ? 0xE0 : 0xF0); boot_ata_wait_io(IO); @@ -148,7 +152,7 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, Out8(IO + ATA_REG_SEC_COUNT0, 2); - Out8(IO + ATA_REG_LBA0, (Lba)); + Out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); Out8(IO + ATA_REG_LBA3, (Lba) >> 24); @@ -219,9 +223,7 @@ BootDeviceATA& BootDeviceATA::Read(CharacterTypeUTF8* Buf, const SizeT& SectorSz if (!Buf || SectorSz < 1) return *this; - auto lba = this->Leak().mBase / SectorSz; - - boot_ata_read(lba, this->Leak().mBus, this->Leak().mMaster, + boot_ata_read(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, this->Leak().mSize); return *this; @@ -245,9 +247,7 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS if (!Buf || SectorSz < 1) return *this; - auto lba = this->Leak().mBase / SectorSz; - - boot_ata_write(lba, this->Leak().mBus, this->Leak().mMaster, + boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, this->Leak().mSize); return *this; diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index f6438be8..1011ce10 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -216,9 +216,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, checkPart.Format("ZKA (A:)", &root, 1); - cg_write_text("INSATLLED PARTITION WITH SUCCESS.", 40, 10, RGB(0xFF, 0xFF, 0xFF)); - - rt_reset_hardware(); EFI::Stop(); } diff --git a/dev/ZBA/Sources/HEL/AMD64/New+Delete.cxx b/dev/ZBA/Sources/HEL/AMD64/New+Delete.cxx index 8b9a41fa..4a308f94 100644 --- a/dev/ZBA/Sources/HEL/AMD64/New+Delete.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/New+Delete.cxx @@ -19,7 +19,7 @@ EXTERN EfiBootServices* BS; void* operator new(size_t sz) { void* buf = nullptr; - + while (BS->AllocatePool(EfiMemoryType::EfiLoaderData, sz, &buf) == kBufferTooSmall) BS->FreePool(buf); @@ -59,4 +59,4 @@ void operator delete(void* buf, size_t size) BS->FreePool(buf); } -#endif // Inactive +#endif // __STANDALONE__ diff --git a/dev/ZBA/amd64-efi.make b/dev/ZBA/amd64-efi.make index dcb0972c..9e1fcd98 100644 --- a/dev/ZBA/amd64-efi.make +++ b/dev/ZBA/amd64-efi.make @@ -33,7 +33,7 @@ EMU_FLAGS=-net none -smp 4 -m 8G -M q35 \ -bios $(BIOS) -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:Sources/Root/,index=2,format=raw -d int -hdd $(IMG_2) + file=fat:rw:Sources/Root/,index=2,format=raw -d int LD_FLAGS=-e Main --subsystem=10 |
