SATA as IDE [SOLVED]
Posted: Mon Oct 07, 2013 2:07 pm
Hi,
My ATA/PATA (PIO mode) driver works with ATA/PATA winchesters (I tested it on a real HW and in emulators) but doesn't work with SATA winchesters set to "SATA as IDE" in BIOS. Unfortunately VirtualBox only has SATA as AHCI, so it can't be tested there. Bochs doesn't support SATA(AHCI) and I couldn't get QEMU working with SATA(AHCI).
Do I have to do something differently in the driver if a SATA winchester is emulating PATA?
The algorithm of my driver (kernel calls hd_detect):
hd_detect:
set nIEN for primary and secondary bus (maybe this should be done after drive select but it's not important now)
loop through primary and secondary busses (master and slave) by calling ata_identify with the proper addresses(port and ctrl) and slavebit
if a winchester was found then exit loop and set hd_detected variable to 1; otherwise "Couldn't Detect"
ata_identify:
send (0xA0 | slavebit <<4) to PORT_DRV_HEAD (offset 6)
sleep (1) // 1 ms
set 0 to ports from offset 2 to offset 5 (PORT_SECT_COUNT, PORT_SECT_NUM, PORT_CYL_LOW and _HIGH)
sleep(1)
send cmd IDENTIFY to PORT_COMMAND (offset 7)
sleep(1)
Read PORT_CYL_LOW and _HIGH // check signature bytes
If both zero then jump to polling (ATA/PATA disk)
If not 0x3C and 0xC3 respectively then return with NOT_FOUND (SATA disk)
polling (wait 1ms, test BSY bit (for zero) in loop with a 2-second-timeout, test ERR (for zero), test DF (for zero), test DRQ (for 1))
If not ok then return with ERROR
read 256 words from PORT_DATA (offset 0)
return FOUND
EDIT: During polling if Timeout, ERR or DF fails then return with with ERROR.
Neither of the signature-byte-pairs match but if I remove that code then polling fails.
A winchester gets detected in Bochs regardless of being a primary or secondary and master or slave.
I wouldn't like to write the AHCI driver if it's not necessary. Getting "SATA disks emulating IDE" working would be much easier.
EDIT: link to thread about HDD Detection:
http://forum.osdev.org/viewtopic.php?p=111815
My ATA/PATA (PIO mode) driver works with ATA/PATA winchesters (I tested it on a real HW and in emulators) but doesn't work with SATA winchesters set to "SATA as IDE" in BIOS. Unfortunately VirtualBox only has SATA as AHCI, so it can't be tested there. Bochs doesn't support SATA(AHCI) and I couldn't get QEMU working with SATA(AHCI).
Do I have to do something differently in the driver if a SATA winchester is emulating PATA?
The algorithm of my driver (kernel calls hd_detect):
hd_detect:
set nIEN for primary and secondary bus (maybe this should be done after drive select but it's not important now)
loop through primary and secondary busses (master and slave) by calling ata_identify with the proper addresses(port and ctrl) and slavebit
if a winchester was found then exit loop and set hd_detected variable to 1; otherwise "Couldn't Detect"
ata_identify:
send (0xA0 | slavebit <<4) to PORT_DRV_HEAD (offset 6)
sleep (1) // 1 ms
set 0 to ports from offset 2 to offset 5 (PORT_SECT_COUNT, PORT_SECT_NUM, PORT_CYL_LOW and _HIGH)
sleep(1)
send cmd IDENTIFY to PORT_COMMAND (offset 7)
sleep(1)
Read PORT_CYL_LOW and _HIGH // check signature bytes
If both zero then jump to polling (ATA/PATA disk)
If not 0x3C and 0xC3 respectively then return with NOT_FOUND (SATA disk)
polling (wait 1ms, test BSY bit (for zero) in loop with a 2-second-timeout, test ERR (for zero), test DF (for zero), test DRQ (for 1))
If not ok then return with ERROR
read 256 words from PORT_DATA (offset 0)
return FOUND
EDIT: During polling if Timeout, ERR or DF fails then return with with ERROR.
Neither of the signature-byte-pairs match but if I remove that code then polling fails.
A winchester gets detected in Bochs regardless of being a primary or secondary and master or slave.
I wouldn't like to write the AHCI driver if it's not necessary. Getting "SATA disks emulating IDE" working would be much easier.
EDIT: link to thread about HDD Detection:
http://forum.osdev.org/viewtopic.php?p=111815