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

📄 pvr_pdump.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*******************************************************************************
<module>
* Name         : pvr_pdump.c
* Title        : PVR Debug Functionality
* Author       : Dave Rovberts
* Created      : 17 / 11 / 03
*
* Copyright    : 2003 by Imagination Technologies Limited.
*                All rights reserved.  No part of this software, either
*                material or conceptual may be copied or distributed,
*                transmitted, transcribed, stored in a retrieval system
*                or translated into any human or computer language in any
*                form by any means, electronic, mechanical, manual or
*                other-wise, or disclosed to third parties without the
*                express written permission of Imagination Technologies
*                Limited, Unit 8, HomePark Industrial Estate,
*                King's Langley, Hertfordshire, WD4 8LZ, U.K.
*
* Description  : Implements WinCE pdump
*
* Platform     : WinCE
*
* $Date: 2004/07/20 10:38:00 $ $Revision: 1.7 $
* $Log: pvr_pdump.c $

</module>
********************************************************************************/
#if defined(PDUMP) && defined(PVR_KERNEL)

#include "mbx13ddef.h"
#include "img_types.h"
#include "services_headers.h"
#include "pvr_bridge.h"
#include <stdio.h>

PVRSRV_PDUMP_MEMMAP		*gpsPDMMData = IMG_NULL;

/***********************************************************************************
 Macro to validate context - If Null, global context is used
************************************************************************************/

#define VALIDATE_PDUMP_CONTEXT(x) \
if(x == IMG_NULL) \
{\
	PVRSRV_PDUMP_MEMMAP		*psPDMemMap;\
	psPDMemMap		= SysGetPDUMPData();\
	x				= psPDMemMap->psGlobalContext;\
	SysReleasePDUMPData(psPDMemMap);\
}\

/***********************************************************************************
 Macro to validate File - If Null, file is opened
************************************************************************************/

#define VALIDATE_PDUMP_FILE(x, y, z) \
if(!x) \
{\
	IMG_CHAR	szTmpString[256];\
	sprintf(szTmpString, "%s%s", y, z);\
	x = fopen(szTmpString, "wb");\
}\


/***********************************************************************************
 Local Prototypes
************************************************************************************/
IMG_BOOL DumpScriptLine (PDUMP_CONTEXT	*psPDContext, 
						 IMG_CHAR*		pszString, 
						 IMG_UINT32		ui32Bytes, 
						 IMG_BOOL		bIs2DWrite);

IMG_BOOL MemDumpScriptLine (PDUMP_CONTEXT	*psPDContext, 
							IMG_CHAR*		pszString, 
							IMG_UINT32		ui32Bytes);

IMG_VOID ConfigureScriptFile(PDUMP_CONTEXT *psPDContext, IMG_HANDLE *phFile);

/*!
*****************************************************************************
 @Function	: PVRSRVPDumpCommand
    
 @Description	: pdump command

 @Input : psCommandData - pdump command data
		  
 @Return	: PVRSRV_ERROR
*****************************************************************************/
PVRSRV_ERROR IMG_CALLCONV PVRSRVPDumpCommand (PVRSRV_BRIDGE_IN_PDUMP_COMMAND	*psCommandData)
{
	PDUMP_TYPE ePDumpType = psCommandData->ePDumpCommandType;

	switch(ePDumpType)
	{
		case PDUMP_TYPE_INIT:
		{
			if(psCommandData->sPDumpData.sInit.bInitialise)
			{
				if(!PDumpInit(&psCommandData->psPDumpContext, IMG_NULL))
					return PVRSRV_ERROR_GENERIC;
			}
			else
			{
				if(!PDumpClose(psCommandData->psPDumpContext))
					return PVRSRV_ERROR_GENERIC;
			}
			break;
		}
		case PDUMP_TYPE_DUMP_TEX:
		{
			if(!PDumpTex(psCommandData->psPDumpContext,
						 psCommandData->sPDumpData.sDumpTex.psMemInfo))
				return PVRSRV_ERROR_GENERIC;
			break;
		}
		case PDUMP_TYPE_REGISTER_TEX:
		{
			if(!PDumpRegisterTex(psCommandData->psPDumpContext,
								 psCommandData->sPDumpData.sDumpTex.psMemInfo))
				return PVRSRV_ERROR_GENERIC;
			break;
		}
		case PDUMP_TYPE_FLUSH_TEX_LIST:
		{
			if(!PDumpFlushTexList(psCommandData->psPDumpContext))
				return PVRSRV_ERROR_GENERIC;
			break;
		}
		case PDUMP_TYPE_DUMP_STRING:
		{
			if(!PDumpString(psCommandData->psPDumpContext,
						    psCommandData->sPDumpData.sWriteString.pszString))
				return PVRSRV_ERROR_GENERIC;
			break;
		}
		case PDUMP_TYPE_WRITE_REG:
		{
			if(!PDumpRegArray(psCommandData->psPDumpContext,
						      psCommandData->sPDumpData.sWriteReg.ui32PDumpRegType,
							  psCommandData->sPDumpData.sWriteReg.psRegs,
							  psCommandData->sPDumpData.sWriteReg.ui32RegCount))
				return PVRSRV_ERROR_GENERIC;
			break;
		}
		case PDUMP_TYPE_WRITE_SP:
		{
			if(!PDumpSPBatch(psCommandData->psPDumpContext,
							 psCommandData->sPDumpData.sWriteSP.ui32PDumpSPType,
							 psCommandData->sPDumpData.sWriteSP.pui32Data,
							 psCommandData->sPDumpData.sWriteSP.ui32DataCount))
				return PVRSRV_ERROR_GENERIC;
			break;
		}
		case PDUMP_TYPE_WRITE_POLL:
		{
			if(!PDumpPoll(psCommandData->psPDumpContext,
						  psCommandData->sPDumpData.sWritePoll.ui32PDumpRegType,
						  psCommandData->sPDumpData.sWritePoll.ui32Addr,
						  psCommandData->sPDumpData.sWritePoll.ui32Mask,
						  psCommandData->sPDumpData.sWritePoll.ui32Value,
						  psCommandData->sPDumpData.sWritePoll.ui32A,
						  psCommandData->sPDumpData.sWritePoll.ui32B,
						  psCommandData->sPDumpData.sWritePoll.ui32C))
						  return PVRSRV_ERROR_GENERIC;
			break;
		}
		case PDUMP_TYPE_UPDATE_FRAME:
		{
			PDumpUpdateFrame(psCommandData->psPDumpContext);
			break;
		}
		case PDUMP_TYPE_ENABLE:
		{
			PDumpEnable();
			break;
		}
		case PDUMP_TYPE_DISABLE:
		{
			PDumpDisable();
			break;
		}
		case PDUMP_TYPE_DISABLE_2D:
		{
			PDumpDisable2D();
			break;
		}
		case PDUMP_TYPE_ENABLE_LOCAL_SCRIPT:
		{
			PDumpEnableLocalScript(psCommandData->psPDumpContext);
			break;
		}
	}
	return PVRSRV_OK;
}

/***********************************************************************************
 Kernel Mode PDUMP Functionality
************************************************************************************/

/***********************************************************************************
 Function Name      : PDumpInit
 Inputs             : 
 Outputs            : -
 Returns            : PDUMP_CONTEXT
 Description        : Initialise pdump resources
************************************************************************************/

IMG_BOOL PDumpInit(PDUMP_CONTEXT **ppsPDContext, IMG_HANDLE hServices)
{
	PDUMP_CONTEXT	*psPDContext;
	IMG_HANDLE		*fpControl = IMG_NULL;;

	if(ppsPDContext == IMG_NULL)
	{
		/*
			Initialise global context
		*/
		gpsPDMMData = SysGetPDUMPData();
		return IMG_TRUE;
	}
	
	if(HostAllocMem(PVRSRV_HOST_NON_PAGEABLE_HEAP,sizeof(PDUMP_CONTEXT), &psPDContext, 0) != PVRSRV_OK)
	{
		PVR_DPF((PVR_DBG_ERROR,"PDumpInit: failed to allocate PDUMP_CONTEXT"));
		goto ErrorExit;
	}
	HostMemSet(psPDContext, 0, sizeof(PDUMP_CONTEXT));

	psPDContext->psPDumpMemMap			= SysGetPDUMPData();
	psPDContext->bLocalScriptDumpingOn	= IMG_FALSE;
	psPDContext->bScriptConfigured		= IMG_FALSE;
	psPDContext->b2DScriptConfigured	= IMG_FALSE;

	if(psPDContext->psPDumpMemMap->ui32ActiveContexts == 0)
	{
		/*
			Global Context
		*/
		psPDContext->bGlobalContext = IMG_TRUE;

		//FIXME: default path should be run directory
		strcpy(psPDContext->szTexFilePath, "\\release\\");
		strcpy(psPDContext->szTexFileName, "out.tex");
		
		//FIXME: default path should be run directory
		strcpy(psPDContext->szPrimFilePath, "\\release\\");
		strcpy(psPDContext->szPrimFileName, "out.prm");

		//FIXME: default path should be run directory
		strcpy(psPDContext->szScriptFilePath, "\\release\\");
		strcpy(psPDContext->szScriptFileName, "out.txt");

		//FIXME: default path should be run directory
		strcpy(psPDContext->sz2DScriptFilePath, "\\release\\");
		strcpy(psPDContext->sz2DScriptFileName, "out.2D.txt");
	}
	else
	{
		psPDContext->ui32StreamID = ++(psPDContext->psPDumpMemMap->ui32StreamCount);

		//FIXME: default path should be run directory
		strcpy(psPDContext->szTexFilePath, "\\release\\");
		sprintf(psPDContext->szTexFileName, "out%d.tex", psPDContext->ui32StreamID);

		
		//FIXME: default path should be run directory
		strcpy(psPDContext->szPrimFilePath, "\\release\\");
		sprintf(psPDContext->szPrimFileName, "out%d.prm", psPDContext->ui32StreamID);


		//FIXME: default path should be run directory
		strcpy(psPDContext->szScriptFilePath, "\\release\\");
		sprintf(psPDContext->szScriptFileName, "out%d.txt", psPDContext->ui32StreamID);
	}


	fpControl = fopen("\\release\\pdump.txt","rt");

	if(fpControl)
	{
		fscanf(fpControl, "Start:%d\nStop:%d\nSkip:%d", 
			&psPDContext->ui32StartFrame, 
			&psPDContext->ui32StopFrame, 
			&psPDContext->ui32SkipFrame);

		fclose(fpControl);
	}
	else
	{
		psPDContext->ui32StartFrame = 0;
		psPDContext->ui32StopFrame	= 0xFFFFFFFF;
		psPDContext->ui32SkipFrame	= 1;
	}

	*ppsPDContext = psPDContext;

	psPDContext->psPDumpMemMap->ui32ActiveContexts++;

	return IMG_TRUE;
	
ErrorExit:

	if(psPDContext)
	{
		if(psPDContext->fpPrim)
			fclose(psPDContext->fpPrim);
		if(psPDContext->fpTex)
			fclose(psPDContext->fpTex);
		if(psPDContext->fpScript)
			fclose(psPDContext->fpScript);
		if(psPDContext->psPDumpMemMap)
			SysReleasePDUMPData(psPDContext->psPDumpMemMap);
		HostFreeMem(PVRSRV_HOST_PAGEABLE_HEAP, psPDContext);
	}
	
	if(fpControl)
	{
		fclose(fpControl);
	}
	
	return IMG_FALSE;
}

