Page 1 of 1

ATA/PIO not working stuck on infinite loop waiting for RDY

Posted: Tue Mar 07, 2023 8:49 am
by Marques
i have written a super simple os and i decided to start using grub to boot it, so i started a new projected and im getting my old kernel functions to the new kernel and the ATA driver is not working stuck when i wait for RDY

Code: Select all

void ATA_wait_BSY() // Wait for bsy to be 0
{
	while (insb(0x1F7) & STATUS_BSY)
		;
}

void ATA_wait_DRQ() // Wait fot drq to be 1
{
	while (!(insb(0x1F7) & STATUS_RDY))
		;
}
i have this 2 functions

and

Code: Select all

int disk_read_sector(int lba, void *buf)
{
	ATA_wait_BSY();
	print("1");

	outb(0x1F6, 0xE0 | ((lba >> 24) & 0xF));
	outb(0x1F2, 1);
	outb(0x1F3, (uint8_t)lba);
	outb(0x1F4, (uint8_t)(lba >> 8));
	outb(0x1F5, (uint8_t)(lba >> 16));
	outb(0x1F7, 0x20); // Send the read command

	uint16_t *ptr = (uint16_t *)buf;

	ATA_wait_BSY();
	print("2");
	ATA_wait_DRQ();
	print("3");
	for (int i = 0; i < 256; i++)
	{
		*ptr = insw(0x1F0);
		ptr++;
	}

	return 0;
}
i only get printed 1 and 2 so i presume it is stuck on ATA_wait_DRQ();
this used to work on my old bootloader so i think is something related to it the idt is also from the old bootloader and de gdt is the same as nanobyte used.
so im really lost... the interrupts are working fine, div 0 is good... keyboard input also, my unique current problem is this

Re: ATA/PIO not working stuck on infinite loop waiting for R

Posted: Mon Apr 03, 2023 5:55 pm
by Octocontrabass
Marques wrote:

Code: Select all

	while (!(insb(0x1F7) & STATUS_RDY))
Is that "inb" or "insb"? Is that DRQ or DRDY?
Marques wrote:i only get printed 1 and 2 so i presume it is stuck on ATA_wait_DRQ();
If it is stuck there, you should print the status register to see if the drive is reporting an error of some kind.
Marques wrote:the interrupts are working fine
If you have interrupts, why are you polling?