Page 1 of 1

Kernel works on bochs not on qemu.

Posted: Sun Oct 20, 2013 3:18 pm
by summersong
fasm, long mode

Memory mapped at phys 0000:0000:0000:0000 -> log 0000:0000:4000:0000 (+ 1 Gb). First gigabyte (log) is reserved to tasks. All tasks is loaded at 0000:0000:0000:0000 (log). Each task has own PML3 (PDP) page table. When I switch task, I rewrite PML3[0] like that:

Code: Select all

KERNEL_ORG = 1024*1024*1024 ; 1 Gb

mov rax,[rsi + Task.PML3]
mov [PML3_PHYS + KERNEL_ORG],rax
wbinvd
My log:
task old_task (ID) -> new_task

and new task PML trace:
cr3 -- PML4[0] ; (PML4) 512 Gb pages
cr3 -- PML3[0] ; (PDP) 1 Gb pages
cr3 -- PML2[0] ; (PD) 2 Mb pages
cr3 -- PML1[0] ; (PT) 4 kb pages
Bochs:
task 0000:0000:4009:E870 -> 0000:0000:4009:A870
cr3 -- 0000:0000:0000:4027
cr3 -- 0000:0000:0009:7007
cr3 -- 0000:0000:0009:8007
cr3 -- 0000:0000:0009:A007

task 0000:0000:4009:A870 -> 0000:0000:4009:E870
cr3 -- 0000:0000:0000:4027
cr3 -- 0000:0000:0009:B007
cr3 -- 0000:0000:0009:C007
cr3 -- 0000:0000:0009:E007

task 0000:0000:4009:E870 -> 0000:0000:4009:A870
cr3 -- 0000:0000:0000:4027
cr3 -- 0000:0000:0009:7007
cr3 -- 0000:0000:0009:8027
cr3 -- 0000:0000:0009:A027
Qemu:
task 0000:0000:407D:CB70 -> 0000:0000:4009:B470
cr3 -- 0000:0000:0000:4027
cr3 -- 0000:0000:0009:7C07
cr3 -- 0000:0000:0009:8C07
cr3 -- 0000:0000:0009:AC07

exc PF cr2 0000:0000:0000:0000
First of all, I don't know why "0x27" at PML. I was set 7 (PG_PRESENT + PG_WRITEABLE + PG_USER) everywhere.

Second, I don't know why qemu do that.

Please, help me.

Re: Kernel works on bochs not on qemu.

Posted: Mon Oct 21, 2013 4:05 am
by stlw
0x27 is easy - the Accessed bit (bit 5) is set.

BDW, the wbinvd has no meaning in this case.
On every processor the cache is coherent memory so no need to write back data from cache explicitly.
Might be you should to TLB invalidation instead ?

Stanislav

Re: Kernel works on bochs not on qemu.

Posted: Mon Oct 21, 2013 7:00 am
by summersong
Thank you.
Now instead of "wbinvd" is "mov rax,cr3 mov cr3,rax", but it doesn't help.

I try to make a very simple example of task switching without any other init. Maybe I can find the error.