Reference beam zhao new "direct access 4 gb of memory in the DOS real mode", code basically didn't change, but the execution to the asm LGDT pdescr_tmp error, what is the reason?
Unsigned long GDT_Table []=
{
0, 0, 00//NULL - h
X0000ffff 0, 0 x00cf9a00,//Code32 Base - 08 h=0 Limit Size=4 g=4 g - 1
X0000ffff 0, 0 x00cf9200/Base/Data32-10 h=0 Limit Size=4 g=4 g - 1
};
Unsigned char OldIDT [6]={0};//Save The IDTR before Enter Protect Mode.
Unsigned char pdescr_tmp [6]={0};//NULL The IDTR s Limit=0, The CPU will
//disable all Interrupts, include NMI.
# define KeyWait () {while (inportb (0 x64) & amp; 2); }
Void A20Enable (void)
{
KeyWait ();
X64 outportb (0, 0 xd1);
KeyWait ();
XDF outportb (0 x60, 0);//Enable A20 with 8042.
KeyWait ();
X64 outportb (0, 0 XFF);
KeyWait ();
}
Void LoadFSLimit4G (void)
{
A20Enable ();//Enable A20
//* * * Disable ints & amp; Null IDT//* * *
Asm cli//Disable inerrupts
//SIDT OldIDT//Save OLD IDTR
//LIDT pdescr_tmp//Set up the empty IDT. Disable any interrupts
//Include NMI.
//* * * Lodd GDTR//* * *
//The right Code is Real, But BC++ s would NOT Work with 32 bits of Code.
Asm db 0 x66//32 bit Operation Prefix in 16 bit DOS.
CX, asm MOV DS//MOV ECX, DS
Asm db 0 x66//Get Data segment physical Address
Asm SHL CX, 4//SHL ECX, 4
Asm MOV word PTR pdescr_tmp [0], (3 * 8-1)//MOV word PTR pdescr - TMP [0], (3 * 8-1)
Asm db 0 x66
Asm XOR AX, AX//XOR EAX, EAX
Asm MOV AX, offset GDT_Table//MOV AX, offset GDT - Table
Asm db 0 x66
CX//asm ADD AX, ADD EAX, ECX
Asm MOV word PTR pdescr_tmp [2], AX//GDTR Base low16 bits
Asm db 0 x66
Asm SHR AX, 16//SHR EAX, 16
Asm MOV word PTR pdescr_tmp [4], AX//GDTR Base high16 bits
the asm LGDT pdescr_tmp//the Load GDTR//an error error
//* * * * Enter 32 bit Flat Protected Mode//* * * *
Asm mov DX, 0 x10//The Data32 Selector
Asm x66 db 0, 0 x0f, 0 x20, 0 xc0//MOV EAX, CR0
Asm db 0 x66
Asm MOV BX, AX//MOV EBX, EAX
Asm OR AX, 1
Asm x66 db 0, 0 x0f, x22 0, 0 xc0//MOV CRO, EAX//Set Protection, the enable bit
//And it sattrib is 16 bit Code Segment.
Asm db 0 x66
Asm MOV AX, BX//MOV EAX and EBX
Asm db 0 x8e, 0 xe2//MOV FS, DX
//Load the FS Base=0 Size=4 g now
Asm x66 db 0, 0 x0f, x22 0, 0 xc0//MOV CRO, EAX
//Return Real Mode.
//LIDT OldIDT//LIDT OldIDT//Restore IDTR
Asm STI//STI//Enable INTR
}
Unsigned char ReadByte1 (unsigned long Address)
{
Asm db 0 x66
Asm mov di, word PTR Address//mov EDI, Address
Asm db 0 x67//32 bit Address Prefix
Asm db 0 x64//FS:
Asm mov ax, word PTR [bx]//=mov AL, FS: (EDI)
Return _AX;
}
Void WriteByte1 (unsigned long Address, unsigned short data)
{
Asm db 0 x66
Asm mov di, word PTR Address//mov EDI, Address
Asm mov ax, data
Asm db 0 x67//32 bit Address Prefix
Asm db 0 x64//FS
Asm mov word PTR [bx], ax
}