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

📄 debug.c

📁 wince host 和 target PCI驱动程序
💻 C
字号:
/*	debug.c	Requires the C Run time libraries to be linked.	980518	Tilakraj Roy	Changed Defaukt Debugging to TMMan Internal.*/
#include "ops/custom_defs.h"
#include "stdio.h"
#include "stdarg.h"
#include "tmmanlib.h"
#include "tm1/mmio.h"
#include "tm1/tmInterrupts.h"

#define constDebugMaxStringSize		0x100#define constDebugCacheBlockSize	(0x40)#define constDebugCacheAlignSize	(constDebugCacheBlockSize*2)
#define DisableInterrupts(x)	*((UInt32*)(&x))  = intClearIEN ()
#define RestoreInterrupts(x)	intRestoreIEN ( (x) );

typedef struct tagDebugObject{	/* general debugging */

	UInt32			SDRAMBase;
 	UInt32			SDRAMSize;
 	UInt32			MMIOBase;
	UInt32			DebugBufferSize;
	UInt32			LevelBitmap;
	UInt32			HalHandle;
	UInt32			Type;
	DebugControl	*Control;	UInt8			pTempStrG[constDebugMaxStringSize]; /* general debugging */}	DebugObject;void	debugTrace (  UInt8* pString );void	debugProcessChar ( UInt8* pszBuffer, UInt32*pdwPosition, UInt8 Value  );void	debugProcessDec ( UInt8* pszBuffer, UInt32* pdwPosition, UInt32 Value  );void	debugProcessHex ( UInt8* pszBuffer, UInt32* pdwPosition, UInt32 Value  );void	debugProcessStr ( UInt8* pszBuffer, UInt32* pdwPosition, UInt8* Value  );/* GLOBAL DATA STRUCTURES */static DebugObject		globalDebugObject;
static DebugObject*	Debug = &globalDebugObject;

/* IMPLEMENTATION */
/* 
	Note that this function uses the HAl and should be called after initializing
	the hal 
*/
Bool	debugInit(
	/* platform specific implementation */					  
	debugParameters* Parameters )
{	void*	pPBuf;
	UInt32	Idx, Dummy;	UInt8*	pSDRAM;

	DebugControl*	Control;
	Debug->DebugBufferSize = ((debugParameters*)Parameters)->TraceBufferSize;	Debug->LevelBitmap = ((debugParameters*)Parameters)->LevelBitmap;
	Debug->Type = ((debugParameters*)Parameters)->Type;

	Debug->SDRAMBase = *(((char*)_MMIO_base) + DRAM_BASE );
	Debug->SDRAMSize = *(((char*)_MMIO_base) + DRAM_LIMIT ) - Debug->SDRAMBase ; 

	switch ( Debug->Type )
	{
		case constTMManDebugTypeTrace :
		/* initialize the persistent trace data structures */		if ( ( pPBuf = (UInt8*)malloc ( Debug->DebugBufferSize + sizeof ( DebugControl ) +			constDebugCacheAlignSize ) ) == 0 ) /* HARDCODED 64 byte alignment */		{			return False;		}
		Control = 			(DebugControl*)((((UInt32)pPBuf) & 0xffffffc0 ) + constDebugCacheBlockSize);		Control->AllocBase = pPBuf;		Control->Wrapped = 0; /* FIXME */
		strcpy ( Control->szMagic, constDebugTMManMagic );
		Control->szMagic[0] = 'T';
		Control->szMagic[1] = 'i';
		Control->szMagic[2] = 'l';
		Control->szMagic[3] = 'a';
		Control->szMagic[4] = 'k';
		Control->szMagic[5] = 'r';
		Control->szMagic[6] = 'a';
		Control->szMagic[7] = 'j';

				/* destroy any occurance of this string in memory */		pSDRAM = (UInt8*)Debug->SDRAMBase;		for ( Idx = 0 ; Idx < Debug->SDRAMSize ;			Idx += constDebugMagicSize, pSDRAM += constDebugMagicSize )		{			if ( strcmp ( pSDRAM, Control->szMagic ) != 0  )				continue;			/* ensure that we are not destroying out own data */			if ( pSDRAM == (UInt8*)&Control->szMagic[0] ) 				continue;
			/* clear the string */			memset ( pSDRAM, 'X' , constDebugMagicSize );			/* make sure that the memory is updated */			COPYBACK (pSDRAM , 1 );		}		Control->BufLen = Debug->DebugBufferSize;		Control->BufPos = 0;		Control->Buffer = 			((UInt8*)Control) + sizeof ( DebugControl );				/* write back the buffer control data */		COPYBACK ( Control, 2 );
		Debug->Control = Control;
		break;

		default :
		break;

	}
	return True;}Bool	debugExit( void )
{	free ( Debug->Control );
	return statusSuccess;}Bool	debugCheckLevel ( UInt32 Level )
{
	if( (( Level) & Debug->LevelBitmap)  )
	{
		return True;
	}
	return False;
}
UInt32	debugLevel ( UInt32 OptionBits )
{
	UInt32	TempOptionBits = Debug->LevelBitmap;
	Debug->LevelBitmap = OptionBits;
	return TempOptionBits;
}
	void	debugPrintf( 
	Int8* FormatString, 
	... )
{	/*PVOID	pArgument = &pFormat; */	UInt32	Idx, StrIdx = 0;	UInt8	Char;	UInt32	Items = 0;	UInt32	dwPCSW;	va_list	pArgument;	DisableInterrupts( dwPCSW );		va_start ( pArgument, FormatString );	for( Idx = 0 ; FormatString[Idx] ; Idx ++ )	{		/* check if we are overflowing the temp buffer. */		if ( ! ( StrIdx < constDebugMaxStringSize ) )		{			StrIdx--;			break;		} 		if( FormatString[Idx] == '%')		{			Items++;			Char = FormatString[++Idx];			switch( Char )			{				case 'd':				debugProcessDec ( Debug->pTempStrG, &StrIdx, va_arg ( pArgument, UInt32 ) );				break;				case 's':				debugProcessStr ( Debug->pTempStrG, &StrIdx, va_arg ( pArgument, UInt32 ) );				break;				case 'c':				debugProcessChar ( Debug->pTempStrG, &StrIdx, va_arg ( pArgument, UInt8 ) );				break;				case 'x':				debugProcessHex ( Debug->pTempStrG, &StrIdx, va_arg ( pArgument, UInt32 ) );				break;				default :				Items--;				Debug->pTempStrG[StrIdx++] = ('%');				Debug->pTempStrG[StrIdx++] = (Char);				break;			}		}		else		{			Debug->pTempStrG[StrIdx++] = FormatString[Idx];			continue;		}	}	Debug->pTempStrG[StrIdx] = 0;	va_end ( pArgument );
	switch ( Debug->Type )
	{
		case constTMManDebugTypeTrace :		debugTrace ( Debug->pTempStrG ); 
		break;

		default :
		break;
	}	RestoreInterrupts(dwPCSW);}
