OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:41 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: System hangs if I send Identify Device command to ATA port
PostPosted: Mon Jun 21, 2010 6:29 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: System hangs if I send Identify Device command to ATA po
PostPosted: Mon Jun 21, 2010 7:42 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: System hangs if I send Identify Device command to ATA po
PostPosted: Mon Jun 21, 2010 7:47 am 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
You are only getting half the data. The disk still has 128 more words to send to you.


Top
 Profile  
 
 Post subject: Re: System hangs if I send Identify Device command to ATA po
PostPosted: Mon Jun 21, 2010 11:54 am 
Offline

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


Top
 Profile  
 
 Post subject: Re: System hangs if I send Identify Device command to ATA po
PostPosted: Mon Jun 21, 2010 10:53 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
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).

_________________
Live PC 1: Image Live PC 2: Image

YouTube:
http://youtube.com/@AltComp126/streams
http://youtube.com/@proyectos/streams

http://master.dl.sourceforge.net/projec ... 7z?viasf=1


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 67 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group