Page fault when accessing the GRUB framebuffer

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.
Post Reply
User avatar
catOS
Member
Member
Posts: 28
Joined: Tue Mar 31, 2020 6:28 pm

Page fault when accessing the GRUB framebuffer

Post by catOS »

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: Select all

    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: Select all

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 <<
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Page fault when accessing the GRUB framebuffer

Post by iansjack »

Have you mapped the frame buffer in your page table?
klange
Member
Member
Posts: 679
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Page fault when accessing the GRUB framebuffer

Post by klange »

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.
User avatar
catOS
Member
Member
Posts: 28
Joined: Tue Mar 31, 2020 6:28 pm

Re: Page fault when accessing the GRUB framebuffer

Post by catOS »

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 <<
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Page fault when accessing the GRUB framebuffer

Post by iansjack »

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.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Page fault when accessing the GRUB framebuffer

Post by bzt »

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
Post Reply