xdbioctls.c
来自「该BSP是基于PXA270+WINCE的BSP」· C语言 代码 · 共 768 行 · 第 1/2 页
C
768 行
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// XDB Browser debug extension implementation
/*
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
*/
#define WINCEMACRO 1
#include <windows.h>
#include "xdbioctl.h"
// GLOBALS
DWORD XSCBwrThreadID = (DWORD)INVALID_HANDLE_VALUE;
DWORD XSCBwrProcessID = (DWORD)INVALID_HANDLE_VALUE;
// storage for the original OS DATA-Abort handler address while
// a modified execution trace handler is active
//
static PFNVOID pfOSDataAbortHandler;
//External functions
//
extern void OEMCacheRangeFlush(LPVOID pAddr, DWORD dwLength, DWORD dwFlags);
/*-------------------------------------------------------------------------
* Function: GetVersionIoctl
*-------------------------------------------------------------------------
* Description: process the get version command from
* the XDB Browser
*-------------------------------------------------------------------------
* Pre/Side/Post: prototype matches OEMIoControl
*-------------------------------------------------------------------------
*/
static BOOL GetVersionIoctl(DWORD dwIoControlCode,
LPVOID lpInBuf, DWORD nInBufSize,
LPVOID lpOutBuf, DWORD nOutBufSize,
LPDWORD lpBytesReturned)
{
// output buffer format
PXSCBwrVersion pXSCBwrVersion;
// Return Value
BOOL retval = FALSE;
if ( (lpOutBuf == NULL ) ||
(sizeof(XSCBwrVersion) > nOutBufSize) ||
(lpBytesReturned == NULL)
)
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return (retval);
}
pXSCBwrVersion = (PXSCBwrVersion)lpOutBuf;
pXSCBwrVersion->Major = XSCBWR_V_MAJOR;
pXSCBwrVersion->Minor = XSCBWR_V_MINOR;
// Set the Bytes Returned size
*lpBytesReturned = sizeof(XSCBwrVersion);
// Set the return value
retval = TRUE;
return (retval);
}
/*-------------------------------------------------------------------------
* Function: ReadCoProcessorIoctl
*-------------------------------------------------------------------------
* Description: process the coprocessor read command from
* the XDB Browser
*-------------------------------------------------------------------------
* Pre/Side/Post: prototype matches OEMIoControl
*-------------------------------------------------------------------------
*/
static BOOL ReadCoProcessorIoctl(DWORD dwIoControlCode,
LPVOID lpInBuf, DWORD nInBufSize,
LPVOID lpOutBuf, DWORD nOutBufSize,
LPDWORD lpBytesReturned)
{
// CoProc Read Input Buffer Ptr
PXSCBwrRdRegIn pXSCBwrRdRegInBuf;
// CoProc Read Output Buffer Ptr
PXSCBwrRdRegOut pXSCBwrRdRegOutBuf;
// Return Value
BOOL retval = FALSE;
//Check the size of the input & Output buffers
if ((lpInBuf == NULL) || (lpOutBuf == NULL))
{
SetLastError(ERROR_INVALID_PARAMETER);
return (retval);
}
if ( (sizeof(XSCBwrRdRegOut) > nOutBufSize) || (lpBytesReturned == NULL) )
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return (retval);
}
pXSCBwrRdRegInBuf = (PXSCBwrRdRegIn)lpInBuf;
pXSCBwrRdRegOutBuf = (PXSCBwrRdRegOut)lpOutBuf;
// execute the 'read'
XSCBwrExecuteCoProcCode((pXSCBwrRdRegInBuf->OpCode),
(&pXSCBwrRdRegOutBuf->Reg1),
(&pXSCBwrRdRegOutBuf->Reg2));
// Set the Bytes Returned size
*lpBytesReturned = sizeof(XSCBwrRdRegOut);
// Set the return value
retval = TRUE;
return (retval);
}
/*-------------------------------------------------------------------------
* Function: WriteCoProcessorIoctl
*-------------------------------------------------------------------------
* Description: Process the coprocessor write command from
* the XDB Browser
*-------------------------------------------------------------------------
* Pre/Side/Post: prototype matches OEMIoControl
*-------------------------------------------------------------------------
*/
static BOOL WriteCoProcessorIoctl(DWORD dwIoControlCode,
LPVOID lpInBuf, DWORD nInBufSize,
LPVOID lpOutBuf, DWORD nOutBufSize,
LPDWORD lpBytesReturned)
{
// CoProc Write Input Buffer Ptr
PXSCBwrWrteRegIn pXSCBwrWrteRegInBuf;
// Set the default return value
BOOL retval = FALSE;
//Check the size of the input & Output buffers (no output buffer for write)
//
if ((lpInBuf == NULL) || (nInBufSize < (sizeof(XSCBwrWrteRegIn)) ) )
{
SetLastError(ERROR_INVALID_PARAMETER);
return (retval);
}
//Now assign the input buffer
pXSCBwrWrteRegInBuf = (PXSCBwrWrteRegIn)lpInBuf;
// execute the 'write'
//
XSCBwrExecuteCoProcCode((pXSCBwrWrteRegInBuf->OpCode),
(&pXSCBwrWrteRegInBuf->Reg1),
(&pXSCBwrWrteRegInBuf->Reg2));
// Set the Bytes Returned size
*lpBytesReturned = 0;
// Set the return value
retval = TRUE;
return (retval);
}
/*-------------------------------------------------------------------------
* Function: SetTaskIoctl
*-------------------------------------------------------------------------
* Description: Set the thread context for context registers and trace
*-------------------------------------------------------------------------
* Pre/Side/Post: prototype matches OEMIoControl
*-------------------------------------------------------------------------
*/
static BOOL SetTaskIoctl(DWORD dwIoControlCode,
LPVOID lpInBuf, DWORD nInBufSize,
LPVOID lpOutBuf, DWORD nOutBufSize,
LPDWORD lpBytesReturned)
{
// Set Task Input Buffer Ptr
PXSCBwrSetTaskIn pXSCBwrSetTaskInBuf;
// Set the default return value
BOOL retval = FALSE;
//Check the size of the input buffer
if ((lpInBuf == NULL) || (sizeof(XSCBwrSetTaskIn) > nInBufSize))
{
SetLastError(ERROR_INVALID_PARAMETER);
return (retval);
}
if ( (lpBytesReturned == NULL) )
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return (retval);
}
pXSCBwrSetTaskInBuf = (PXSCBwrSetTaskIn)lpInBuf;
if ( pXSCBwrSetTaskInBuf->ThreadID ) {
XSCBwrThreadID = pXSCBwrSetTaskInBuf->ThreadID;
XSCBwrProcessID = pXSCBwrSetTaskInBuf->ProcessID;
} else {
// thread set to 0: Browser is detaching from thread
//
XSCBwrThreadID = XSCBwrProcessID = (DWORD)INVALID_HANDLE_VALUE;
}
// Set the Bytes Returned size
*lpBytesReturned = 0;
// Set the return value
retval = TRUE;
return (retval);
}
/*-------------------------------------------------------------------------
* Function: ReadKMemIoctl
*-------------------------------------------------------------------------
* Description: Read memory from kernel space (>=0x80000000)
*-------------------------------------------------------------------------
* Pre/Side/Post: prototype matches OEMIoControl
*-------------------------------------------------------------------------
*/
static BOOL ReadKMemIoctl(DWORD dwIoControlCode,
LPVOID lpInBuf, DWORD nInBufSize,
LPVOID lpOutBuf, DWORD nOutBufSize,
LPDWORD lpBytesReturned)
{
// Set kmem read Input Buffer Ptr
PXSCBwrRdKMem pXSCBwrRdKMem;
// Set the default return value
BOOL retval = FALSE;
//Check the size of the input buffer
//
if ( (lpInBuf == NULL) || (sizeof(XSCBwrRdKMem) > nInBufSize) ) {
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return (retval);
}
if ( (lpBytesReturned == NULL) ){
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return (retval);
}
pXSCBwrRdKMem = (PXSCBwrRdKMem)lpInBuf;
if ( (pXSCBwrRdKMem->Address & 0x80000000) == 0 ) {
SetLastError(ERROR_INVALID_PARAMETER); // not in kernel space
return (retval);
}
// check output buffer
//
if ( (lpOutBuf == NULL) || (nOutBufSize < pXSCBwrRdKMem->Size ) ) {
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return (retval);
}
// copy kernel memory into output buffer
//
__try {
memcpy( lpOutBuf, (LPVOID)pXSCBwrRdKMem->Address, pXSCBwrRdKMem->Size );
// Set the Bytes Returned size
*lpBytesReturned = pXSCBwrRdKMem->Size;
// Set the return value
retval = TRUE;
}
__except(EXCEPTION_EXECUTE_HANDLER) {
SetLastError(ERROR_INVALID_PARAMETER);
*lpBytesReturned = 0;
}
return (retval);
}
///////////////////////// EXECUTION TRACE BUFFER HANDLING /////////////////////
typedef enum e_tracemode{
FILL_ONCE,
WRAP_AROUND,
TRACE_OFF
}tracemode;
typedef struct s_multi_trace{
int TASKID;
int CHKPT0;
int CHKPT1;
char Trace[256];
}multi_trace;
#define uiAddr DWORD
#define uiSize DWORD
typedef struct s_BufferAddr{
uiAddr pTraceBuffer; //pointer to Trace buffer
uiAddr StartAddress;
uiAddr EndAddress;
uiSize TraceBufferSize; //Size of Trace buffer
tracemode TraceMode; //Current Trace mode
uiAddr TaskIDAddress; //pointer to TaskID block
uiSize TaskIDSize; //Count of Available TaskIDs
uiSize CurrentTaskIDs; //Count of current used TaskIDs
}ConfigBlock;
static DWORD CurrentTaskID=0;
static int CFGBlockvalid = FALSE;
static ConfigBlock CFGBlock;
/*******************************************************************
trace_clear_current
*********************************************************************/
static void trace_clear_current(void)
{
//clear the Target trace buffer by reading
unsigned char dummy;
int i = 0;
for(i=0;i<256;i++){
dummy = (unsigned char)XSCBwrReadTraceByte();
}
}
/*-------------------------------------------------------------------------
* Function: XSCBwrInitExecutionTrace
*-------------------------------------------------------------------------
* Description: initialize the trace module
* *pBuffer address of the application trace buffer
* Size Size of the buffer in Bytes (X*264 Bytes)
*-------------------------------------------------------------------------
* Pre/Side/Post: prototype matches OEMIoControl
*-------------------------------------------------------------------------
*/
void XSCBwrInitExecutionTrace(void* pBuffer,uiSize Size)
{
CFGBlock.TraceBufferSize = Size;
CFGBlock.pTraceBuffer = (int) pBuffer;
CFGBlock.StartAddress = (int) CFGBlock.pTraceBuffer;
CFGBlock.EndAddress = (int) CFGBlock.pTraceBuffer;
CFGBlock.TaskIDAddress = 0;
CFGBlock.TaskIDSize = 0;
CFGBlock.CurrentTaskIDs = 0;
/* obtain address of the orginal OS DataAbort handler */
pfOSDataAbortHandler = NKSetDataAbortHandler(XSCBwrTraceDataAbortHandler);
NKSetDataAbortHandler(pfOSDataAbortHandler);
/* set multi trace mode */
CFGBlock.TraceMode = TRACE_OFF;
XSCBwrTraceSetFillOnce();
//clear the current processor Trace
trace_clear_current();
RETAILMSG(1, (TEXT("XSCDBG:Trace initialized: CFG:%08x Buffer: %08x, %x\n"),&CFGBlock,CFGBlock.pTraceBuffer, Size ));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?