在DOS实模式下直接存取4GB内存(4)
2015-06-24 01:06
导读:MOVwordptrpdescr-tmp[2],AX //GDTRBaselow16bits db0x66 SHRAX,16//SHREAX,16 MOVwordptrpdescr-tmp[4],AX //GDTRBasehigh16bits LGDTpdescr-tmp//LoadGDTR } //**** //*Enter32bitFlatProtectedMode //**** asm{ m
MOV word ptr pdescr-tmp [2], AX
//GDTR Base low16 bits
db 0x66
SHR AX,16 //SHR EAX,16
MOV word ptr pdescr-tmp [4],AX
//GDTR Base high16 bits
LGDT pdescr-tmp //Load GDTR
}
//****
//* Enter 32 bit Flat Protected Mode
//****
asm{
mov DX,0x10 // The Data32 Selector
db 0x66,0x0F,0x20,0xC0 // MOV EAX,CR0
db 0x66
MOV BX,AX // MOV EBX,EAX
OR AX,1
db 0x66,0x0F,0x22,0xC0
//MOV CRO,EAX // Set Protection enable bit
JMP Flsuh
} //Clear machine perform cache.
flush: // Now In Flat Mode, But The CS is Real Mode Value.
asm { //And it s attrib is 16Bit Code Segment.
db 0x66
MOV AX,BX //MOV EAX,EBX
db 0x8E,0xE2 //MOV FS,DX
//Load FS Base=0 Size=4G now
db 0x66,0x0F,0x22,0xC0 //MOV CRO,EAX
//Return Real Mode.
LIDT OldIDT //LIDT OldIDT //Restore IDTR
STI // STI //Enable INTR
}
}
unsigned char ReadByte (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 al,byte ptr [BX] // =MOV AL, FS: [EDI]
return -AL;
}
unsigned char WriteByte(unsigned Long Address)
{
asm db 0x66
asm mov di,word ptr Address //MOV EDI, Address