OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Page fault when accessing the GRUB framebuffer
PostPosted: Tue May 18, 2021 4:58 am 
Offline
Member
Member
User avatar

Joined: Tue Mar 31, 2020 6:28 pm
Posts: 28
Hello,

In my OS (x86_64), I am supporting multiboot2. I've done the normal procedure of parsing the multiboot structure and retrieving a framebuffer and various information. But here's the part that bugs me, if I try the following demo, a page fault will occur

Code:
    uint32_t* fb_addr = (uint32_t*)uheader.framebuffer_addr;

    for(size_t i = 0; i < uheader.framebuffer_width; i++)
    {
        fb_addr[i] = 0x34eb7d;
        fb_addr[i + uheader.framebuffer_width] = 0x34eb7d;
        fb_addr[i + (uheader.framebuffer_width * 2)] = 0x34eb7d;
        fb_addr[i + (uheader.framebuffer_width * 3)] = 0x34eb7d;
        fb_addr[i + (uheader.framebuffer_width * 4)] = 0x34eb7d;
        for(int i = 0; i < 1000000; i++); // latency test
    }


Code:
bootloader_name: GRUB 2.04-1ubuntu26.8
command_line:
framebuffer: addr=0xfd000000; width=800; height=600

int_num=0xe; error=0x2
kernel panic!
    occurred in file arch/x86_64/features/interrupts.cpp:69:0 in the function 'page_fault_handler()'
    page fault


but if I use Limine the code runs fine without any problems.

I'm not exactly sure what's causing this issue. I thought that maybe it has something to do about being in long mode

https://github.com/ackOS-project/ackOS

_________________
Visit ackOS's GitHub page:
>> https://github.com/ackOS-project/ackOS <<


Top
 Profile  
 
 Post subject: Re: Page fault when accessing the GRUB framebuffer
PostPosted: Tue May 18, 2021 5:09 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Have you mapped the frame buffer in your page table?


Top
 Profile  
 
 Post subject: Re: Page fault when accessing the GRUB framebuffer
PostPosted: Tue May 18, 2021 5:26 am 
Offline
Member
Member

Joined: Wed Mar 30, 2011 12:31 am
Posts: 676
catOS wrote:
but if I use Limine the code runs fine without any problems.

I'm not exactly sure what's causing this issue. I thought that maybe it has something to do about being in long mode

https://github.com/ackOS-project/ackOS

Your longmode bootstrap appears to be only mapping one 2MiB page, which obviously will not get you the region just below 4GiB where that framebuffer lives. Limine's stivale spec loads an identity map for all of the 32-bit address space.

_________________
toaruos on github | toaruos.org | gitlab | twitter | bim - a text editor


Top
 Profile  
 
 Post subject: Re: Page fault when accessing the GRUB framebuffer
PostPosted: Wed May 19, 2021 4:45 am 
Offline
Member
Member
User avatar

Joined: Tue Mar 31, 2020 6:28 pm
Posts: 28
iansjack wrote:
Have you mapped the frame buffer in your page table?

no, but how?

_________________
Visit ackOS's GitHub page:
>> https://github.com/ackOS-project/ackOS <<


Top
 Profile  
 
 Post subject: Re: Page fault when accessing the GRUB framebuffer
PostPosted: Wed May 19, 2021 5:09 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
catOS wrote:
iansjack wrote:
Have you mapped the frame buffer in your page table?

no, but how?

The same way that you map any other memory pages. Just make an entry for the memory range in your page table. It's probably easier to identity map the range, but you could assign it a different virtual address if you wish.

When you are in paging mode any memory that you address must be mapped in your page tables.


Top
 Profile  
 
 Post subject: Re: Page fault when accessing the GRUB framebuffer
PostPosted: Wed May 19, 2021 12:10 pm 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 1584
catOS wrote:
iansjack wrote:
Have you mapped the frame buffer in your page table?

no, but how?
Take a look at BOOTBOOT source code. Unlike limine and Grub, it will map the framebuffer for you. It is MIT licensed, so feel free to study its source.
Mapping framebuffer is special, should be handled as MMIO, and not like normal RAM (for one, always use write-through policy).

Cheers,
bzt


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: Bing [Bot] and 64 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