Page 1 of 1
Controlling Hard disk SATA in asm on x86 in pmode
Posted: Mon Aug 29, 2016 4:01 pm
by Factorisable
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.
Re: Controlling Hard disk SATA in asm on x86 in pmode
Posted: Mon Aug 29, 2016 4:08 pm
by BrightLight
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
Re: Controlling Hard disk SATA in asm on x86 in pmode
Posted: Mon Aug 29, 2016 8:21 pm
by BenLunt
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