Disabling paging

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
pini

Disabling paging

Post by pini »

I wrote a little thing based upon my kernel.
It works pretty the same, but has rather no features implemented
When a CPL3->CPL0 switch occurs, I'm disabling paging, re-enabling it and switching back to CPL3.
Currently, only the IRQ0 is enabled.

This works perfectly under bochs and qemu and with my two simple Pentium computers (90 and 166), but it reboots when I'm trying it under my two other machines (Pentium III 667 and Pentium 4M 2GHz).

I don't remind of any special difference between these families concerning paging, but maybe I missed something in the Intel books.

Anyone has an idea of why this is happening ?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Disabling paging

Post by Candy »

You might have a case of bad caching there. Think the P3/P4 wille xecute the rest of the code from the current paged history up to a certain point and only then switch to the nonpaged history. You could try to reload CR3 between them?
pini

Re:Disabling paging

Post by pini »

I spent some time handling with the couple cli/hlt to know exactly where was the faulty instruction located.
Surprise : it isn't paging disabling that causes reboot, it's paging enabling.
This is particularly strange, as it is working both in emulators and real machines, so it isn't a problem of missing PDEs or PTEs.

I still don't know what is the real cause, but I will try again and will post feedback
pini

Re:Disabling paging

Post by pini »

here is the faulty code.

Code: Select all

cli
mov    eax,cr0
mov    ecx,[edi + CONTEXT_PD]
mov    esp,[edi + CONTEXT_OFFSET]
or        eax,0x80000000
pop     edx
mov     cr3,ecx
and     esp,MEM_OFFSET_MASK
mov     [edi + CONTEXT_OFFSET],edx
mov     cr0,eax
pop_all
iret
The code about CONTEXT_OFFSET is used for kernel preemption (currently disabled).

pop_all is a macro that simply pops gs,fs,es,ds,ebp,edi,esi,edx,ecx,ebx,eax in this order
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Disabling paging

Post by Candy »

So, you take CR0, or it with 0x80000000 and then move that into CR0 AND CR3? Looks kind of weird, or at least unreliable.
pini

Re:Disabling paging

Post by pini »

You must have mis-read the code above.
I used EAX to compute new CR0 value and ECX to compute new CR3 value.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Disabling paging

Post by Candy »

hm.. ok, slightly dysiectlc...

Assuming this works in bochs, I can't see any reason it wouldn't on a p3/p4.

You don't do PAE stuff anywhere I hope?
pini

Re:Disabling paging

Post by pini »

Candy wrote: You don't do PAE stuff anywhere I hope?
No, I don't
Post Reply