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

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Marques
Posts: 4
Joined: Mon Mar 06, 2023 10:25 am
Libera.chat IRC: Marques

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

Post 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
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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?
Post Reply