System hangs if I send Identify Device command to ATA port

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
Mimo
Posts: 2
Joined: Mon Jun 21, 2010 5:47 am

System hangs if I send Identify Device command to ATA port

Post 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]);
}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

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

Post by bewing »

You are only getting half the data. The disk still has 128 more words to send to you.
Mimo
Posts: 2
Joined: Mon Jun 21, 2010 5:47 am

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

Post 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!
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

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

Post 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).
Post Reply