OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Page fault when trying to scan for AHCI sata drives
PostPosted: Mon Jun 14, 2021 4:48 am 
Offline

Joined: Mon Jun 14, 2021 4:39 am
Posts: 3
Hello,

i am currently working on AHCI implementation. I use the codebase from "MonkOS" (https://github.com/beevik/MonkOS) and tried to implement AHCI based on the code from https://github.com/ethan4984/rock/blob/ ... ers/ahci.c

getting pci bar information does work but as soon as I start reading from that memory region I get a page fault.
Here is my AHCI_init code so far:

Code:
void ahci_init(struct pci_device *device) {
    switch(device->prog_if) {
        case 0:
            kprint("[AHCI] detected a vendor specific interface (get a new pc)\n");
            return;
        case 1:
            kprint("[AHCI] detetced an AHCI 1.0 compatiable device\n");
            break;
        case 2:
            kprint("[AHCI] detetced a serial storage bus\n");
            return;
    }
   
   
    pci_become_bus_master(device);


    struct pci_bar bar;
    if(pci_get_bar(device, &bar, 5) == -1)
        return;

    pmap_add(PAGE_ALIGN_DOWN(bar.base), PAGE_SIZE, PMEMTYPE_UNCACHED);  //<-- this might be wrong?

    volatile struct GHC *GHC = (volatile struct GHC*)((size_t)bar.base);

    for(int i = 0; i < 32; i++) {
        if(GHC->pi & (1 << i)) {
            volatile struct port_regs *regs = (volatile struct port_regs*)&GHC->port[i];

            switch(regs->sig) {
                case SATA_ATA:
                    kprintf("[AHCI] sata drive found on port %d\n", i);
                    init_sata_device(regs);
                    break;
                case SATA_ATAPI:
                    kprintf("[AHCI] ATAPI drive found on port %d\n", i);
                    break;
                case SATA_SEMB:
                    kprintf("[AHCI] enclosure management bridge found on port %d\n", i);
                    break;
                case SATA_PM:
                    kprintf("[AHCI] port multipler found on port %d\n", i);
                    break;
            }
        }
    }
}


I assume I am doing something wrong with memory mapping. When I put the line "pmap_add(PAGE_ALIGN_DOWN(bar.base), PAGE_SIZE, PMEMTYPE_UNCACHED);" with hardcoded adress values inside the function "pmap_init()" (https://github.com/beevik/MonkOS/blob/m ... map.c#L292) i dont get a page fault. I assume the problem is my AHCI initialization happens after the call to pmap_init()?

Maybe I am misunderstanding the memory management in the codebase of "MonkOS"? Might someone lead me in the right direction?


Top
 Profile  
 
 Post subject: Re: Page fault when trying to scan for AHCI sata drives
PostPosted: Mon Jun 14, 2021 7:04 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
A page fault ought to be easy enough to find. Have you run under a debugger, watching what happens when you map the page?


Top
 Profile  
 
 Post subject: Re: Page fault when trying to scan for AHCI sata drives
PostPosted: Tue Jun 15, 2021 1:07 am 
Offline

Joined: Mon Jun 14, 2021 4:39 am
Posts: 3
iansjack wrote:
A page fault ought to be easy enough to find. Have you run under a debugger, watching what happens when you map the page?


no not yet, I will try as soon as I get a working GDB connection to qemu... :roll:


//EDIT: Ok I managed to attach gdb to the VM but I still dont get the problem. The Page Fault error occures as soon as i try to access the GHC values. Its this line:
Code:
if(GHC->pi & (1 << i)) {


I have the feeling I am completly misunderstanding the memory management implementation of the MonkOS codebase. Could someone maybe explain to me the memory management implementation of monkOS? [-o<


Top
 Profile  
 
 Post subject: Re: Page fault when trying to scan for AHCI sata drives
PostPosted: Tue Jun 15, 2021 8:36 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
C0dR wrote:
I have the feeling I am completly misunderstanding the memory management implementation of the MonkOS codebase. Could someone maybe explain to me the memory management implementation of monkOS? [-o<

It looks like MonkOS is only capable of mapping usable RAM in the page tables. You'll have to write new code to handle mapping and unmapping MMIO.


Top
 Profile  
 
 Post subject: Re: Page fault when trying to scan for AHCI sata drives
PostPosted: Tue Jun 22, 2021 1:28 am 
Offline

Joined: Mon Jun 14, 2021 4:39 am
Posts: 3
Octocontrabass wrote:
C0dR wrote:
I have the feeling I am completly misunderstanding the memory management implementation of the MonkOS codebase. Could someone maybe explain to me the memory management implementation of monkOS? [-o<

It looks like MonkOS is only capable of mapping usable RAM in the page tables. You'll have to write new code to handle mapping and unmapping MMIO.


OK I see, that explains. Thank you, that led me in the right direction!


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 75 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