System hangs if I send Identify Device command to ATA port
Posted: Mon Jun 21, 2010 6:29 am
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.
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]);
}