1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/sysdata/programs/diskio_driver/src/main.hb

134 lines
2.6 KiB
Plaintext
Raw Normal View History

.{memory, buffer, log} := @use("../../../libraries/stn/src/lib.hb");
.{inb, outb} := memory
2024-12-04 03:53:13 -06:00
regs := @use("regs.hb");
2024-12-07 10:44:29 -06:00
.{ATA_PRIMARY_IO, ATA_PRIMARY_DEVCTL, ATA_SECONDARY_DEVCTL, ATA_REG_STAT, ATA_SR_ERR, ATA_SR_BSY, ATA_SR_DF, ATA_SR_DRQ} := regs
sloop := fn(i: u8): void {
// idx := 0xFFFFFFF
// loop {
// if idx == 0 {
// break
// } else {
// idx -= 1
// }
// }
2024-07-23 19:37:43 -05:00
loop {
2024-12-07 10:44:29 -06:00
if i == 0 {
break
} else {
2024-12-07 10:44:29 -06:00
a := inb(ATA_SECONDARY_DEVCTL)
i -= 1
}
}
2024-12-04 03:53:13 -06:00
}
2024-12-07 10:44:29 -06:00
// 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 {
// log.info("Status got.\0")
// break
// } else {
// sloop()
// }
// status = inb(ATA_PRIMARY_COMM_REGSTAT)
// }
// if status == 0 {
// log.error("No drive detected.\0")
// return 0
// }
// log.info("Status indicates presence of a drive. Polling while STAT_BSY... \0")
// loop {
// if (status & STAT_BSY) == 0 {
// log.info("Status got.\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
// }
drive_reset := fn(): void {
log.warn("Drive resetting.\0")
outb(ATA_PRIMARY_DEVCTL, 0x4)
sloop(4)
outb(ATA_PRIMARY_DEVCTL, 0x0)
}
poll := fn(): u8 {
sloop(4)
status := 0
// busy loop waiting for status
loop {
2024-12-07 10:44:29 -06:00
status = inb(ATA_PRIMARY_IO + ATA_REG_STAT)
if (status & ATA_SR_BSY) == 0 {
break
2024-12-04 03:53:13 -06:00
}
}
2024-12-07 10:44:29 -06:00
status = inb(ATA_PRIMARY_IO + ATA_REG_STAT)
if (status & ATA_SR_DF) == 0 {
log.error("ATA PRIMARY DRIVE FAULT\0")
return 1
2024-12-04 03:53:13 -06:00
}
2024-12-07 10:44:29 -06:00
if (status & ATA_SR_ERR) == 0 {
log.error("ATA PRIMARY ERR\0")
return 2
}
2024-12-04 03:53:13 -06:00
2024-12-07 10:44:29 -06:00
if (status & ATA_SR_DRQ) == 0 {
log.error("ATA PRIMARY DRQ\0")
return 3
2024-12-04 03:53:13 -06:00
}
return 0
2024-12-04 03:53:13 -06:00
}
2024-12-07 10:44:29 -06:00
main := fn(): int {
// shuts down ableOS
// outb(0xF400, 0)
2024-12-04 03:53:13 -06:00
a := inb(0x4600)
b := inb(0x4700)
2024-12-04 03:53:13 -06:00
// c := buffer.search("XNumber\0")
2024-12-07 10:44:29 -06:00
// c := identify()
d := drive_reset()
e := poll()
return 0
2024-05-23 16:59:17 -05:00
}