ableos/sysdata/programs/diskio_driver/src/main.hb

79 lines
1.6 KiB
Plaintext

.{memory, buffer, log} := @use("../../../libraries/stn/src/lib.hb");
.{inb, outb} := memory
regs := @use("regs.hb");
.{ATA_PRIMARY_COMM_REGSTAT, ATA_PRIMARY_DRIVE_HEAD, ATA_PRIMARY_SECCOUNT, ATA_PRIMARY_LBA_LO, ATA_PRIMARY_LBA_MID, ATA_PRIMARY_LBA_HI, STAT_BSY} := regs
sloop := fn(): void {
idx := 0xFFFFFFF
loop {
if idx == 0 {
break
} else {
idx -= 1
}
}
}
identify := fn(): u8 {
a := inb(ATA_PRIMARY_COMM_REGSTAT)
outb(ATA_PRIMARY_DRIVE_HEAD, 0xA0)
log.info("Primary drive head set.\0")
a = inb(ATA_PRIMARY_COMM_REGSTAT)
outb(ATA_PRIMARY_SECCOUNT, 0)
a = inb(ATA_PRIMARY_COMM_REGSTAT)
outb(ATA_PRIMARY_LBA_LO, 0)
a = inb(ATA_PRIMARY_COMM_REGSTAT)
outb(ATA_PRIMARY_LBA_MID, 0)
a = inb(ATA_PRIMARY_COMM_REGSTAT)
outb(ATA_PRIMARY_LBA_HI, 0)
a = inb(ATA_PRIMARY_COMM_REGSTAT)
outb(ATA_PRIMARY_COMM_REGSTAT, 0xEC)
outb(ATA_PRIMARY_COMM_REGSTAT, 0xE7)
status := inb(ATA_PRIMARY_COMM_REGSTAT)
log.info("Waiting for status.\0")
loop {
if (status & STAT_BSY) == 0 {
break
} else {
sloop()
}
status = inb(ATA_PRIMARY_COMM_REGSTAT)
}
log.info("Status got\0")
if status == 0 return 0
log.info("Status indicates presence of a drive. Polling while STAT_BSY... \0")
loop {
if (status & STAT_BSY) == 0 {
break
} else {
sloop()
}
status = inb(ATA_PRIMARY_COMM_REGSTAT)
}
mid := inb(ATA_PRIMARY_LBA_MID)
hi := inb(ATA_PRIMARY_LBA_HI)
if (mid | hi) == 0 {
log.error("The drive is not ATA. (Who knows what it is.)\0")
return 0
}
return 0
}
main := fn(): int {
// shuts down ableOS
// outb(0xF400, 0)
a := inb(0x4600)
b := inb(0x4700)
// c := buffer.search("XNumber\0")
c := identify()
return 0
}