simple ata pio driver
Posted: Sat Nov 12, 2022 10:58 am
I'm trying to get a simple ATA PIO driver to work. I read https://wiki.osdev.org/ATA_PIO_Mode . But when I try to read(data from disk), I get a PAGE FAULT error. Why could this happen? And how to fix it?
ata.c:
page fault:
[Error 14 at ring 0] 2:0H FFFF80000020C54CH
github link(devel branch):https://github.com/JustVic/melisa_kernel/tree/devel
ata.c:
Code: Select all
#define STATUS_BSY 0x80
#define STATUS_RDY 0x40
#define STATUS_DRQ 0x08
#define STATUS_DF 0x20
#define STATUS_ERR 0x01
static void ATA_wait_BSY();
static void ATA_wait_DRQ();
void read_sectors_ATA_PIO(uint32_t target_address, uint32_t LBA, uint8_t count)
{
ATA_wait_BSY();
port_outb(0x1F6,0xE0 | ((LBA >>24) & 0xF));
port_outb(0x1F2,count);
port_outb(0x1F3, (uint8_t) LBA);
port_outb(0x1F4, (uint8_t)(LBA >> 8));
port_outb(0x1F5, (uint8_t)(LBA >> 16));
port_outb(0x1F7,0x20); //Send the read command
uint16_t *target = (uint16_t*) target_address;
for (int j =0;j<count;j++)
{
ATA_wait_BSY();
ATA_wait_DRQ();
for(int i=0;i<256;i++)
target[i] = port_inw(0x1F0);
target+=256;
}
}
void write_sectors_ATA_PIO(uint32_t LBA, uint8_t count, uint32_t* bytes)
{
...
[Error 14 at ring 0] 2:0H FFFF80000020C54CH
github link(devel branch):https://github.com/JustVic/melisa_kernel/tree/devel