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

📄 xdbioctls.c

📁 Windows CE 6.0 BSP for VOIPAC Board (PXA270) Version 2b.
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
// -----------------------------------------------------------------------
// INTEL CORPORATION MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS
// MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// INTEL CORPORATION ASSUMES NO RESPONSIBILITY FOR ANY ERRORS THAT MAY
// APPEAR IN THIS DOCUMENT. INTEL CORPORATION MAKES NO COMMITMENT TO
// UPDATE NOR TO KEEP CURRENT THE INFORMATION CONTAINED IN THIS DOCUMENT.
// -----------------------------------------------------------------------
//
// XDB Browser debug extension implementation

#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -