Problem with x86-64 paging in qemu

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
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Problem with x86-64 paging in qemu

Post by Griwes »

For most time, I had been testing my code in Bochs only - and it worked without any problem. But today, I tried in QEMU - and it failed. I found the piece of code that caused triple fault - it happened on "jmp rax", where rax = 0xffffffff80000020. I checked the paging setup, using info mem:

Code: Select all

(qemu) info mem
0000000000000000-0000000004000000 0000000004000000 -rw
0000000008000000-0000000008006000 0000000000006000 -rw
00000000f0000000-00000000f00eb000 00000000000eb000 -rw
0000ffff80000000-0000ffff810d4000 00000000010d4000 -rw
Note the last entry, starting at 0xffff80000000 - it should be 0xffffffff80000000, of course, as 0xffff80000000 isn't canonical address. I confirmed that my code used to setup paging structures is right using some simple prints in bootloader's memory mapping code; I'm only touching 510th and 511th entries of 511th PML4 entry. Bochs works fine with jumping to 0xffffffff80000000.

Does anyone have any idea what to do to make this work?

Paging at the moment when QEMU fails is set by functions called from here; the code that fails is:

Code: Select all

bits    64

global  entry
extern  kernel_main

entry:
    mov     rax, qword 0xFFFFFFFF80000000
    add     rax, byte 32
    jmp     rax

times 32 - ($-$$) db 0

highmemory:
    hlt
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: Problem with x86-64 paging in qemu

Post by Griwes »

Seems that that entry in info mem is just visual bug; I started QEMU with -no-kvm and it worked. Yet, the entire problem seems weird to me.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Problem with x86-64 paging in qemu

Post by bluemoon »

As a side note, if your startup code is position independent and the whole kernel is linked at high address, you can just do:

Code: Select all

    mov     rax, qword highmemory
    jmp     rax
highmemory:
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: Problem with x86-64 paging in qemu

Post by Griwes »

Heh, good point, IDK why I haven't done it like this when I wrote that code...
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Post Reply