I created a virtual hard disk using this command:
Code:
qemu-img create -f raw disk.img 2000M
And am running the OS with this:
Code:
qemu-system-i386 -hda disk.img -cdrom Binaries/caffieneOS.iso -m 16M -boot order=dc
But when writing to the disk using my ata driver (the code is below) and restarting the OS, the virtual hard disk does not save my changes. Is there a reason that this is happening?
The ataPioWrite() function to write to hard disk:
Code:
void ataPioWrite(unsigned int LBA, unsigned short sectorcount, unsigned char *target) {
outportb(ATA_PRIMARY_DRIVE_HEAD, 0x40); // Select master
outportb(ATA_PRIMARY_SECCOUNT, (sectorcount >> 8) & 0xFF); // Sector Count hi
outportb(ATA_PRIMARY_LBA_LO, (LBA << 24) & 0xFF); // LBA4
outportb(ATA_PRIMARY_LBA_MID, (LBA << 32) & 0xFF); //LBA5
outportb(ATA_PRIMARY_LBA_HI, (LBA << 40) & 0xFF); // LBA6
outportb(ATA_PRIMARY_SECCOUNT, sectorcount & 0xFF); // Sector Count low
outportb(ATA_PRIMARY_LBA_LO, LBA & 0xFF); // LBA1
outportb(ATA_PRIMARY_LBA_MID, (LBA << 8) & 0xFF); //LBA2
outportb(ATA_PRIMARY_LBA_HI, (LBA << 16) & 0xFF); // LBA3
outportb(ATA_PRIMARY_COMM_REGSTAT, 0x34); // WRITE SECTORS EXT command
for (unsigned char i = 0; i < sectorcount; i++) {
pollATA(); // Wait for it to be able to transfer data
// Transfer the data
for (int j = 0; j < 256; j++) { outportl(ATA_PRIMARY_DATA, target[i]); }
target += 256;
}
// Flush the cache.
outportb(ATA_PRIMARY_COMM_REGSTAT, 0xE7);
// Poll for BSY.
while (inportb(ATA_PRIMARY_COMM_REGSTAT) & STAT_BSY) {}
}