I've recently been trying to identify an ATA PIO drive, following the wiki's instructions. Reading the STATUS port works, but the BSY bit of the STATUS port never clears.
My code is in Rust, but it should hopefully be pretty self explanatory.
Code: Select all
pub fn init() {
unsafe {
io::outb(DRIVESEL, 0xE0);
io::outb(SECTOR_COUNT, 0);
io::outb(LBAL, 0);
io::outb(LBAM, 0);
io::outb(LBAH, 0);
io::outb(COMMAND, ATACommand::IdentifyDevice as u8);
if io::inb(STATUS) == 0 {
println!("ATA: master not found");
} else {
println!("ATA: master found");
}
io::outb(DRIVESEL, 0xF0);
io::outb(SECTOR_COUNT, 0);
io::outb(LBAL, 0);
io::outb(LBAM, 0);
io::outb(LBAH, 0);
io::outb(COMMAND, ATACommand::IdentifyDevice as u8);
if io::inb(STATUS) == 0 {
println!("ATA: slave not found");
} else {
println!("ATA: slave found");
}
while io::inb(STATUS).get_bit(BSY) {
crate::hlt_loop();
}
if io::inb(STATUS).get_bit(DRQ) && !io::inb(STATUS).get_bit(ERR) {
let mut data: [u16; 256] = [0; 256];
for i in 0..data.len() {
data[i] = io::inw(DATA);
print!("{}", data[i]);
}
} else {
println!("ATA: read error");
return;
}
}
}