Page 1 of 1

IDE/ATA driver not working

Posted: Sun Aug 20, 2006 5:25 pm
by AWOS
Hello,

First of all, I'm new the this forum. You seem like helpful people, though.

My OS is at http://code.google.com/p/awos/ -- so you can see all the source code there.

Now, my problem is, my IDE detection code isn't working. Obviously it is detecting a hard disk, because the while(!(status & 0x40)) loop works (to make sure that DRDY is set). The problem is, the KiAtapiIdent struct is empty, set to all 0xFFFFFFFF. Doing a dump of memory in Qemu, that's what came up at the location (I had it print the location on the screen).

Here is the relevant code:

buffer is a char *. malloc()d to contain 512 bytes,

Code: Select all

   while(status & 0x80) status = inportb(PORT_ATAPI_STATUS);
   while(!(status & 0x40)) status = inportb(PORT_ATAPI_STATUS);
   
   outportb(PORT_ATAPI_COMMAND, 0xEC);   //EIDE ident
   
   for(i = 0; i < 512; i++)
      buffer[i] = inportb(PORT_ATAPI_DATA);
      
   atapi = (struct KiAtapiIdent *)buffer;
   
   if(!(atapi->config & 0x40))
   {
      retv = 0x02;
      goto ret;
   }
   
hd:
   dprintf("hd: detected a disk at ide0:0\nconfiguration byte: %08l\n", atapi->config);
   
   ptable = (char *)kmalloc(512);
   if(!HdReadSector(0, 1, 1, 0, 0, 0, ptable))
      dprintf("hd: critical error: could not read partition table!\n");
   else
      dprintf("last two bytes of partition table: %02X %02X\n", ptable[510], ptable[511]);
   retv = TRUE;
It always prints:
last two bytes of partition table: 0xFFFFFFFF 0xFFFFFFFF

Like I said if you want to see the rest of my code go here:
http://awos.googlecode.com/svn/trunk/src/kernel/

Places you might want to look are hdd.c and driver/hdd.h.

Thank you!

Andrew

Re:IDE/ATA driver not working

Posted: Mon Aug 21, 2006 5:01 am
by falconfx
I didn't write a working IDE ATA/ATAPI driver (I'm planning to code it soon though) but AFAIK ATA ports always have to be read or written using words.

I suggest you to try to use inportw and outportw in your ATA code. Many kernel coders had problems with ATA driver and most of them were reading/writing bytes instead of words.

If this doesn't solve the problem, feel free to post again ;)

Re:IDE/ATA driver not working

Posted: Mon Aug 21, 2006 5:32 am
by blip
You only need to do word I/O on the data port.

Re:IDE/ATA driver not working

Posted: Mon Aug 21, 2006 9:16 am
by Pype.Clicker
well, not sure it'll help, but you're supposed to do 16-bit I/O on ATAPI data registers, not 8-bit. Chances are that a real disk would just end up with screwed data, but considering how emulator are typically written, it's not a surprise for me that your sector is all-0xffff.

If you're looking for a good reference ATA scanner, i'd recommend tim robinson's. That's what i used when writing the ATA device detection for Clicker (which you can feel free to check as well if you're not horrified by my codestyle.