当前位置:博学在线教学资源论文计算机论文网络技术论文 → 文章内容

在DOS实模式下直接存取4GB内存

减小字体 增大字体 作者:佚名  来源:不详  发布时间:2007-9-21 6:21:16

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
//***
asm{ // The right Code is Real, But BC++ s Linker NOT
// Work with 32bits Code.
db 0x66 //32 bit Operation Prefix in 16 Bit DOS.
MOV CX,DS //MOV ECX,DS
db 0x66 //Get Data segment physical Address
SHL CX,4 //SHL ECX,4
MOV word ptr pdescr-tmp [0],(3*8-1)
//MOV word ptr pdescr-tmp [0], (3*8-1)
db 0x66
XOR AX,AX //XOR EAX,EAX
MOV AX,offset GDT-Table
// MOV AX,offset GDT-Table
db 0x66
ADD AX,CX //ADD EAX,ECX
MOV word ptr pdescr-tmp , 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
asm db 0x67 //32 bit Address Prefix
asm db 0x64 //FS:
asm mov byte ptr [BX],al //=MOV FS: [EDI],AL
return -AL;
}
//////// Don t Touch Above Code ///
# include <stdio, h>
void Dump4G (unsigned long Address)
{
int i;
int j;
for (i=0; i<20; i++)
{
printf (“%081X: ”, (Address+i*16));
for (j=0; j<16;j++)
printf ("% 02X" ,ReadByte (Address+i*16+j));
printf (" ");
for (j=0;j<16;j++)
{
if (ReadByte (Address+i*16+j) <0x20) printf (" . ");
else printf (" %C ", ReadByte (Address+i*16+j));
}
printf ("\n");
}
}
main ()
{
unsigned long Address=0;
unsigned long tmp;
LoadFSLimit4G ();
printf ("====Des

上一页  [1] [2]