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

📄 tmdbg.c

📁 wince host 和 target PCI驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	tmdbg.c	Debugging support for target	stdout, monochrome and tracebuffer	Requires the C Run time libraries to be linked.	960925	TR	Organized and added all three types of debugging.*/#include "ops/custom_defs.h"#include "tmman.h"#include "tmhd.h"#include "tmdbg.h"#include "stdio.h"#include "stdlib.h"#include "stdarg.h"#include "ctype.h"#include "tm1/tmInterrupts.h"#define DEBUG_FUNCTION	dbgOutTraceP#define SCREEN_ROWS	(25)#define SCREEN_COLS	(80)#define DBG_MAX_FUNCTION_COUNT		0x10#define DBG_MAX_STRING_SIZE			0x100#define TMDBG_CACHE_BLOCK_SIZE		(0x40)#define TMDBG_CACHE_ALIGNED_SIZE	(TMDBG_CACHE_BLOCK_SIZE*2)
#define DISABLEALL(x)	{ *((PDWORD)(&x))  = intCLEAR_IEN (); }#define ENABLEALL(x)	intRESTORE_IEN ( (x) );
typedef VOID (*PDEBUGFUNC)( PVOID, PCHAR );typedef struct _TMDBG_OBJECT{	/* general debugging */	DWORD	dwLevelBitmap;	PDEBUGFUNC	pfnDBGOutput;	DWORD	dwFlags;	DWORD	dwSize;	/* monochrome debugging */	DWORD	dwScreenRows;	DWORD	dwScreenCols;	DWORD	dwCurrentRow;	DWORD	dwCurrentCol;	DWORD	dwStartRow;	DWORD	dwStartCol;	PWORD	pwScreenBuffer;	PTMHD_DBG_SHARED	pSharedData;	PTMHD_DBG_PBUFFER	pPersistData;	/* physical output functions */	PDEBUGFUNC		OutFunc[TMSTD_DBG_MAXOUTFUNC];	/* for callback debugging */	DWORD	dwFunctionCount;	/* these fields have to be encapsulated in a structure */	PVOID	pvFunction[DBG_MAX_FUNCTION_COUNT];	PVOID	pvContext[DBG_MAX_FUNCTION_COUNT];	PCHAR	pszString[DBG_MAX_FUNCTION_COUNT];	/* for general debugging */	CHAR	pTempStrG[DBG_MAX_STRING_SIZE]; /* general debugging */	CHAR	pTempStrT[DBG_MAX_STRING_SIZE]; /* tmman debugging */}	TMDBG_OBJECT, *PTMDBG_OBJECT;BOOL	dbgRowInc ( PVOID pvDebug );BOOL	dbgColInc ( PVOID pvDebug );VOID	dbgOutTraceV ( PVOID pvDebug, PCHAR pString );VOID	dbgOutTraceP ( PVOID pvDebug, PCHAR pString );VOID	dbgOutStdout ( PVOID pvDebug, PCHAR pString );VOID	dbgOutStderr ( PVOID pvDebug, PCHAR pString );VOID	dbgOutMono ( PVOID pvDebug, PCHAR pString );VOID	dbgProcessChar ( PCHAR pszBuffer, PDWORD pdwPosition, CHAR Value  );VOID	dbgProcessDec ( PCHAR pszBuffer, PDWORD pdwPosition, DWORD Value  );VOID	dbgProcessHex ( PCHAR pszBuffer, PDWORD pdwPosition, DWORD Value  );VOID	dbgProcessStr ( PCHAR pszBuffer, PDWORD pdwPosition, PCHAR Value  );/* GLOBAL DATA STRUCTURES */TMDBG_OBJECT	DBG;PVOID	pDBG = &DBG;extern	PBYTE	_MMIO_base;
extern DWORD	*MMIODebugPtr;
/* IMPLEMENTATION */BOOL	dbgInit ( PVOID *ppvDebug ){	PTMDBG_OBJECT this;	PVOID	pPBuf;	DWORD	SDRAMBase = *((PDWORD)(((PBYTE)_MMIO_base) + 0x100000)); 	DWORD	SDRAMSize = (*((PDWORD)(((PBYTE)_MMIO_base) + 0x100004))) - SDRAMBase; 	DWORD	MMIOBase = (DWORD)_MMIO_base;	DWORD	Idx;	PBYTE	pSDRAM;	if ( *ppvDebug )	{		this = *ppvDebug;	}	else	{		if ( ( this = (PTMDBG_OBJECT)malloc ( 			sizeof ( TMDBG_OBJECT ) ) ) == NULL )		{			return FALSE;		}	}	this->dwFlags = 0;	this->dwSize	= sizeof ( TMDBG_OBJECT );	this->pfnDBGOutput = dbgOutMono;	this->dwLevelBitmap = 0xffffffff;	/* initialize the monochrome trace data structures */	this->pwScreenBuffer = (PWORD)0xb0000;	this->dwCurrentRow = 0;	this->dwCurrentCol = 0;	this->dwScreenRows = SCREEN_ROWS;	this->dwScreenCols = SCREEN_COLS;	this->dwStartRow = 0;	this->dwStartCol = 0;
	while(*MMIODebugPtr != 0x1 );

	*MMIODebugPtr = 0x12345679;
	/* initialize the volatile trace data structures */ 	tmParameterDWORDGet ( TMHD_PARAM_DBG, (PDWORD)&this->pSharedData );	/* this parameter is currently read from the registry */	/*this->pSharedData->Level = 0;*/	this->pSharedData->VWrapped = FALSE;	this->pSharedData->VBufLen = TMHD_DBG_VBUFLEN;	/* size - always default*/	this->pSharedData->VBufPos = 0;	/* current postion */

	while(*MMIODebugPtr != 0x2 );

	*MMIODebugPtr = 0x1234567a;
	memset ( this->pSharedData->VBuffer,0, this->pSharedData->VBufLen);

	*MMIODebugPtr = 0x1234567b;		/* initialize the persistent trace data structures */	if ( ( pPBuf = malloc ( TMHD_DBG_PBUFLEN + sizeof ( TMHD_DBG_PBUFFER ) +		TMDBG_CACHE_ALIGNED_SIZE ) ) == NULL ) /* HARDCODED 64 byte alignment */	{		dbgOutTraceV( this, "tmman:dbgInit:malloc:Persistent:FAIL\n");		return FALSE;	}	else	{		dbgOutTraceV( this, "tmman:dbgInit:malloc:Persistent:OK\n");	}	this->pPersistData = 		(PTMHD_DBG_PBUFFER)((((DWORD)pPBuf) & 0xffffffc0 ) + TMDBG_CACHE_BLOCK_SIZE);	this->pPersistData->pPBufStart = pPBuf;	this->pPersistData->PWrapped = FALSE;	strcpy ( this->pPersistData->szMagic, TMHD_DBG_BUFMAGIC );	this->pPersistData->szMagic[0] = 'T';	this->pPersistData->szMagic[1] = 'M';	this->pPersistData->szMagic[2] = '-';	this->pPersistData->szMagic[3] = 'S';	this->pPersistData->szMagic[4] = 'o';	this->pPersistData->szMagic[5] = 'f';	this->pPersistData->szMagic[6] = 't';		/* destroy any occurance of this string in memory */	pSDRAM = (PBYTE)SDRAMBase;	for ( Idx = 0 ; Idx < SDRAMSize ;		Idx += TMHD_DBG_MAGICSIZE, pSDRAM += TMHD_DBG_MAGICSIZE )	{		if ( strcmp ( pSDRAM, this->pPersistData->szMagic ) != 0  )			continue;		/* ensure that we are not destroying out own data */		if ( pSDRAM == (PBYTE)&this->pPersistData->szMagic[0] ) 			continue;		/* clear the string */		memset ( pSDRAM, 'X' , TMHD_DBG_MAGICSIZE );		/* make sure that the memory is updated */		COPYBACK (pSDRAM , 1 );	}	this->pPersistData->PBufLen = TMHD_DBG_PBUFLEN;	this->pPersistData->PBufPos = 0;	this->pPersistData->pPBuffer = 		((PBYTE)this->pPersistData) + sizeof ( TMHD_DBG_PBUFFER );		/* write back the buffer control data */	COPYBACK ( this->pPersistData , 2 );	this->OutFunc[0] = dbgOutMono;	this->OutFunc[1] = dbgOutTraceP;	this->OutFunc[2] = dbgOutTraceV;	this->OutFunc[3] = dbgOutStdout;	this->OutFunc[4] = dbgOutStderr;		*((PTMDBG_OBJECT *)ppvDebug) = this;	this->pfnDBGOutput = DEBUG_FUNCTION;	return TRUE;}VOID	dbgScreenSetSize ( PVOID pvDebug, DWORD dwStartRow, 	DWORD dwStartCol, DWORD dwRows, DWORD dwCols ){	PTMDBG_OBJECT this = (PVOID)pvDebug;	if ( dwStartRow > SCREEN_ROWS )		return;	if ( dwStartCol > SCREEN_COLS )		return;	if ( ( dwRows + dwStartRow ) > SCREEN_ROWS )		return;	if ( ( dwCols + dwStartCol ) > SCREEN_COLS )		return;	this->dwStartRow = dwStartRow;	this->dwStartCol = dwStartCol;	this->dwScreenRows = dwRows;	this->dwScreenCols = dwCols;/*	dbgScreenClr ( this ); */}BOOL	dbgRowInc ( PVOID pvDebug ){	PTMDBG_OBJECT this = (PVOID)pvDebug;	DWORD	dwIdx;	if ( this->dwCurrentRow < ( this->dwScreenRows -1 ) )	{		/* initially when the screen is not full */		this->dwCurrentRow++;	}	else	{		/* scroll up one line */		for ( dwIdx = 1 ; dwIdx < this->dwScreenRows ; dwIdx ++ )		{			memcpy ( 				( this->pwScreenBuffer +				( ( this->dwStartRow + ( dwIdx - 1 ) ) * SCREEN_COLS ) +				this->dwStartCol ),				( this->pwScreenBuffer +				( ( this->dwStartRow + dwIdx ) * SCREEN_COLS ) +				this->dwStartCol ),				this->dwScreenCols * 2 );		}		memset ( 			( this->pwScreenBuffer +			( ( this->dwStartRow + (this->dwScreenRows-1) )  * SCREEN_COLS ) +			this->dwStartCol ), 			0x00 ,			this->dwScreenCols * 2 );	}	this->dwCurrentCol = 0;	return TRUE;}BOOL	dbgColInc ( PVOID pvDebug ){	PTMDBG_OBJECT this = (PTMDBG_OBJECT)pvDebug;	if ( this->dwCurrentCol < ( this->dwScreenCols - 1 ) )	{		this->dwCurrentCol++;	}	else	{		dbgRowInc ( this );	}	return TRUE;}VOID	dbgExit ( PVOID pvDebug ){	if  ( pvDebug )	{		free ( pvDebug );	}	/* free the trace buffer here 	free ( this->Buffer ); */}VOID	dbgScreenClr ( PVOID pvDebug ){	PTMDBG_OBJECT this = (PTMDBG_OBJECT)pvDebug;	DWORD dwIdx;	for ( dwIdx = 0 ; dwIdx < this->dwScreenRows ; dwIdx ++ )	{		memset ( 			( this->pwScreenBuffer +			( ( this->dwStartRow + ( dwIdx ) ) * SCREEN_COLS ) ) +			this->dwStartCol, 			0x00 ,			this->dwScreenCols * 2 );	}	}/* PHYSICAL OUTPUT FUNCTIONS */VOID	dbgOutTrace ( PVOID pvDebug, PCHAR szString ){}VOID	dbgOutTraceV ( PVOID pvDebug, PCHAR szString ){
	PTMDBG_OBJECT this = (PVOID)pvDebug;	WORD wIdx;	DWORD	PCSW;

	DWORD	Start, End, Cycles;
	PCSW = intCLEAR_IEN ();
/*	Start = cycles(); */

	for ( wIdx = 0; szString[wIdx]; wIdx++ )	{		this->pSharedData->VBuffer[this->pSharedData->VBufPos] =			szString[wIdx];		if ( ++this->pSharedData->VBufPos >= this->pSharedData->VBufLen)		{			this->pSharedData->VBufPos = 0;			this->pSharedData->VWrapped = TRUE;		}	}
/*	End = cycles(); */
	intRESTORE_IEN ( PCSW );
/*	Cycles = ( End > Start ) ? (End - Start)  : (End + ((DWORD)(~0) - Start)); */

}VOID	dbgOutTraceP ( PVOID pvDebug, PCHAR szString ){	PTMDBG_OBJECT this = (PVOID)pvDebug;	DWORD		  Current = this->pPersistData->PBufPos;	DWORD		  Length = 0;	WORD wIdx;	DWORD	PCSW;	DWORD Invalidate, LastInvalidated = 0;	DWORD	Start, End, Cycles;
	PCSW = intCLEAR_IEN ();
	Start = cycles();
/*	sprintf (szTemp, "START[%x]",		&this->pPersistData->pPBuffer[this->pPersistData->PBufPos] );	dbgOutTraceV(this, szTemp );	sprintf (szTemp, "Start[%x]:Len[%x]:Pos[%x]:Buf[%x]:Wrap[%x]\n",		this->pPersistData->pPBufStart,		this->pPersistData->PBufLen,		this->pPersistData->PBufPos,		this->pPersistData->pPBuffer,		this->pPersistData->PWrapped );	dbgOutTraceV(this, szTemp );*/	for ( wIdx = 0; szString[wIdx]; wIdx++ )	{		this->pPersistData->pPBuffer[this->pPersistData->PBufPos] =			szString[wIdx];		if ( ++this->pPersistData->PBufPos >= this->pPersistData->PBufLen )		{			this->pPersistData->PBufPos = 0;			this->pPersistData->PWrapped = TRUE;		}

⌨️ 快捷键说明

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