Page 1 of 1

Problem with x86-64 paging in qemu

Posted: Tue May 22, 2012 7:06 am
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

Re: Problem with x86-64 paging in qemu

Posted: Tue May 22, 2012 8:28 am
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.

Re: Problem with x86-64 paging in qemu

Posted: Tue May 22, 2012 10:14 am
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:

Re: Problem with x86-64 paging in qemu

Posted: Tue May 22, 2012 10:18 am
by Griwes
Heh, good point, IDK why I haven't done it like this when I wrote that code...