void	debugTrace ( UInt8* szString )
{
	UInt32			Current;
	UInt32			Length = 0;
	UInt32			Idx;
	UInt32			dwPCSW;
	UInt32			Invalidate, LastInvalidated = 0;
	DebugControl	*Control = Debug->Control;;

	Current = Control->BufPos; 
	

	DisableInterrupts(dwPCSW);

	for ( Idx = 0; szString[Idx]; Idx++ )
	{
		Control->Buffer[Control->BufPos] = szString[Idx];


		if ( ++Control->BufPos >= Control->BufLen )
		{
			Control->BufPos = 0;
			Control->Wrapped = 1;/* FIXME */

		}

	}

	/* write back the buffer control block - ignoring the magic string */
	COPYBACK ( (((UInt8*)Control) + constDebugMagicSize + 1), 1 );


	Length = Idx;

	for ( Idx = 0 ; Idx < Length ; Idx++ )
	{
		Invalidate = (UInt32)&Control->Buffer[Current];

		if ( ++Current >= Control->BufLen )
		{
			Current = 0;
		}

		COPYBACK ( (UInt8*)Invalidate , 1); 
	}

	RestoreInterrupts(dwPCSW);

}

void	debugProcessChar ( UInt8* pszBuffer, UInt32* pdwPosition, UInt8 Value  ){	pszBuffer[(*pdwPosition)++] = Value;}
void	debugProcessDec ( UInt8* pszBuffer, UInt32* pdwPosition, UInt32 Value  ){	UInt32	Divisor;
	for( Divisor = 1 ; (Value / Divisor) >= 10 ;		Divisor *= 10);	do	{		pszBuffer[(*pdwPosition)++] = (UInt8)( (Value / Divisor) + '0');		Value = (UInt32)(Value % Divisor);		Divisor /= 10;	} while ( Divisor > 0);}
void	debugProcessHex ( UInt8* pszBuffer, UInt32* pdwPosition, UInt32 Value  ){	UInt8 Hex[] = "0123456789ABCDEF";	UInt32	Divisor;	for( Divisor = 1 ; (Value / Divisor) >= 16 ;		Divisor *= 16);	do	{		pszBuffer[(*pdwPosition)++] = (Hex[(Value / Divisor)]);		Value = (UInt32)(Value % Divisor);		Divisor /= 16;	} while ( Divisor > 0);}void	debugProcessStr ( UInt8* pszBuffer, UInt32* pdwPosition, UInt8* Value  ){	UInt32 BufIdx;	for ( BufIdx = 0 ; Value[BufIdx];	BufIdx++ )		pszBuffer[(*pdwPosition)++]  = Value[BufIdx];}

⌨️ 快捷键说明

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