.{memory, buffer, log} := @use("../../../libraries/stn/src/lib.hb") // Influenced by https://github.com/levex/osdev/blob/master/drivers/ata.c main := fn(): int { // shuts down ableOS // memory.outb(0xF400, 0) a := memory.inb(0x4600) b := memory.inb(0x4700) // c := buffer.search("XNumber\0") ata := ATA.new() return 0 } ATA_PRIMARY := @as(u8, @intcast(0x0)) ATA_PRIMARY_IO := @as(u8, @intcast(0x1F0)) 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 { // BUG: Causes qemu to crash // memory.outb(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, 0xA0) } else { // outportb(ATA_PRIMARY_IO + ATA_REG_HDDEVSEL, 0xB0); } } else { if i == ATA_MASTER { // outportb(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, 0xA0); } else { // outportb(ATA_SECONDARY_IO + ATA_REG_HDDEVSEL, 0xB0) } } } identify := fn(bus: u8, drive: u8): bool { io := 0 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 { ata_probe() } }