Changing CR3
Posted: Mon Mar 28, 2005 1:47 pm
Consider the following code :
At the end, you can see this instruction : which loads the page directory of the next task to EAX, and then EAX is put in CR3.
This code works good with both bochs and qemu.
In fact, with my initial task example, the page directory is located at 0x1003000, which is correct (I printed this value out before writing to CR3).
But when I do the same with my real P4M, EAX contains the value 0x1003F80, which is false, and obviously the computer reboots when I write CR3.
I can't figure out why this is happening. Any idea ?
Code: Select all
mov edx,cr3
mov ebx,[edi + CONTEXT_KSTACK]
mov eax,[edx + (ADDRESS_KSTACK shr (MEM_PTE_BITS + MEM_OFFSET_BITS))]
or ebx,MEM_PAGE_PRESENT or MEM_PAGE_WRITEABLE
and eax,MEM_PAGE_MASK
mov [eax + (((ADDRESS_KSTACK and MEM_PTE_MASK) shr MEM_OFFSET_BITS) shl 2)],ebx
invlpg [ADDRESS_KSTACK]
; The code above is just used to map the process context in the kernel address space
mov esp,[edi + CONTEXT_OFFSET]
pop eax
mov [edi + CONTEXT_OFFSET],eax
mov eax,[edi + CONTEXT_PD]
mov cr3,eax
pop_all
iret
Code: Select all
mov eax,[edi + CONTEXT_PD]
This code works good with both bochs and qemu.
In fact, with my initial task example, the page directory is located at 0x1003000, which is correct (I printed this value out before writing to CR3).
But when I do the same with my real P4M, EAX contains the value 0x1003F80, which is false, and obviously the computer reboots when I write CR3.
I can't figure out why this is happening. Any idea ?