From 23cb50a73f8e226519deb8fdd12b0ef09e1e4588 Mon Sep 17 00:00:00 2001 From: Gregory Bowne Date: Sun, 18 Jan 2026 17:44:18 -0800 Subject: [PATCH] Create ata.h implement the base ata pio mode driver so that the filesystems like fat16, fat32 work. This is the header for that. It will need a iso9660 driver for cdrom etc optical media --- kernel/ata.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 kernel/ata.h diff --git a/kernel/ata.h b/kernel/ata.h new file mode 100644 index 0000000..c503d5c --- /dev/null +++ b/kernel/ata.h @@ -0,0 +1,43 @@ +#ifndef ATA_H +#define ATA_H + +#include +#include + +/* ATA I/O ports */ +#define ATA_PRIMARY_IO 0x1F0 +#define ATA_PRIMARY_CTRL 0x3F6 + +/* ATA registers */ +#define ATA_REG_DATA 0x00 +#define ATA_REG_ERROR 0x01 +#define ATA_REG_FEATURES 0x01 +#define ATA_REG_SECCOUNT0 0x02 +#define ATA_REG_LBA0 0x03 +#define ATA_REG_LBA1 0x04 +#define ATA_REG_LBA2 0x05 +#define ATA_REG_HDDEVSEL 0x06 +#define ATA_REG_COMMAND 0x07 +#define ATA_REG_STATUS 0x07 + +/* ATA commands */ +#define ATA_CMD_READ_PIO 0x20 +#define ATA_CMD_WRITE_PIO 0x30 +#define ATA_CMD_IDENTIFY 0xEC + +/* Status flags */ +#define ATA_SR_BSY 0x80 +#define ATA_SR_DRDY 0x40 +#define ATA_SR_DRQ 0x08 +#define ATA_SR_ERR 0x01 + +/* Drive select */ +#define ATA_MASTER 0x00 +#define ATA_SLAVE 0x10 + +/* Public API */ +bool ata_init(void); +bool ata_read_sector(uint32_t lba, uint8_t* buffer); +bool ata_write_sector(uint32_t lba, const uint8_t* buffer); + +#endif