Phoenix wrote:Combuster wrote:
Setting PE in CR0 will immediately cause an entry to protected mode,
NO, It wont.
Please make a test and read manuals !
If you don't change CS, you are in real mode. It doesn't matter PE bit in cr0
This is in pmode
mov eax,cr0
or eax,1
mov cr0,eax
jmp far 08h:main32 ;08 code segment
main32:
BUT This is NOT !
mov eax,cr0
or eax,1
mov cr0,eax
the intel manuals are very clear (check section 2.5)
immediately when you activate the PE bit you are in PMode -- before the switch, your CS hidden portion is duplicated from the internal GDT which the CPU uses in RMode, which is: 16bit, 64k length, base = 0x10*CS, ring 0
this is exactly why UMode works
the only reason you would ever need to do a jump upon entering PMode, is to change to 32bit, or enlarge the segment (or change the base)
even in RMode, every time the segment selectors are loaded, the hidden portion is loaded from the GDT, but in RMode it is redirected to an internal table, instead of the normal GDT pointer
2)Switch back to real mode
Now your TLBs were filled and you will be unreal mode...
(P.S.: And ofcourse only clearing 0.bit of cr0 doesn't make any changes, you must change CS too)
also untrue:
you are in RMode -- even if it is 32bit, 4GB length, base=0 RMode
it is still RMode (although if your segment is not 16bit/64k/base = 0x10*CS you should change it -- because the first interrupt or call will trash the current state, and on ret/iret it will resume executing in invalid memory (and the TLBs are
never filled with
anything unless paging is enabled)
i recommend rereading intel manuals volume3, chapter 2&3
section 9.9.1 is a little misleading, and prob where your getting that information:
1) the book assumes you want 32bit PMode
2) the book assumes you care if the instructions are translated improperly on the P5
the warning about steps 3&4 refer to the P5 -- the translation engine wouldnt know that it was in PMode until after the mov had been completed, and would therefore occasionally translate them improperly, an absolute jump, would clear the instruction cache and pipeline, and force all instructions to be reloaded and retranslated -- however, absolute jumps are now executed by the prefetch engine (rather than the execution core) and only reloaded if the GDT was altered between the prefetch and the execution of the jump, and translation engine is notified of the switch, so no manual clearing is necessary -- if you were going to stay in PMode, you should probably switch to 32bit 0-based segment anyway, and if your not, then it doesnt matter (for setting up UMode, it is unnecessary)