/***********************************************************************************
 Function Name      : PDumpEnableVirtual
 Inputs             : ppsPDContext, pszPath - path to script file
 Outputs            : -
 Returns            : success
 Description        : Re-routes 2d pdumps to mem file
************************************************************************************/

IMG_BOOL PDumpEnableVirtual(IMG_CHAR *pszPath)
{
	PDUMP_CONTEXT	*psPDContext = IMG_NULL;
	
	VALIDATE_PDUMP_CONTEXT(psPDContext)


	/*
		Set intial size to 800 line by 40 char mem file buffer
	*/
	psPDContext->ui32MemFileByteCount = 800 * 40;
	psPDContext->ui32MemFileIndex = 0;

	if (psPDContext->pvMemFile == NULL)
	{
		if(HostAllocMem(PVRSRV_HOST_PAGEABLE_HEAP, 
						psPDContext->ui32MemFileByteCount, 
						&psPDContext->pvMemFile, 0) != PVRSRV_OK)
		{
			PVR_DPF((PVR_DBG_ERROR,"PDumpInitVirtual: failed to allocate mem file"));
			return IMG_FALSE;
		}
	}

	psPDContext->bVirtualContextEnabled	= IMG_TRUE;

	/*
		Configure Script and add a token string as a marker
	*/
	ConfigureScriptFile(psPDContext, IMG_NULL);
	PDumpString(IMG_NULL, "\r\n-- Virtual File Start --");

	strcpy(psPDContext->sz2DMemFilePath, pszPath);
	strcpy(psPDContext->sz2DMemFileName, "out.txt");
	return IMG_TRUE;
}

/***********************************************************************************
 Function Name      : PDumpDisableVirtual
 Inputs             : ppsPDContext, pszPath - path to script file
 Outputs            : -
 Returns            : success
 Description        : Re-routes 2d pdumps to script file and closes mem file
************************************************************************************/

IMG_BOOL PDumpDisableVirtual()
{
	PDUMP_CONTEXT	*psPDContext = IMG_NULL;;
	
	VALIDATE_PDUMP_CONTEXT(psPDContext)

	if(!psPDContext->bVirtualContextEnabled)
		return IMG_TRUE;

	psPDContext->bVirtualContextEnabled	= IMG_FALSE;

	/*
		Free up virtual file
	*/

	HostFreeMem(PVRSRV_HOST_PAGEABLE_HEAP, psPDContext->pvMemFile);
	psPDContext->pvMemFile = NULL;

	return IMG_TRUE;
}

/***********************************************************************************
 Function Name      : PDumpFlushAndClose
 Inputs             : psPDContext
 Outputs            : -
 Returns            : success
 Description        : Flushes a virtual context to a file and closes the context
************************************************************************************/

IMG_BOOL PDumpFlushVirtual(IMG_CHAR *pszPrefix)
{

⌨️ 快捷键说明

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