OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 26, 2024 8:47 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Controlling Hard disk SATA in asm on x86 in pmode
PostPosted: Mon Aug 29, 2016 4:01 pm 
Offline

Joined: Wed Aug 03, 2016 12:09 pm
Posts: 16
Hi, i am in protected mode (on a x86 processor), i would like to know how to write/read in a hard disk SATA, i assume by writing its driver, ok, what information do i need to do that ?

Thant you in advance.


Top
 Profile  
 
 Post subject: Re: Controlling Hard disk SATA in asm on x86 in pmode
PostPosted: Mon Aug 29, 2016 4:08 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
A SATA hard disk is normally attached to the AHCI controller.
The basic theory is that the system has a PCI bus, the PCI bus has an AHCI controller, the AHCI controller has up to 32 ports. Each port can attach a SATA device, SATAPI device, or port multiplier device. You read values from the ports to check what kind of device it is. SATA (Serial ATA) devices use the same command set as PATA (Parallel ATA), and so you want to detect them the same way you detect ATA devices (using identify command).
Sending commands goes something like this (very very brief explanation, the wiki has more):
  • Set up a command table and FIS in memory. ATA commands are constructed here, to be sent to a SATA device through AHCI.
  • Set up a PRDT. The PRDT tells the DMA where to transfer data to/from and how many bytes to transfer.
  • Set up a received FIS and command list, with command headers.
  • Find an idle command slot on the device.
  • Send the command list and received FIS to the AHCI port which contains the SATA device.
  • Enable the drive's command execution.
  • Send the command using the port issue register.
  • Wait for the port issue register to clear. When it does, you can check the command list and task file register for errors, and if no errors are found, then the transfer has completed.
You should note that AHCI only uses DMA, and all addresses must be physical. You should work with IDE and ATA first, as many of the concepts are the same, but using the I/O bus is somewhat easier if you're new to device driver development.
AHCI Wiki Entry

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: Controlling Hard disk SATA in asm on x86 in pmode
PostPosted: Mon Aug 29, 2016 8:21 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
I agree with omarxx024. If you have not done PATA yet, I would go that route first. Then migrate to SATA.

There have been a few posts within this forum about it too, along with some code I posted for ATA.

There is a book that explains both PATA and SATA in detail with included source code at
http://www.fysnet.net/media_storage_devices.htm
where the author fully supports his work and welcomes questions, though he suggests that you
post here first, then via his email if this fails.

First do PATA, then move to SATA. Also note that some SATA controllers are PATA only, i.e.: they
do not use AHCI and emulate the PATA protocol only.

Ben


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot] and 42 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