2 ms·
>Do we leave real mode as soon as CR0 bit 1 is set Yes, that's what the bit is defined as doing. Protected mode was introduced on the 16-bit 80286, and 16-bit
by rep_lodsb 5y ago
>Do we leave real mode as soon as CR0 bit 1 is set
Yes, that's what the bit is defined as doing. Protected mode was introduced on the 16-bit 80286, and 16-bit code segment descriptors are still supported to this day.
Even in real mode, the segment registers have hidden fields containing base, limit and access rights. The difference is that when they get loaded in real mode, the base will be set to the segment shifted left by 4 bits, with the limit¹ and access rights² generally left unchanged. What the PE bit actually affects is how segment load instructions operate, how interrupts/exceptions are handled, and a few other details.
Most instructions run exactly the same microcode in either mode: any memory access will form the address and do protection checks based on whatever is currently in those hidden fields. But a segment load (or far jump) decoded while PE=0 will execute different microcode than one with PE=1.
>That's weird. I tracked down the commit
Shuffling the code around may have fixed some alignment bug? The jump could likely be replaced by two NOPs, in any case the comment is completely wrong.
2.6.22 seems to be the last version using LMSW followed by a near jump, and presumably worked on that CPU (at least there is a comment mentioning bugfixes for Elan), so it isn't likely to be the cause of the problem.
¹ the limit on power-on/reset is 64K, but it is possible to change it to 4G, allowing access to all memory ("unreal mode")
² CS will always be made a writable data segment, something not possible to set up in protected mode without the use of LOADALL
edit:
>Interesting. The new Intel docs explicitly say to do the far jump "Immediately" after setting the PE bit in CR0.
Well, it's probably not required to do any kind of jump immediately on modern CPUs, but it wouldn't be the first time Intel got something completely wrong:
https://www.os2museum.com/wp/sgdtsidt-fiction-and-reality/ https://www.os2museum.com/wp/sgdtsidt-fiction-and-reality/