Could not switch back to Real-Address mode from Protected Mode. Help?
- From: "jfguo" <spamtrap@xxxxxxxxxx>
- Date: 29 Aug 2006 01:56:39 -0700
I am writing a function to switch from Protected Mode to Real Mode, but
the code does't work. The program crashes when doing the second far
jump.
I followed the steps of section 9.9.2 of Intel IA32 Manual Vol3 (June
2005 version),
and checked the relevant threads in this forum. But still can't figure
out where is my error. The following is my codes.
Any helps, thanks a lot.
jfguo
/* Segment Descriptor table. */
SEGMENT_DESCRIPTOR RealGdt[] = {
{0, 0, 0, 0, 0, 0}, //First Descriptor in GDT is not used
{0xffff, 0x0000, 0x09, 0x9b, 0x00, 0x00}, //Protected/Real 16bit
code, 0x08
{0xffff, 0x0000, 0x00, 0x9f, 0xcf, 0x00} //protected flat mode
code, 0x10
};
;At this point, the CPU operates at Protected mode with flat memory
model.
;
;Step 1. Disable interrupts.
cli
;Step 2 of IA32 Manual. If paging is enabled, ...
;Because the paging is not enabled, I omited this step.
lgdt fword ptr [RealGdtr]
;Step 3 of IA32 Manual.
;Because I loaded my code at 90000h, so I subtract 90000h from the
PMode16bit.
DB 0EAh
DD PMode16bit-90000h
DW 08h
PMode16bit:
;92h is outputed at port 80h correct.
mov al, 92h
out 80h, al
;Step 4 of IA32 Manual. Load segment registers.
;Omit. I want using the descriptor attributes loaded during protected
mode.
;Step 5 of IA32 Manual. Execute LIDT.
;Omit.
;Step 6 of IA32 Manual. Clear the PE flag.
mov eax, cr0
and al, 0feh
mov cr0, eax
;Step7 of IA32 Manual.
;Far jump to the real-address mode code.
DB 66h
DB 0EAh
DD RealMode16bit-90000h
DW 08h
RealMode16bit:
;93h is not outputed in port 80.
mov al, 93h
out 80h, al
...
.
- Follow-Ups:
- Re: Could not switch back to Real-Address mode from Protected Mode. Help?
- From: Jean-François Michaud
- Re: Could not switch back to Real-Address mode from Protected Mode. Help?
- Prev by Date: Re: C++
- Next by Date: Dramatic speed effect of code-data proximity
- Previous by thread: Re: Any explanations
- Next by thread: Re: Could not switch back to Real-Address mode from Protected Mode. Help?
- Index(es):
Relevant Pages
|