OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 9:17 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: simple ata pio driver
PostPosted: Sat Nov 12, 2022 10:58 am 
Offline

Joined: Tue Jul 07, 2020 3:18 pm
Posts: 15
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:
#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.

Top
 Profile  
 
 Post subject: Re: simple ata pio driver
PostPosted: Sat Nov 12, 2022 11:52 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
What is the value of target_address? Did you map that memory in your paging structures? With what flags?

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: simple ata pio driver
PostPosted: Sat Nov 12, 2022 12:00 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: simple ata pio driver
PostPosted: Sat Nov 12, 2022 12:06 pm 
Offline

Joined: Tue Jul 07, 2020 3:18 pm
Posts: 15
This line make the page fault:
Code:
target[i] = port_inw(0x1F0);


Top
 Profile  
 
 Post subject: Re: simple ata pio driver
PostPosted: Sat Nov 12, 2022 12:14 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: simple ata pio driver
PostPosted: Sat Nov 12, 2022 12:28 pm 
Offline

Joined: Tue Jul 07, 2020 3:18 pm
Posts: 15
Sorry I understood, I just not allocate memory for pointer target_address. :oops:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 58 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group