參考梁肇新的"在DOS實模式下直接存取4G記憶體",代碼基本上沒怎么改動,但是執行到asm LGDT pdescr_tmp報錯,請問下是什么原因導致的?

unsigned long GDT_Table[]=
{
0,0, //NULL - 00H
0x0000FFFF,0x00CF9A00, //Code32 - 08h Base=0 Limit=4G-1 Size=4G
0x0000FFFF,0x00CF9200 //Data32 - 10h Base=0 Limit=4G-1 Size=4G
};
unsigned char OldIDT [6]={0}; //Save The IDTR before Enter Protect Mode.
unsigned char pdescr_tmp [6]={0}; //NULL The IDTR s Limit=0 CPU will
// disable all Interrupts, include NMI.
#define KeyWait() {while(inportb(0x64) &2);}
void A20Enable(void)
{
KeyWait ();
outportb(0x64,0xD1);
KeyWait();
outportb(0x60,0xDF); //Enable A20 with 8042.
KeyWait();
outportb(0x64,0xFF);
KeyWait ();
}
void LoadFSLimit4G(void)
{
A20Enable (); //Enable A20
//***Disable ints & Null IDT //***
asm cli //Disable inerrupts
//SIDT OldIDT //Save OLD IDTR
//LIDT pdescr_tmp //Set up empty IDT.Disable any interrupts
// Include NMI.
//*** Lodd GDTR //***
// The right Code is Real, But BC++ s Linker NOT Work with 32bits Code.
asm db 0x66 //32 bit Operation Prefix in 16 Bit DOS.
asm MOV CX,DS //MOV ECX,DS
asm db 0x66 //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 0x66
asm XOR AX,AX //XOR EAX,EAX
asm MOV AX,offset GDT_Table // MOV AX,offset GDT-Table
asm db 0x66
asm ADD AX,CX //ADD EAX,ECX
asm MOV word ptr pdescr_tmp [2], AX //GDTR Base low16 bits
asm db 0x66
asm SHR AX,16 //SHR EAX,16
asm MOV word ptr pdescr_tmp [4],AX //GDTR Base high16 bits
asm LGDT pdescr_tmp //Load GDTR//報錯報錯
//**** Enter 32 bit Flat Protected Mode //****
asm mov DX,0x10 // The Data32 Selector
asm db 0x66,0x0F,0x20,0xC0 // MOV EAX,CR0
asm db 0x66
asm MOV BX,AX // MOV EBX,EAX
asm OR AX,1
asm db 0x66,0x0F,0x22,0xC0//MOV CRO,EAX // Set Protection enable bit
//And it sattrib is 16Bit Code Segment.
asm db 0x66
asm MOV AX,BX //MOV EAX,EBX
asm db 0x8E,0xE2 //MOV FS,DX
//Load FS Base=0 Size=4G now
asm db 0x66,0x0F,0x22,0xC0 //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 0x66
asm mov di,word ptr Address // MOV EDI, Address
asm db 0x67 //32 bit Address Prefix
asm db 0x64 //FS:
asm mov ax,word ptr [bx] // =MOV AL, FS: [EDI]
return _AX;
}
void WriteByte1(unsigned long Address, unsigned short data)
{
asm db 0x66
asm mov di,word ptr Address //MOV EDI, Address
asm mov ax,data
asm db 0x67 //32 bit Address Prefix
asm db 0x64 //FS
asm mov word ptr [bx],ax
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/242537.html
標籤:匯編語言
上一篇:OpenCV橢圓擬合錯誤
