NASM Forum > Programming with NASM

Ok I finally got this working.

<< < (2/2)

fredericopissarra:
Here's an example on how to go to protected mode (not back to real mode) using a lagacy MBR...

Notice, as an example, you forgot to enable Gate A20 when jumping to protected mode (and disable it when back to real mode).

ben321:

--- Quote from: fredericopissarra on February 22, 2023, 12:37:22 PM ---Notice, as an example, you forgot to enable Gate A20 when jumping to protected mode (and disable it when back to real mode).

--- End quote ---
I wasn't using the extra memory space, just testing how to transition in and out of protected mode.

ben321:

--- Quote from: fredericopissarra on February 22, 2023, 12:25:59 PM ---See table 9.1 at Intel SDM to have an idea of how to do it... Notice you load the segment descriptors with Granularity flags turned on and never turned it off to go back to real mode (just an example). As for the far jump, to go to protected mode you should do a far 32 bits jump after loading GDTR, not a simple far jump. You are probably NOT in protected mode there because the processor will jump to protected mode just after this specific kind of jump.

--- End quote ---

I absolutely was in protected mode. I made sure to use a far jump (or in this case a far call). If you read the code I posted at the top of this thread (in fact you initially were replying directly to the code I'd written, when you criticized it), you would see I did make this far call. In fact, DosBox Debugger is what I used to test my code, and like any good debugger it reports the internal state of the CPU. Its mode indicator changed from Real to Pr32 when I made that far call. And after turning off the CR0 bit and then making a far return, the debugger's mode indicator went back to showing Real. And I didn't even have to reload the GDT. Then when I exited to leave back to DOS, I had no problems. Had I attempted to go back to DOS while still in protected mode, it would have crashed.

However you say you need to reload the GDTR when leaving protected mode (even though it worked for me in DosBox without doing this step). So, please inform me more about that. What am I supposed to reload the GDTR with, in order to properly leave protected mode? Am I supposed to load it with a null pointer? Also, am I supposed to do this reloading of the GDTR just before or after I clear the PE bit in CR0?

Navigation

[0] Message Index

[*] Previous page

Go to full version