diff options
| author | Carlos Maiolino <[email protected]> | 2026-02-24 08:13:48 +0100 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2026-02-24 20:24:57 +0100 |
| commit | c96b289dc49c18ac36fb7e13242e5f855a56840e (patch) | |
| tree | 01235198a6b4148e3bd00b1dd03aa69e6dd76afd | |
| parent | dae0a3cbf6dba6fc537f943362021f4d8ffcd859 (diff) | |
Add ata driver
Enable the kernel to read from an ATA device
Signed-off-by: Carlos Maiolino <[email protected]>
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | src/drivers/ata.c | 34 | ||||
| -rw-r--r-- | src/kernel.c | 4 |
3 files changed, 44 insertions, 0 deletions
@@ -19,6 +19,7 @@ KOBJ_FILES = $(KERNEL_ASM_OBJ) \ ./build/mm/kernel_heap.o \ ./build/mm/paging.asm.o \ ./build/mm/paging.o \ + ./build/drivers/ata.o BOOT_TGT =./bin/boot.bin @@ -79,6 +80,10 @@ $(BUILD_DIR)/mm/paging.asm.o: ./src/mm/paging.asm $(BUILD_DIR)/mm/paging.o: ./src/mm/paging.c i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./src/mm/paging.c -o $(BUILD_DIR)/mm/paging.o + +$(BUILD_DIR)/drivers/ata.o: ./src/drivers/ata.c + i686-elf-gcc $(INCLUDES) $(FLAGS) -std=gnu99 -c ./src/drivers/ata.c -o $(BUILD_DIR)/drivers/ata.o + clean: rm -f $(BOOT_TGT) rm -f bin/kernel.bin @@ -91,4 +96,5 @@ clean: rm -f build/idt/idt.o rm -f build/io/io.asm.o rm -f build/mm/*.o + rm -f build/drivers/*.o rm -f bin/os.bin 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 <toxic/io.h> + +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; +} diff --git a/src/kernel.c b/src/kernel.c index 01de04f..d917bd8 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -7,11 +7,14 @@ #include <toxic/io.h> #include <mm/kernel_heap.h> #include <mm/paging.h> +#include <ata/ata.h> static struct page_directory *kernel_directory; void start_kernel() { + char buf[512] = {0}; + init_display(2); vprintl("Hello World!!!\n"); vprintl("Testing it!!!\n"); @@ -48,4 +51,5 @@ void start_kernel() kfree(ptr); + ata_read_sector(0, 1, buf); } |
