From c96b289dc49c18ac36fb7e13242e5f855a56840e Mon Sep 17 00:00:00 2001 From: Carlos Maiolino Date: Tue, 24 Feb 2026 08:13:48 +0100 Subject: Add ata driver Enable the kernel to read from an ATA device Signed-off-by: Carlos Maiolino --- src/drivers/ata.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/drivers/ata.c (limited to 'src/drivers') diff --git a/src/drivers/ata.c b/src/drivers/ata.c new file mode 100644 index 0000000..82df0e3 --- /dev/null +++ b/src/drivers/ata.c @@ -0,0 +1,34 @@ +#include + +int +ata_read_sector( + int lba, + int total, + void *buf) +{ + int i, j; + unsigned short *ptr; /* Get 2 bytes at a time from the controller */ + + outb(0x1F6, (lba >> 24) | 0xE0); + outb(0x1F2, total); + outb(0x1F3, (unsigned char)(lba & 0xff)); + outb(0x1F4, (unsigned char)(lba >> 8)); + outb(0x1F5, (unsigned char)(lba >> 16)); + outb(0x1F7, 0x20); + + ptr = (unsigned short *)buf; + + for (i = 0; i < total; i++) { + char c = insb(0x1F7); + /* This should be implemented in interrupts */ + while (!(c & 0x08)) + c = insb(0x1F7); + + for (j = 0; j < 256; j++) { + *ptr = insw(0x1F0); + ptr++; + } + } + + return 0; +} -- cgit v1.2.3