📄 xdb.c
字号:
//
// 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.
//
//------------------------------------------------------------------------------
//
// File: xdbioctl.c
//
// context register IOCTLs from xdb client on host
#ifdef USING_XSCALEBROWSER
#define WINCEMACRO 1
#include <windows.h>
#include <xdbioctl.h>
#include <coproc.h>
#include <xdb.h>
#define SIZEOFARRAY(a) (sizeof(a) / sizeof(a[0]))
// structure allocated for saving coproc registers when xdb is
// compiled into the image
//
XSCContextArea XSCBwrSaveThreadContextArea;
// QueryContextRegs IdTable Struct
// This table has the same 'layout' as the save/restore puts
// the registers in memory - it is not linear with respect
// to simply increasing the registers, it is interleaved
DWORD XSCBwrQryCxtRegsIdTable[XSCOPROC_NUM_CXTREGS_SAVED] = {
0x00002100, // wR0 (CoProc0, Reg 0)
0x00002101, // wR1
0x00002102, // wR2
0x00002103, // wR3
0x00002104, // wR4
0x00002105, // wR5
0x00002106, // wR6
0x00002107, // wR7
0x00002108, // wR8
0x00002109, // wR9
0x0000210a, // wR10
0x0000210b, // wR11
0x0000210c, // wR12
0x0000210d, // wR13
0x0000210e, // wR14
0x0000210f, // wR15
0x10000200, // wC2 (CoProc1, Reg 2) - WCSSF
0x10000300, // wC3 - WCASF
0x10000800, // wC8 - Also WCGR0
0x10000900, // wC9 - WCGR1
0x10000a00, // wC10 - WCGR2
0x10000b00, // wC11 - WCGR3
};
// This array acts as an index for the above registers in the global context
// save area. As this area has both 32 & 64-bit elements, it is not a linear
// index, as such, this table will "Translate" from one to the other.
// This array is the offset into XSCBwrSaveThreadContextArea.Context_Area
// where each register defined in XSCBwrQryCxtRegsIdTable is saved.
//
int CxtRegXLTNTable[XSCOPROC_NUM_CXTREGS_SAVED] =
{
1, // wR0 (CoProc0, Reg 0) (Array Pos. 0 = saved flag)
3, // wR1 (CoProc0, Reg 1)
5, // wR2
7, // wR3
9, // wR4
11, // wR5
13, // wR6
15, // wR7
17, // wR8
19, // wR9
21, // wR10
23, // wR11
25, // wR12
27, // wR13
29, // wR14
31, // wR15
33, // wC2 (CoProc1, Reg 2) - WCSSF
34, // wC3 - WCASF
35, // wC8 - Also WCGR0
36, // wC9 - WCGR1
37, // wC10 - WCGR2
38 // wC11 - WCGR3
};
//------------------------------------------------------------------------------
//
// Function: QueryContextRegistersIoctl
//
// IOCTL called by the xdb browser on host to query the context saved coprocessor registers.
//
BOOL OALQueryContextRegistersIoctl(
UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
UINT32 outSize, UINT32 *pOutSize)
{
// Context Query Output Buffer Ptr
PXSCBwrQryCxtRegsOut pXSCBwrQryCxtRegsOutBuf;
// Set the default return value
BOOL retval = FALSE;
//Check the size of the input & Output buffers (No input buffer for Query)
if ((pOutBuffer == NULL) || (outSize < (sizeof(XSCBwrQryCxtRegsOut)) ) )
{
SetLastError(ERROR_INVALID_PARAMETER);
return (retval);
}
//Now assign the Output pointer to a buffer pointer
pXSCBwrQryCxtRegsOutBuf = (PXSCBwrQryCxtRegsOut)pOutBuffer;
pXSCBwrQryCxtRegsOutBuf->Count = XSCOPROC_NUM_CXTREGS_SAVED;
memcpy(pXSCBwrQryCxtRegsOutBuf->IdTable, XSCBwrQryCxtRegsIdTable, sizeof(XSCBwrQryCxtRegsIdTable));
*pOutSize = sizeof(XSCBwrQryCxtRegsOut);
// Set the return value
retval = TRUE;
return (retval);
}
//------------------------------------------------------------------------------
//
// Function: ReadContextRegisterIoctl
//
// IOCTL called by the xdb browser on host to read one coprocessor register from saved context
//
BOOL OALReadContextRegisterIoctl(
UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
UINT32 outSize, UINT32 *pOutSize)
{
// Context Read Reg Input Buffer Ptr
PXSCBwrRdCxtRegIn pXSCBwrRdCxtRegInBuf;
// Context Read Reg Output Buffer Ptr
PXSCBwrRdCxtRegOut pXSCBwrRdCxtRegOutBuf;
int i, regPos;
if ((pInpBuffer == NULL) || (pOutBuffer == NULL) ||
(sizeof(XSCBwrRdCxtRegIn) > inpSize))
{
SetLastError(ERROR_INVALID_PARAMETER);
return (FALSE);
}
if ( (sizeof(XSCBwrRdCxtRegOut) > outSize) || (pOutSize==NULL) )
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return (FALSE);
}
// Now assign the pointers to access the data
pXSCBwrRdCxtRegInBuf = (PXSCBwrRdCxtRegIn)pInpBuffer;
pXSCBwrRdCxtRegOutBuf = (PXSCBwrRdCxtRegOut)pOutBuffer;
*pOutSize = 0;
for (i=0; i < SIZEOFARRAY(XSCBwrQryCxtRegsIdTable); i++)
{
if (XSCBwrQryCxtRegsIdTable[i] == pXSCBwrRdCxtRegInBuf->RegID)
{
regPos = CxtRegXLTNTable[i];
pXSCBwrRdCxtRegOutBuf->Reg1 = XSCBwrSaveThreadContextArea.Context_Area[regPos];
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
{
regPos++;
pXSCBwrRdCxtRegOutBuf->Reg2 = XSCBwrSaveThreadContextArea.Context_Area[regPos];
}
//Set the Bytes Returned
*pOutSize = sizeof(XSCBwrRdCxtRegOut);
// We've found the register. return.
return (TRUE);
}
}
//RegID was incorrect.
SetLastError(ERROR_INVALID_PARAMETER);
return (FALSE);
}
//------------------------------------------------------------------------------
//
// Function: WriteContextRegisterIoctl
//
// IOCTL called by the xdb browser on host to write one coprocessor register from saved context
//
BOOL OALWriteContextRegisterIoctl(
UINT32 code, VOID *pInpBuffer, UINT32 inpSize, VOID *pOutBuffer,
UINT32 outSize, UINT32 *pOutSize)
{
// Context Write Reg Input Buffer Ptr
PXSCBwrWrteCxtRegIn pXSCBwrWrteCxtRegInBuf;
int i, regPos;
//Check the size of the input & Output buffers
if ((pInpBuffer == NULL) || (sizeof(XSCBwrWrteCxtRegIn) > inpSize))
{
SetLastError(ERROR_INVALID_PARAMETER);
return(FALSE);
}
if (pOutSize != NULL)
{
//Set the Bytes Returned
*pOutSize = 0;
}
// Now assign the pointers to access the data
pXSCBwrWrteCxtRegInBuf = (PXSCBwrWrteCxtRegIn)pInpBuffer;
for (i=0; i < SIZEOFARRAY(XSCBwrQryCxtRegsIdTable); i++)
{
if (XSCBwrQryCxtRegsIdTable[i] == pXSCBwrWrteCxtRegInBuf->RegID)
{
regPos = CxtRegXLTNTable[i];
XSCBwrSaveThreadContextArea.Context_Area[regPos] = 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
{
regPos++;
XSCBwrSaveThreadContextArea.Context_Area[regPos] = pXSCBwrWrteCxtRegInBuf->Reg2;
}
// We've found the register. return.
return (TRUE);
}
}
//RegID was incorrect.
SetLastError(ERROR_INVALID_PARAMETER);
return (FALSE);
}
#endif //USING_XSCALEBROWSER
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -