All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to use SATA software reset command? (PIO)
PostPosted: March 30th, 2012, 4:47 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
I've tried to reset SATA-Controller with seting SRST-bit to 1 in Shadow Control Register. While waiting for the BSY-bit in Shadow Status Register be cleared to 0. However, I got 0xD8 everytime I read the Shadow Status Register.
My code follow:
Code:
void software_reset(WORD portCtrl)
{
   __asm
   {
      xor eax, eax
      xor edx, edx
      mov dx, word ptr[portCtrl]
      mov al, _CONTROL_SRST_
      out dx, al
   }
}
void watch_dog(DWORD* pCount)
{
   (*pCount)++;
   if((*pCount) >= 0x100000)
   {
      __asm int 3
      (*pCount) = 0;
   }
}
void wait_until_ready(WORD portBase)
{
   DWORD count = 0;
   __asm
   {
L_READ:
      lea eax, dword ptr[count]
      push eax
      call watch_dog
      mov dx, word ptr[portBase]
      xor eax, eax
      add dx, 0x7  //status
      in al, dx 
      test al, (_STATUS_BSY_ | _STATUS_DRQ_)
      jz L_RET
      nop
      nop
      nop
      jmp L_READ
   }
L_RET:
   __asm int 3
   return;
}
void DriverEntry()
{
   software_reset(0x3F6);
   wait_until_ready(0x1F0);
}

Any info should be appreciated.


Last edited by corner on March 30th, 2012, 4:49, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: how to use SATA software reset command? (PIO)
PostPosted: March 30th, 2012, 6:02 
Offline
User avatar

Joined: May 5th, 2004, 20:06
Posts: 2831
Location: England
Hi, Don't have time but take look here

http://www.serialata.org/documents/SATA ... rs_000.pdf

_________________
All went well until I plugged the drive in.


Top
 Profile  
 
 Post subject: Re: how to use SATA software reset command? (PIO)
PostPosted: March 30th, 2012, 21:37 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
guru wrote:
Hi, Don't have time but take look here

http://www.serialata.org/documents/SATA ... rs_000.pdf


I read this document, just found out the intruduction of SStatus, the SStatus-Register looks like part of SCR-Register(It saids SCR0). However, Which Register I polling is Shadow-Status-Register.

Thank you anyway. :shock:


Top
 Profile  
 
 Post subject: Re: how to use SATA software reset command? (PIO)
PostPosted: March 30th, 2012, 22:53 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
I got it !!
Detail here: http://wiki.osdev.org/ATA_PIO_Mode#IDENTIFY_command
part of explantion wrote:
summary:
Resetting a drive / Software Reset

For non-ATAPI drives, the only method a driver has of resetting a drive after a major error is to do a "software reset" on the bus. Set bit 2 (SRST, value = 4) in the proper Control Register for the bus. This will reset both ATA devices on the bus. Then, you have to clear that bit again, yourself. The master drive on the bus is automatically selected. ATAPI drives set values on their LBA_LOW and LBA_HIGH IO ports, but are not supposed to reset or even terminate their current command.

Hope this could help someone who got the same perplexity like me. :roll:


Top
 Profile  
 
 Post subject: Re: how to use SATA software reset command? (PIO)
PostPosted: March 30th, 2012, 23:34 
Offline

Joined: December 20th, 2011, 22:12
Posts: 30
Location: china
By the words:
1. The Shadow-Status-Register of SATA-Controller is similar to Status-Register of PATA, just a different name.
2. The Shadow-Status-Register is a 8-bit Register, If you use it with a 16-bit instruction(like "in ax, 0x1F7") the result maybe uncertainty.(If the incorrect instruction executed under VMWare-Guest-OS, the VMWare will stop itself, you can verify this situation.)

Share my experience of SATA study.


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

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 6 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