Page 1 of 1

System hangs if I send Identify Device command to ATA port

Posted: Mon Jun 21, 2010 6:29 am
by Mimo
This simple piece of code causes my system to hang (FreeDOS, djgpp compiler).
The Identify Device command is sent successfully and the output is correct. But when the program closes the system hangs and the HDD activity led stays on.
It works fine on another system.
I've been trying to find the cause of this for several days now but I ran out of ideas.

The attached devices are SATA and the ports (IOPORT and CTRLPORT) are different than the standard PATA ports (ie. 1F0/3F4) but I don't think that's the problem.

Code: Select all

void main()
{
  outportb(CTRLPORT+2,0x06);
  delay(10);
  outportb(CTRLPORT+2,0x02);

  // wait for busy
  while((inportb(IOPORT+7)&0x80));

  // select drive
  outportb(IOPORT+6,DEV);

  // send Identify Device command
  outportb(IOPORT+7,0xEC);
  // wait for busy
  while((inportb(IOPORT+7)&0x08));
  inportb(CTRLPORT);

  int i;
  unsigned short Identify[128];
  char cIdentify[256];
  for(i=0;i<128;i++)  {
    Identify[i]=inportw(IOPORT);
    cIdentify[2*i+1]=Identify[i];
    cIdentify[2*i]=Identify[i]>>8;
  }

  for (i=0;i<40;i++) printf("%c",cIdentify[54+i]);
}

Re: System hangs if I send Identify Device command to ATA po

Posted: Mon Jun 21, 2010 7:42 am
by Combuster
Most likely you are not leaving the system in a state in which freedos expects it to be. Begin by reading all the device's registers at the start and comparing those to an image you make at the end - you may find out where things are different and thus go wrong. By looking up the meaning of the changed bits you may even find a clue as to why FreeDOS doesn't like what you do.

Re: System hangs if I send Identify Device command to ATA po

Posted: Mon Jun 21, 2010 7:47 am
by bewing
You are only getting half the data. The disk still has 128 more words to send to you.

Re: System hangs if I send Identify Device command to ATA po

Posted: Mon Jun 21, 2010 11:54 am
by Mimo
bewing wrote:You are only getting half the data. The disk still has 128 more words to send to you.
How could I have missed this. #-o
That's my punishment for using copy/paste too much.

It works great now. Thanks!

Re: System hangs if I send Identify Device command to ATA po

Posted: Mon Jun 21, 2010 10:53 pm
by ~
Mimo wrote:The attached devices are SATA and the ports (IOPORT and CTRLPORT) are different than the standard PATA ports (ie. 1F0/3F4) but I don't think that's the problem.
Could you please clarify how did you find the CTRLPORT (I suppose this is the Alternate Status/Device Control register)?

I currently can only find the first 8 (S)ATA registers located in the base address of IOPORT, looking for their addresses in the PCI Base Address Registers of the disk controllers, but the ports I find only have 8 registers range, and the last register is missing (the one corresponding to 3F6h of the 1F0h/3F6h pair, for instance).