⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vxmisc.c

📁 wince host 和 target PCI驱动程序
💻 C
字号:
/*---------------------------------------------------------------------------- COPYRIGHT (c) 1995 by Philips SemiconductorsTHIS 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 OTHERPERSON. THE OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT ANY PRIOR NOTICEAND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY Philips Semiconductor. PHILIPS ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWAREON PLATFORMS OTHER THAN THE ONE ON WHICH THIS SOFTWARE IS FURNISHED.----------------------------------------------------------------------------*//*	HISTORY	#define	TR	Tilakraj Roy	960405	TR 	Created		Misclaneous functions required from the vxd*/#pragma pack(1)#define WANTVXDWRAPS#include "basedef.h"#include "vmm.h"#include "vmmreg.h"#include "vxdwraps.h"#include "vwin32.h"#include "vxstd.h"#include "vxwin.h"#include "vxdbg.h"#pragma VxD_LOCKED_CODE_SEG#pragma VxD_LOCKED_DATA_SEGtypedef 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;VOID	vxdMemCopy ( PVOID pSource, PVOID pDestination, DWORD dwSize ){	DWORD dwIdx;	DWORD dwDWordSize = (dwSize >> 2);	for ( dwIdx = 0 ; dwIdx < dwDWordSize ; dwIdx ++ )	{		((PDWORD)pDestination)[dwIdx] = ((PDWORD)pSource)[dwIdx];	}	dwIdx *= sizeof ( DWORD );	for (  ; dwIdx <  dwSize ; dwIdx ++ )	{		((PBYTE)pDestination)[dwIdx] = ((PBYTE)pSource)[dwIdx];	}}VOID	vxdMemSet ( PVOID pSource, BYTE bValue, DWORD dwSize ){	DWORD dwIdx;	for ( dwIdx = 0 ; dwIdx < dwSize; dwIdx++ )	{		((PBYTE)pSource)[dwIdx] = bValue;	}}BOOL	vxdMemIsZero ( PVOID pMemory, WORD wSize ){	WORD wIdx;	for ( wIdx = 0 ; wIdx < wSize ; wIdx++ )	{		if ( ((PBYTE)pMemory)[wIdx] != 0 )			return FALSE;	}	return TRUE;}BOOL	vxdStrCmp ( PCHAR pSource1, PCHAR pSource2 ){		while ( *((PBYTE)pSource1) )	{		if ( *((PBYTE)pSource1)++ != *((PBYTE)pSource2)++ )			return FALSE;	}	return TRUE;}BOOL	vxdStrCopy ( PCHAR pSource, PCHAR pDestination ){	while ( *((PBYTE)pDestination)++ = *((PBYTE)pSource)++ );	*((PBYTE)pDestination)++ = *((PBYTE)pSource)++;	return TRUE;}WORD	vxdStrLen ( PCHAR pSource ){	WORD	Length = 0;	while ( *((PBYTE)pSource)++ ) Length++;	return ( Length + 1 );}VOID vxdSprintf(PCHAR pString, DWORD	dwLevel, char * pFormat, ...){	PVOID	pArgument = &pFormat;	WORD	Idx, StrIdx = 0, BufIdx = 0;	BYTE	Char;	// this function is ment for a 32 bit environment.	// modify pointer increment values for 32 bit stack.	((PVOID *)pArgument)++;	for( Idx = 0 ; pFormat[Idx] ; Idx ++ )	{		if( pFormat[Idx] == '%')		{			Char = pFormat[++Idx];			switch( Char )			{				case 'd':				{					DWORD	Value = *((PDWORD)pArgument);					DWORD	Divisor;					for( Divisor = 1 ; (Value / Divisor) >= 10 ;						Divisor *= 10);					do					//for( ; Value ; Divisor /= 10)					{						pString[StrIdx++] = (BYTE)							( (Value / Divisor) + '0');						Value = (DWORD)(Value % Divisor);						Divisor /= 10;					} while ( Divisor > 0);					((PDWORD)pArgument)++;				}				break;				case 's':				for ( BufIdx = 0 ;					((PBYTE)(*((PBYTE*)pArgument)))[BufIdx];					BufIdx++ )					pString[StrIdx++] = 					(((PBYTE)(*((PBYTE*)pArgument)))[BufIdx]);				((PVOID *)pArgument)++;				break;				case 'c':				pString[StrIdx++] = (*((PBYTE)pArgument));				((PDWORD)pArgument)++;				break;				case 'x':				{					DWORD	Value = *((PDWORD)pArgument);					BYTE Hex[] = "0123456789ABCDEF";					DWORD	Divisor;					for( Divisor = 1 ; (Value / Divisor) >= 16 ;						Divisor *= 16);					do					//for(  ; Value ; Divisor /= 16)					{						pString[StrIdx++] = 							(Hex[(Value / Divisor)]);						Value = (DWORD)(Value % Divisor);						Divisor /= 16;					} while ( Divisor > 0);					((PDWORD)pArgument)++;				}				break;				default :				pString[StrIdx++] = ('%');				pString[StrIdx++] = (Char);				break;			}		}		else		{			pString[StrIdx++] = pFormat[Idx];			continue;		}	}	pString[StrIdx] = 0;	//(DBG.pfnDBGOutput)(DBG.pTempStr);}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 );}PVOID	vxdMalloc ( DWORD dwSize ){	return winHeapAllocate (  dwSize ); }VOID	vxdFree ( PVOID pvMemory ){	winHeapFree ( (DWORD)pvMemory );}/*	vxdLinearToPhysical	This is how Andy implements linear to physical translation	CR3->PageDirectoryBase->PageTableBase->PageFrame*/DWORD	vxdLinearToPhysical ( DWORD dwLinear ){	DWORD	dwCR3;	PPAGEDIR	pPageDir;	PPAGETABLE	pPageTable;	PLINADDR	pLinearAddr = &dwLinear;	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 [age table entry to get the physical address of the page	// then add the offset within the page via the linear addr	return ( ( pPageTable->Address << 12 ) + ( pLinearAddr->PageOffset) );}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.}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -