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

📄 dbgioctls.c

📁 Xcale270Bsp包,wince平台
💻 C
📖 第 1 页 / 共 3 页
字号:
    // Context Read Reg Output Buffer Ptr
    PXSCBwrRdCxtRegOut pXSCBwrRdCxtRegOutBuf;

    // General Loop var for Read/Write Context Regs
    int XSCBwrLoopVar = 0;
    int XSCBwrTmpLoopVar = 0; 

    // Set the default return value
    BOOL retval = FALSE;

    if ((lpInBuf == NULL) || (lpOutBuf == NULL) || 
        (sizeof(XSCBwrRdCxtRegIn) > nInBufSize))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return(retval);
    }
    if ( (sizeof(XSCBwrRdCxtRegOut) > nOutBufSize) || (lpBytesReturned==NULL) )
    {
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return(retval);
    }

    // Now assign the pointers so can access the data
    pXSCBwrRdCxtRegInBuf = (PXSCBwrRdCxtRegIn)lpInBuf;
    pXSCBwrRdCxtRegOutBuf = (PXSCBwrRdCxtRegOut)lpOutBuf;

// BSP-SPECIFIC---------------------START-------------------------------------
    XSCBwrLoopVar = 0;

    while ( XSCBwrLoopVar < XSCBWR_NUM_CXTREGS_SAVED )
    {
        if (XSCBwrQryCxtRegsIdTable[XSCBwrLoopVar] == pXSCBwrRdCxtRegInBuf->RegID)
        {
            XSCBwrTmpLoopVar = CxtRegXLTNTable[XSCBwrLoopVar];
            pXSCBwrRdCxtRegOutBuf->Reg1 = 
            XSCBwrSaveThreadContextArea.Context_Area[ XSCBwrTmpLoopVar ];

            pXSCBwrRdCxtRegOutBuf->Reg2 = 0;

            // Are we getting a 1 or 2 DWORD register? - AND RegID with 
            // 0x1000 0000 to see if top bit is set, if it is, then it's a 
            // CP1 register == 32-bit, else, it's a  64-bit register, so need 
            //to grab next element in saved context area array
            if ( ((pXSCBwrRdCxtRegInBuf->RegID) & (0x10000000)) 
                 != (0x10000000) ) // Then it's 64-bit
            {
                XSCBwrTmpLoopVar++;
                pXSCBwrRdCxtRegOutBuf->Reg2 = 
                XSCBwrSaveThreadContextArea.Context_Area[ XSCBwrTmpLoopVar ];
            }

            // Now break out of the for loop, as have found the register
            // we're looking for
            break;
        }
        XSCBwrLoopVar++;
    }

// BSP-SPECIFIC----------------------END--------------------------------------

    //Set the Bytes Returned
    *lpBytesReturned = sizeof(pXSCBwrRdCxtRegOutBuf);


    // Set the return value
    retval = TRUE;

    return(retval);
}

/*-------------------------------------------------------------------------
 * Function:        WriteContextRegisterIoctl
 *-------------------------------------------------------------------------
 * Description:     Write one coprocessor register from saved context 
 *-------------------------------------------------------------------------
 * Pre/Side/Post:   prototype matches OEMIoControl
 *-------------------------------------------------------------------------
*/
static BOOL WriteContextRegisterIoctl(DWORD dwIoControlCode, 
                                      LPVOID lpInBuf, DWORD nInBufSize,
                                      LPVOID lpOutBuf, DWORD nOutBufSize, 
                                      LPDWORD lpBytesReturned)
{
    // Context Write Reg Input Buffer Ptr
    PXSCBwrWrteCxtRegIn pXSCBwrWrteCxtRegInBuf;

    // General Loop var for Read/Write Context Regs
    int XSCBwrLoopVar = 0;
    int XSCBwrTmpLoopVar = 0;

    // Set the default return value 
    BOOL retval = FALSE;

    //Check the size of the input & Output buffers      
    if ((lpInBuf == NULL) || (sizeof(XSCBwrWrteCxtRegIn) > nInBufSize))
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return(retval);
    }
    if ( lpBytesReturned == NULL )
    {
        SetLastError(ERROR_INSUFFICIENT_BUFFER);
        return(retval);
    }

    // Now assign the pointers to access the data
    pXSCBwrWrteCxtRegInBuf = (PXSCBwrWrteCxtRegIn)lpInBuf;

