Page 1 of 1

[Help] Reading a hard drive (LBA).

Posted: Sat Jan 08, 2011 1:50 pm
by binsky3333
Hi guys! Lately i have been trying to add drive reading support to my kernel. Here is what i have so far:

Code: Select all

void write_read_test()
{
	outportb(0x1F6, 0x40);
	outportb(0x1F1, 0x00);
	outportb(0x1F2, (unsigned char) 1);
	outportb(0x1F3, (unsigned char) 000000000000000000000000);
	outportb(0x1F4, (unsigned char) 000000000000000000000000 >> 8);
	outportb(0x1F5, (unsigned char) 000000000000000000000000 >> 16);
	outportb(0x1F7, 0x20);
	inportb(0x3F6);
	inportb(0x3F6);
	inportb(0x3F6);
	inportb(0x3F6);
	k_printf("\n");
	k_printf("Reading...\n");
	char *buffer;
	int i = 0;
	while(buffer != 256)
	{
		buffer[i] = inportw(0x1F0);
		i++;
	}
	k_printf(buffer);
}
Unfortuantely this code doesnt work... In bochs, i get the error... read sectors issued to non-disk. I belive i am getting this because i am either not putting in the right drive id, or it cannot find the drive. The error pops up in the console on this command outportb(0x1F7, 0x20); (Tells the controller to read). This is probably a simple issue. Any support would be greatly appreciated!

Thanks!

Re: [Help] Reading a hard drive (LBA).

Posted: Sat Jan 08, 2011 2:49 pm
by bewing
If bochs is giving you that message, it is most likely because the drive was never defined.
Are you sure you have activated ATA channel 0 and defined a primary master drive in your bochsrc file?

I also see a potential future mistake in your code, but it has no negative effect in this case. A cast has a much higher precedence than a shift operator, so it happens first. So your LBA calculations are truncating your LBA to 8 bits and THEN shifting down 8, 16, or 24. Which will always result in a value of 0. You need parentheses after the cast.

Re: [Help] Reading a hard drive (LBA).

Posted: Sat Jan 08, 2011 3:26 pm
by binsky3333
Ok i added a hd(whoops forgot haha). Now i get the error... ata0-0 read from 0/0/0, aborting command.

LOG:

Code: Select all

00218432312i[HD   ] ata0-0: : read from 0/0/0, aborting command
00218435215e[HD   ] IO read(0x01f0) with drq == 0: last command was 00h
00218435241e[HD   ] IO read(0x01f0) with drq == 0: last command was 00h
00218435267e[HD   ] IO read(0x01f0) with drq == 0: last command was 00h

Re: [Help] Reading a hard drive (LBA).

Posted: Sat Jan 08, 2011 6:04 pm
by Combuster
either use proper CHS (which doesn't start from all zeroes), or set the LBA bit.

Re: [Help] Reading a hard drive (LBA).

Posted: Sun Jan 09, 2011 1:18 pm
by binsky3333
Combuster wrote:either use proper CHS (which doesn't start from all zeroes), or set the LBA bit.
outportb(0x1F6, 0x40) Is this where the lBA bit is set? Is it wrong?

Also Isnt LBA 000000000000000000000000 Cylinder 0, Head 0, Sector 1?