Code: Select all
-hda disk.raw -boot d -cdrom os.iso
Code: Select all
/hello // is a directory
/hello/test.txt // contains "this is test data"
Now, the code for doing a simple read test from the disk is really simple, but for some reason I am getting a bunch of 0s and a couple seemingly random bytes in my return buffer. The disk exists and reading the port back) as well as the controller. I check if the disk exists like this:
Code: Select all
unsigned char poll_drive(unsigned short drive, unsigned char arg) // drive could be 0x1F7 or 0x170 and args 0xA0 or 0xB0
{
outportb(drive, arg);
timer_wait(1);
return inportb(drive) & (1 << 6);
}
My simple read function looks like this:
Code: Select all
void read_hdd_lba28(char buffer[], unsigned char addr, uint8_t sector_count, unsigned short drive, char is_slave)
{
outportb(drive + 1, 0x00);
outportb(drive + 2, sector_count);
outportb(drive + 3, (unsigned char) ((addr) & 0xFF));
outportb(drive + 4, (unsigned char)((addr >> 8) & 0xFF));
outportb(drive + 5, (unsigned char)((addr >> 16) & 0xFF));
outportb(drive + 6, 0xE0 | (is_slave << 4) | ((addr >> 24) & 0x0F));
outportb(drive + 7, ATA_CMD_READ_PIO);
while(!(inportb(drive + 7) & 0x08));
for (int i = 0; i < 256; i++)
{
unsigned short tmpword = inportw(drive);
buffer[i * 2] = (unsigned char)tmpword;
buffer[i * 2 + 1] = (unsigned char)(tmpword >> 8);
}
}
Code: Select all
uint8_t* buf;
char addrbuf[4];
char secbuf[4];
uint32_t addr = 0;
uint32_t sec_ct = 0;
printf("Start addr: ");
getstr(addrbuf);
printf("Sector count: ");
getstr(secbuf);
addr = atoi(addrbuf);
sec_ct = atoi(secbuf);
read_hdd_lba28(buf, addr, sec_ct, PRIMARY_BASE, 0); // primbase is 0x1F0
for (int i = 0; i < 256 * sec_ct; i++)
printf("0x%s ", itoa(buf[i], 0, 16));
printf("\n");
I've read through the wiki pages for PCI IDE, and had some trouble understanding it all, so I discovered most of my information from other sites. I'd greatly appreciate any help.
Thanks!