?? rtal.c
字號(hào):
/*----------------------------------------------------------------------------
COPYRIGHT (c) 1997 by Philips Semiconductors
THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED AND COPIED IN
ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH A LICENSE AND WITH THE
INCLUSION OF THE THIS COPY RIGHT NOTICE. THIS SOFTWARE OR ANY OTHER COPIES
OF THIS SOFTWARE MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER
PERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.
THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICE
AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor.
PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE
ON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.
----------------------------------------------------------------------------*/
/*
FILE : RTAL.c
HISTORY
960510 Tilakraj Roy Created
980601 Tilakraj Roy Ported to Win95 Kernel
ABSTRACT
Contains support functions that are OS / Platform dependent.
This file should be in the platform specific directories,
However most platforms can use this file exactly as it is,
so this file is kept in the common area.
Platforms that require these functions to be overridden can
ignore this file and make a local platform specific copy in
the platform specific directory.
*/
/*----------------------------------------------------------------------------
SYSTEM INCLUDE FILES
----------------------------------------------------------------------------*/
/* tm1 specific includes */ // BUGCHECK - remove this line
#define WANTVXDWRAPS
#include "basedef.h"
#include "vmm.h"
#include "vmmreg.h"
#include "vxdwraps.h"
#include "vwin32.h"
#pragma VxD_LOCKED_CODE_SEG
#pragma VxD_LOCKED_DATA_SEG
#include "vxstd.h"
#include "vxwin.h"
#include "tmtypes.h"
#include "tmmanlib.h"
Pointer memAllocate( UInt32 Size )
{
Pointer Memory;
Memory = winHeapAllocate ( Size );
// BUGCHECK - check for return code before memSet
memSet ( Memory, 0, Size );
return Memory;
}
void memFree( Pointer Memory )
{
winHeapFree ( (DWORD)Memory );
}
void memCopy( Pointer Destination, Pointer Source, UInt32 Size )
{
UInt32 dwIdx;
UInt32 dwDWordSize = (Size >> 2);
for ( dwIdx = 0 ; dwIdx < dwDWordSize ; dwIdx ++ )
{
((UInt32*)Destination)[dwIdx] = ((UInt32*)Source)[dwIdx];
}
dwIdx *= sizeof ( UInt32 );
for ( ; dwIdx < Size ; dwIdx ++ )
{
((UInt8*)Destination)[dwIdx] = ((UInt8*)Source)[dwIdx];
}
}
void memSet ( Pointer Memory, UInt8 Value, UInt32 Size )
{
UInt32 dwIdx;
for ( dwIdx = 0 ; dwIdx < Size; dwIdx++ )
{
((UInt8*)Memory)[dwIdx] = Value;
}
}
UInt32 strCmp ( Pointer String1, Pointer String2 )
{
while ( *((UInt8*)String1) )
{
if ( *((UInt8*)String1) == *((UInt8*)String2) )
{
((UInt8*)String1)++;
((UInt8*)String2)++;
continue;
}
return ( *((UInt8*)String1) - *((UInt8*)String2) );
}
return 0;
}
Pointer strCopy ( Pointer Destination, Pointer Source )
{
while ( *((UInt8*)Destination)++ = *((UInt8*)Source)++ );
*((UInt8*)Destination)++ = *((UInt8*)Source)++;
return Destination;
}
UInt32 strLen ( Pointer String )
{
UInt32 Length = 0;
while ( *((UInt8*)String)++ ) Length++;
return ( Length + 1 );
}
void strSprintf (
Int8* BufferString,
Int8* FormatString,
... )
{
Pointer pArgument = &FormatString;
UInt32 Idx, StrIdx = 0, BufIdx = 0;
UInt8 Char;
// this function is ment for a 32 bit environment.
// modify pointer increment values for 32 bit stack.
((Pointer*)pArgument)++;
for( Idx = 0 ; FormatString[Idx] ; Idx ++ )
{
if( FormatString[Idx] == '%')
{
Char = FormatString[++Idx];
switch( Char )
{
case 'd':
{
DWORD Value = *((PDWORD)pArgument);
DWORD Divisor;
for( Divisor = 1 ; (Value / Divisor) >= 10 ;
Divisor *= 10);
do
//for( ; Value ; Divisor /= 10)
{
BufferString[StrIdx++] = (BYTE)
( (Value / Divisor) + '0');
Value = (UInt32)(Value % Divisor);
Divisor /= 10;
} while ( Divisor > 0);
((UInt32*)pArgument)++;
}
break;
case 's':
for ( BufIdx = 0 ;
((PBYTE)(*((PBYTE*)pArgument)))[BufIdx];
BufIdx++ )
BufferString[StrIdx++] =
(((PBYTE)(*((PBYTE*)pArgument)))[BufIdx]);
((PVOID *)pArgument)++;
break;
case 'c':
BufferString[StrIdx++] = (*((PBYTE)pArgument));
((UInt32*)pArgument)++;
break;
case 'x':
{
UInt32 Value = *((UInt32*)pArgument);
UInt8 Hex[] = "0123456789ABCDEF";
UInt32 Divisor;
for( Divisor = 1 ; (Value / Divisor) >= 16 ;
Divisor *= 16);
do
//for( ; Value ; Divisor /= 16)
{
BufferString[StrIdx++] =
(Hex[(Value / Divisor)]);
Value = (UInt32)(Value % Divisor);
Divisor /= 16;
} while ( Divisor > 0);
((UInt32*)pArgument)++;
}
break;
default :
BufferString[StrIdx++] = ('%');
BufferString[StrIdx++] = (Char);
break;
}
}
else
{
BufferString[StrIdx++] = FormatString[Idx];
continue;
}
}
BufferString[StrIdx] = 0;
}
// END OF RTAL
//All these are operating specific support routines
//provided by WinNT.
typedef struct _PAGEDIR
{
DWORD Present : 1;
DWORD Writable : 1;
DWORD User : 1;
DWORD WriteThrough : 1;
DWORD CacheDisable : 1;
DWORD Accessed : 1;
DWORD Unused : 1;
DWORD PageSize : 1;
DWORD Reserved : 1;
DWORD Available : 3;
DWORD Address : 20;
} PAGEDIR, *PPAGEDIR;
typedef struct _PAGETABLE
{
DWORD Present : 1;
DWORD Writable : 1;
DWORD User : 1;
DWORD WriteThrough : 1;
DWORD CacheDisable : 1;
DWORD Accessed : 1;
DWORD Unused : 1;
DWORD PageSize : 1;
DWORD Reserved : 1;
DWORD Available : 3;
DWORD Address : 20;
} PAGETABLE, *PPAGETABLE;
typedef struct _REGISTERCR3
{
DWORD Unused0 : 3;
DWORD WritesTransparent : 1;
DWORD CacheDisabled : 1;
DWORD Unused1 : 6;
DWORD PageDirPhysBase : 20;
} REGISTERCR3, *PREGISTERCR3;
DWORD vxdPageLock(PVOID pLinear, DWORD dwSize )
{
PLINADDR ppLinearAddr = (PLINADDR)&pLinear;
DWORD dwPageNumber;
DWORD dwNumPages ;
dwPageNumber = ( ((DWORD)pLinear) >> 12 );
dwNumPages =
( ( ((DWORD)pLinear + dwSize ) >> 12 ) -
dwPageNumber + 1 );
return ( _LinPageLock ( dwPageNumber,
dwNumPages, PAGEMAPGLOBAL ) + ppLinearAddr->PageOffset );
}
VOID vxdPageUnlock(PVOID pLinear, DWORD dwSize )
{
PLINADDR ppLinearAddr = (PLINADDR)&pLinear;
DWORD dwPageNumber;
DWORD dwNumPages;
dwPageNumber = ( ((DWORD)pLinear) >> 12 );
dwNumPages =
( ( ((DWORD)pLinear + dwSize ) >> 12 ) -
dwPageNumber + 1 );
_LinPageUnlock ( dwPageNumber, dwNumPages, PAGEMAPGLOBAL );
}
/*
vxdLinearToPhysical
This is how Andy implements linear to physical translation
CR3->PageDirectoryBase->PageTableBase->PageFrame
*/
DWORD vxdErrorBox ( PCHAR pszCaption, PCHAR pszText )
{
VSEB Dialog;
Dialog.vseb_b3 = 0; //
Dialog.vseb_b2 = 0x8000 | 1; // - "OK" 0x8000 | 1
Dialog.vseb_b1 = 0;//
Dialog.vseb_pszCaption = (DWORD)pszCaption;// "TriMedia Manager Fatal Error Message"// text for caption bar
Dialog.vseb_pszText = (DWORD)pszText;// "This system has a Intel Neptune Chipset, Proceed ??"
winVWIN32_SysErrorBox ( &Dialog );
return Dialog.vseb_resp; //1-Yes, 2-No, 3-Ignore.
}
PVOID
MmAllocateContiguousMemory(
IN ULONG NumberOfBytes,
IN PHYSICAL_ADDRESS HighestAcceptableAddress
)
{
Pointer pReturnData;
UInt32 nPages = ((NumberOfBytes - 1) >> 12)+1;
UInt32 pType = PG_SYS;
UInt32 flag = PAGEZEROINIT | PAGEFIXED | PAGECONTIG | PAGEUSEALIGN;
UInt32 minPhys = 0;
UInt32 AlignMask = 0x00000000;
pReturnData = _PageAllocate(
nPages, pType, 0, AlignMask,
minPhys, HighestAcceptableAddress.LowPart,
NULL, flag);
return pReturnData;
}
VOID
MmFreeContiguousMemory(
IN PVOID BaseAddress )
{
_PageFree(BaseAddress, 0);
}
PHYSICAL_ADDRESS
MmGetPhysicalAddress(
IN PVOID BaseAddress
)
{
PHYSICAL_ADDRESS PhysicalAddress;
DWORD dwCR3;
PPAGEDIR pPageDir;
PPAGETABLE pPageTable;
PLINADDR pLinearAddr = (PLINADDR)&BaseAddress;
PREGISTERCR3 pCR3 = (PREGISTERCR3)&dwCR3;
__asm {
mov eax, cr3
mov dwCR3, eax
}
pPageDir = _MapPhysToLinear (
// go to the page directory entry, via the index in the linear addr
( dwCR3 & 0xfffff000 ) + (pLinearAddr->PageDirectory << 2),
4, // we need to access a DWORD from page directory table
0 );
pPageTable = _MapPhysToLinear (
// go to the page table entry, via the index in the linear addr
( pPageDir->Address << 12 ) + ( pLinearAddr->PageNumber << 2),
4, // we need to access a DWORD from page table table
0 );
// use the page table entry to get the physical address of the page
// then add the offset within the page via the linear addr
PhysicalAddress.LowPart = ( ( pPageTable->Address << 12 ) + ( pLinearAddr->PageOffset) );
PhysicalAddress.HighPart = 0;
return PhysicalAddress;
}
PVOID
PsGetCurrentProcess( VOID )
{
return ((void*) winVWIN32_GetCurrentProcessHandle());
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -