Page 1 of 1

[solved] Buggy ATA PIO read

Posted: Mon Apr 06, 2020 2:10 am
by iProgramInCpp
Here's my ATA PIO read code: https://gist.github.com/iProgramMC/a02c ... fff0189b31

I am wondering if what I'm doing is right. Reading the boot sector works just fine, however, reading the FAT (in my case at sector 0x20FE, for some reason) does not work. It skips two bytes. I've tried this code in qemu, not sure about VirtualBox and others.

I've checked that the FAT actually exists at the address - it does.

I've compressed the hard drive image so that you can see if it works. (Warning: it is 256 MB.) Here it is. (the domain is weird because I couldn't be bothered to upload anywhere else)

update: ReadPort is inportb, ReadPortW is inportw, WritePort is outportb and WritePortW is outportw.

Thanks

Re: Buggy ATA PIO read

Posted: Mon Apr 06, 2020 7:16 am
by iProgramInCpp
Fixed it, was a bug totally outside this function :P

Re: Buggy ATA PIO read

Posted: Mon Apr 06, 2020 9:38 am
by Octocontrabass
I found a different bug:

Code: Select all

	switch(drive_num)
	{
		case 0: base = 0x01f0; break;
		case 1: base = 0x0170; break;
		case 2: base = 0x01e8; break;
		case 3: base = 0x0168; break;
		default: return -1;
	}
There can be up to two drives on each channel, but this code can only work with one drive on each channel. (Also, these are the legacy I/O ports, but PCI IDE controllers may be using ports set in their BARs instead of the legacy ports.)

Re: Buggy ATA PIO read

Posted: Mon Apr 06, 2020 11:21 am
by iProgramInCpp
thanks for the info :)