// BSP-SPECIFIC---------------------START-------------------------------------
    XSCBwrLoopVar = 0;

    while (XSCBwrLoopVar < XSCBWR_NUM_CXTREGS_SAVED )
    {
        if (XSCBwrQryCxtRegsIdTable[XSCBwrLoopVar] == 
            pXSCBwrWrteCxtRegInBuf->RegID)
        {
            XSCBwrTmpLoopVar = CxtRegXLTNTable[XSCBwrLoopVar];
            XSCBwrSaveThreadContextArea.Context_Area[ XSCBwrTmpLoopVar ] = 
            pXSCBwrWrteCxtRegInBuf->Reg1;

            // Are we getting a 1 or 2 DWORD register? - AND RegID with 
            // 0x1000 0000 to see if top bit is set, if it is, then it's 
            // a CP1 register == 32-bit, else, it's a  64-bit register, so 
            //need to grab next element in saved context area array
            if ( ((pXSCBwrWrteCxtRegInBuf->RegID) & (0x10000000)) 
                 != (0x10000000) ) // Then it's 64-bit
            {
                XSCBwrTmpLoopVar++;
                XSCBwrSaveThreadContextArea.Context_Area[ XSCBwrTmpLoopVar ] = pXSCBwrWrteCxtRegInBuf->Reg2;
            }
            // Now break out of the for loop, as have found the register we're looking for
            break;

        }
        XSCBwrLoopVar++;
    }

// BSP-SPECIFIC----------------------END--------------------------------------

    //Set the Bytes Returned
    *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 /////////////////////

#define _TRACEBUFFERBLOCKSIZE_ 268

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)
{
//    XSCBwrDisableTrace(); //trace should be disabled

    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 ));
}



/*******************************************************************
                                        fillbuffer

read the target trace buffer and store it in the application buffer

                                internal function
*********************************************************************/
static void fillbuffer(char* pCurrentTraceBuffer)
{
    register int i = 0;

    for (i=0;i<256;i++)
    {
        *pCurrentTraceBuffer++ = (unsigned char)XSCBwrReadTraceByte();
    }
}
/*******************************************************************
                                        trace_add_current
*********************************************************************/
static void trace_add_current(BYTE * ptracebuffer)
{
    //add Task info
    *ptracebuffer++ = (BYTE)(CurrentTaskID >> 24);
    *ptracebuffer++ = (BYTE)(CurrentTaskID >> 16);
    *ptracebuffer++ = (BYTE)(CurrentTaskID >>  8);
    *ptracebuffer++ = (BYTE)(CurrentTaskID >>  0);

    XSCBwrSaveTrace(ptracebuffer);


}

/*****************************************************************
       trace_admin_multi


        Administration of the multiple trace buffers
        two modes are supported: fill-once and wrap-around
        fill-once means:   if the application trace buffer is full 
                           the target stops
        wrap-around means: if the application trace buffer is full the 
                           oldest entry in the application trace buffer 
                           is overwritten with the current trace buffer.
/*****************************************************************/
static int trace_admin_multi(char** pbuffer)
{
    if (CFGBlock.EndAddress == CFGBlock.StartAddress && 
        CFGBlock.StartAddress == (int) CFGBlock.pTraceBuffer)
    {//empty buffer
        /*return address of the current trace buffer block */ 
        *pbuffer =(char*) CFGBlock.StartAddress;
        CFGBlock.EndAddress += _TRACEBUFFERBLOCKSIZE_;
        return FALSE; //not full            
    }

⌨️ 快捷键说明

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