Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
JustVic
Posts: 17 Joined: Tue Jul 07, 2020 3:18 pm
Post
by JustVic » 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:
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)
{
...
page fault:
[Error 14 at ring 0] 2:0H FFFF80000020C54CH
github link(devel branch):
https://github.com/JustVic/melisa_kernel/tree/devel
Last edited by
JustVic on Sat Nov 12, 2022 12:06 pm, edited 1 time in total.
kzinti
Member
Posts: 898 Joined: Mon Feb 02, 2015 7:11 pm
Post
by kzinti » Sat Nov 12, 2022 11:52 am
What is the value of target_address? Did you map that memory in your paging structures? With what flags?
iansjack
Member
Posts: 4703 Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK
Post
by iansjack » Sat Nov 12, 2022 12:00 pm
What is at the faulting memory location? And what type of access caused the fault? What function is running when the fault occurs? The address of the faulting instruction tells you exactly which line of code is being executed.
JustVic
Posts: 17 Joined: Tue Jul 07, 2020 3:18 pm
Post
by JustVic » Sat Nov 12, 2022 12:06 pm
This line make the page fault:
iansjack
Member
Posts: 4703 Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK
Post
by iansjack » Sat Nov 12, 2022 12:14 pm
Then, as kzinti says, you haven’t mapped that address (or you’ve mapped it with the wrong access rights).
Looking further, I can’t see where you have defined the address of your buffer. You declare *target but don’t seem to assign a value to that pointer.
JustVic
Posts: 17 Joined: Tue Jul 07, 2020 3:18 pm
Post
by JustVic » Sat Nov 12, 2022 12:28 pm
Sorry I understood, I just not allocate memory for pointer target_address.