diff --git a/sysdata/programs/diskio_driver/src/main.hb b/sysdata/programs/diskio_driver/src/main.hb index e5edf84..c18b493 100644 --- a/sysdata/programs/diskio_driver/src/main.hb +++ b/sysdata/programs/diskio_driver/src/main.hb @@ -1,4 +1,6 @@ -.{memory, buffer} := @use("../../../libraries/stn/src/lib.hb") +.{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 @@ -7,7 +9,53 @@ main := fn(): int { a := memory.inb(0x4600) b := memory.inb(0x4700) - c := buffer.search("XNumber\0") - + // 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() + } } \ No newline at end of file diff --git a/sysdata/system_config.toml b/sysdata/system_config.toml index e5bf84a..84e2999 100644 --- a/sysdata/system_config.toml +++ b/sysdata/system_config.toml @@ -25,8 +25,8 @@ resolution = "1024x768x24" # [boot.limine.ableos.modules.render_example] # path = "boot:///render_example.hbf" -# [boot.limine.ableos.modules.horizon] -# path = "boot:///horizon.hbf" +[boot.limine.ableos.modules.diskio_driver] +path = "boot:///diskio_driver.hbf" [boot.limine.ableos.modules.ps2_mouse_driver] path = "boot:///ps2_mouse_driver.hbf"