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

67 lines
1.3 KiB
Plaintext
Raw Normal View History

2024-12-04 03:53:13 -06:00
.{memory, buffer, log} := @use("../../../libraries/stn/src/lib.hb")
// Influenced by https://github.com/levex/osdev/blob/master/drivers/ata.c
2024-07-23 19:37:43 -05:00
2024-05-23 16:59:17 -05:00
main := fn(): int {
2024-07-23 19:37:43 -05:00
// shuts down ableOS
2024-09-13 16:41:31 -05:00
// memory.outb(0xF400, 0)
2024-07-23 19:37:43 -05:00
a := memory.inb(0x4600)
b := memory.inb(0x4700)
2024-07-23 19:37:43 -05:00
2024-12-04 03:53:13 -06:00
// c := buffer.search("XNumber\0")
ata := ATA.new()
2024-07-23 19:37:43 -05:00
return 0
2024-12-04 03:53:13 -06:00
}
ATA_PRIMARY := @as(u8, @intcast(0x0))
ATA_PRIMARY_IO := @as(u8, @intcast(0x1F0))
ATA_SECONDARY := @as(u8, @intcast(0x1))
ATA_SECONDARY_IO := @as(u8, @intcast(0x170))
2024-12-04 03:53:13 -06:00
ATA_REG_HDDEVSEL := @as(u8, @intcast(0x6))
ATA_MASTER := @as(u8, @intcast(0x0))
IDE := struct {}
ide_select_drive := fn(bus: u8, i: u8): void {
if bus == ATA_PRIMARY {
if i == ATA_MASTER {
log.info("Primary ATA selected\0")
memory.outb(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, 0xA0)
2024-12-04 03:53:13 -06:00
} else {
memory.outb(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, 0xB0)
2024-12-04 03:53:13 -06:00
}
} else {
if i == ATA_MASTER {
memory.outb(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, 0xA0)
2024-12-04 03:53:13 -06:00
} else {
memory.outb(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, 0xB0)
2024-12-04 03:53:13 -06:00
}
}
}
identify := fn(bus: u8, drive: u8): bool {
io := 0
// BUG: Causes qemu to crash
2024-12-04 03:53:13 -06:00
ide_select_drive(bus, drive)
if bus == ATA_PRIMARY {
io = ATA_PRIMARY_IO
}
return true
}
ata_probe := fn(): void {
if identify(ATA_PRIMARY, ATA_MASTER) {
}
}
ATA := struct {
new := fn(): void {
log.info("Checking for ATA Drives.\0")
// ata_probe()
2024-12-04 03:53:13 -06:00
}
2024-05-23 16:59:17 -05:00
}