2024-12-04 04:21:24 -06:00
|
|
|
.{memory, buffer, log} := @use("../../../libraries/stn/src/lib.hb");
|
|
|
|
.{inb, outb} := memory
|
2024-12-04 03:53:13 -06:00
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
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
|
2024-07-23 19:37:43 -05:00
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
sloop := fn(): void {
|
|
|
|
idx := 0xFFFFFFF
|
|
|
|
loop {
|
|
|
|
if idx == 0 {
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
idx -= 1
|
|
|
|
}
|
|
|
|
}
|
2024-12-04 03:53:13 -06:00
|
|
|
}
|
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
identify := fn(): u8 {
|
|
|
|
a := inb(ATA_PRIMARY_COMM_REGSTAT)
|
|
|
|
outb(ATA_PRIMARY_DRIVE_HEAD, 0xA0)
|
|
|
|
log.info("Primary drive head set.\0")
|
2024-12-04 03:58:23 -06:00
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
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)
|
2024-12-04 03:58:23 -06:00
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
status := inb(ATA_PRIMARY_COMM_REGSTAT)
|
|
|
|
log.info("Waiting for status.\0")
|
|
|
|
loop {
|
|
|
|
if (status & STAT_BSY) == 0 {
|
|
|
|
break
|
2024-12-04 03:53:13 -06:00
|
|
|
} else {
|
2024-12-04 04:21:24 -06:00
|
|
|
sloop()
|
2024-12-04 03:53:13 -06:00
|
|
|
}
|
2024-12-04 04:21:24 -06:00
|
|
|
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
|
2024-12-04 03:53:13 -06:00
|
|
|
} else {
|
2024-12-04 04:21:24 -06:00
|
|
|
sloop()
|
2024-12-04 03:53:13 -06:00
|
|
|
}
|
2024-12-04 04:21:24 -06:00
|
|
|
status = inb(ATA_PRIMARY_COMM_REGSTAT)
|
2024-12-04 03:53:13 -06:00
|
|
|
}
|
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
mid := inb(ATA_PRIMARY_LBA_MID)
|
|
|
|
hi := inb(ATA_PRIMARY_LBA_HI)
|
2024-12-04 03:53:13 -06:00
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
if (mid | hi) == 0 {
|
|
|
|
log.error("The drive is not ATA. (Who knows what it is.)\0")
|
|
|
|
return 0
|
2024-12-04 03:53:13 -06:00
|
|
|
}
|
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
return 0
|
2024-12-04 03:53:13 -06:00
|
|
|
}
|
2024-12-04 04:21:24 -06:00
|
|
|
main := fn(): int {
|
|
|
|
// shuts down ableOS
|
|
|
|
// outb(0xF400, 0)
|
2024-12-04 03:53:13 -06:00
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
a := inb(0x4600)
|
|
|
|
b := inb(0x4700)
|
2024-12-04 03:53:13 -06:00
|
|
|
|
2024-12-04 04:21:24 -06:00
|
|
|
// c := buffer.search("XNumber\0")
|
|
|
|
c := identify()
|
|
|
|
|
|
|
|
return 0
|
2024-05-23 16:59:17 -05:00
|
|
|
}
|