home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n04
/
wqa0495.exe
/
PHYSMEM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-01
|
2KB
|
85 lines
#include <windows.h>
LPVOID AllocatePhysicalMemoryPtr( DWORD physAddress, DWORD len )
{
DWORD linearMappingAddress;
WORD mappingSelector;
WORD ourDS;
__asm mov [ourDS], ds
mappingSelector = AllocSelector( ourDS );
if ( !mappingSelector )
return 0;
__asm mov ax, 0800h
__asm mov bx, word ptr [physAddress+2]
__asm mov cx, word ptr [physAddress]
__asm mov si, word ptr [len+2]
__asm mov di, word ptr [len]
__asm int 31h
__asm jc error
__asm mov word ptr [linearMappingAddress+2], bx
__asm mov word ptr [linearMappingAddress], cx
SetSelectorBase( mappingSelector, linearMappingAddress );
SetSelectorLimit( mappingSelector, len );
return MAKELP( mappingSelector, 0 );
error:
FreeSelector( mappingSelector );
return 0;
}
void FreePhysicalMemoryPtr( LPVOID physPtr )
{
DWORD linearMappingAddress = GetSelectorBase( SELECTOROF(physPtr) );
__asm mov ax, 0801h
__asm mov bx, word ptr [linearMappingAddress+2]
__asm mov cx, word ptr [linearMappingAddress]
__asm int 31h
FreeSelector( SELECTOROF(physPtr) );
}
DWORD GetCR3(void); // A helper function prototype
int PASCAL WinMain( HANDLE h, HANDLE hPrev, LPSTR lpszCmdLine, int nCmdShow )
{
DWORD pageDirBasePhys;
LPDWORD lpPageDirEntry;
LPDWORD lpPageTableEntry;
char szBuffer[1024];
unsigned i;
LPSTR lpsz;
pageDirBasePhys = GetCR3();
lpPageDirEntry = AllocatePhysicalMemoryPtr( pageDirBasePhys, 0x1000 );
lpPageTableEntry
= AllocatePhysicalMemoryPtr( *lpPageDirEntry & 0xFFFFF000, 0x1000 );
FreePhysicalMemoryPtr( lpPageDirEntry );
lpsz = szBuffer + wsprintf(szBuffer, "Linear -> Physical\r\n" );
for ( i = 0; i < 256; i+= 16 )
{
lpsz+= wsprintf(lpsz, "%08lX -> %08lX %s\r\n",
(DWORD)i * 0x1000, // Linear
*lpPageTableEntry & 0xFFFFF000, // Physical
*lpPageTableEntry & 1 ? "present" : "not present");
lpPageTableEntry += 16;
}
FreePhysicalMemoryPtr( lpPageTableEntry );
MessageBox( 0, szBuffer, "PHYSMEM", MB_OK );
return 0;
}