Add ATA PIO IRQ handler, documentation
Still WIP, doesn't look like IRQ handler works yet.
diff --git a/src/kernel/dri/ata_pio/ata_pio.c b/src/kernel/dri/ata_pio/ata_pio.c
index cf55b51..cd426ef 100644
--- a/src/kernel/dri/ata_pio/ata_pio.c
+++ b/src/kernel/dri/ata_pio/ata_pio.c
@@ -2,6 +2,7 @@
#include <io.h>
#include <log.h>
+#include <pic.h>
/* TODO: Rewrite all of this to work with dri_ide in the case of multiple
* devices */
@@ -51,7 +52,7 @@
ata_pio_wait_bsy();
}
-void ata_pio_write_sectors(uint lba, uchar num_sectors, void *buffer)
+void ata_pio_write_sectors(uint lba, uchar num_sectors, ushort *buffer)
{
ata_pio_wait_bsy();
@@ -60,8 +61,10 @@
ata_pio_wait_bsy();
- asm volatile("rep outsw" :: "c"(num_sectors * 256), "d"(ATA_PORT_DATA),
- "S"(buffer));
+ for (int i = 0; i < (num_sectors * 256); i++)
+ {
+ outw(ATA_PORT_DATA, buffer[i]);
+ }
}
static void print_buffer()
@@ -89,3 +92,53 @@
// ata_pio_read_sectors(test_buffer, 0, 1);
// print_buffer();
}
+
+void ata_pio_handle_irq(struct registers *regs)
+{
+ // TODO: check that this IRQ came from the hard drive
+
+ // TODO: use a lock and inform the scheduler that the thread waiting for
+ // this can stop sleeping
+
+ // Acknowledge the IRQ
+ uchar status = inw(ATA_PORT_STATUS);
+
+ kprintf(DEBUG "ATA PIO IRQ received %d (0x%x)\n", status, status);
+}
+
+void init_ata_pio()
+{
+ add_interrupt_handler(46, ata_pio_handle_irq);
+
+/*
+ // TODO: Consider adding this back.
+
+ // 0xA0 for master, 0xB0 for slave
+ outb(ATA_PORT_DRIVE_SEL, 0xA0);
+
+ outb(ATA_PORT_LBA_LOW, 0);
+ outb(ATA_PORT_LBA_MID, 0);
+ outb(ATA_PORT_LBA_HIGH, 0);
+
+ outb(ATA_PORT_CMD, ATA_CMD_IDENTIFY);
+
+ if (inb(ATA_PORT_STATUS))
+ {
+ kprintf(OKAY "ATA drive exists\n");
+
+ // Wait until either DRQ or ERR is set
+ uchar status;
+ while ((status = inb(ATA_PORT_STATUS)) & (ATA_DRQ | ATA_ERR))
+ {
+ if (status & ATA_ERR)
+ {
+
+ }
+ }
+ }
+ else
+ {
+ kprintf(ERROR "ATA drive does not exist\n");
+ }
+*/
+}