coproc.c

来自「该BSP是基于PXA270+WINCE的BSP」· C语言 代码 · 共 131 行

C
131
字号
//
// 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.
//
//------------------------------------------------------------------------------
//
//  File:  coproc.c
//
//  Intel Mainstone II board coprocessor code.
//   1) saving and restoring coprocessors on context switch, and
//   2) coproc functions for xscale debug browser (xdb) trace collection

#if defined(USING_COPROCSUPPORT) || defined(USING_XSCALEBROWSER)

#define WINCEMACRO 1
#include <windows.h>
#include <coproc.h>
#ifdef USING_XSCALEBROWSER
#include <xdbioctl.h>
#include <xdb.h>
#endif

// Function pointers and vars for Saving/Restoring CoProc Register
// 
extern DWORD cbNKCoProcRegSize;
extern DWORD fNKSaveCoProcReg;
extern void (*pOEMInitCoProcRegisterSavedArea) (LPBYTE pArea); 
extern void (*pOEMRestoreCoProcRegister) (LPBYTE);
extern void (*pOEMSaveCoProcRegister)(LPBYTE);

// Prototypes for Assembly routines used for saving/restoring CoProc Registers
//
extern void Xllp_Save_WMMX_Regs(LPBYTE pArea);
extern void Xllp_Restore_WMMX_Regs(LPBYTE pArea);

// Function prototypes
//
void OALInitCoProc();
void OEMInitCoProcRegisterSavedArea(LPBYTE pArea);
void OEMSaveCoProcRegister( LPBYTE pArea );
void OEMRestoreCoProcRegister( LPBYTE pArea);

//------------------------------------------------------------------------------
//
//  Function:  OEMInitCoProcRegisterSavedArea
//
//  This function is required to support xdb browser's trace collection mechanism.
//  Init routine called during OEMInit to initialize kernel vars and function pointers.
//
void OALInitCoProc()
{
    cbNKCoProcRegSize = XSCOPROCREGSAVE_SIZE;
    fNKSaveCoProcReg = 1;
    pOEMInitCoProcRegisterSavedArea = OEMInitCoProcRegisterSavedArea;
    pOEMSaveCoProcRegister = OEMSaveCoProcRegister;
    pOEMRestoreCoProcRegister = OEMRestoreCoProcRegister;
}

//------------------------------------------------------------------------------
//
//  Function:  OEMInitCoProcRegisterSavedArea
//
//  This function is required to support xdb browser's trace collection mechanism.
//  The function sets up the memory area allocated for use in saving/restoring CoProcessor registers.
//  This function is called for every thread created.
//
void OEMInitCoProcRegisterSavedArea(LPBYTE pArea)
{
   // Set initial state of CoProc Reg Area (which will in turn be the Register value) here
   memset( pArea, 0, XSCOPROCREGSAVE_SIZE);
}

//------------------------------------------------------------------------------
//
//  Function:  OEMSaveCoProcRegister
//
//  This function is required to support xdb browser's trace collection mechanism.
//  It is only called when both NkCoProcRegSize and fNKSaveCoProcReg are non-zero values.
//  This function is called every time a thread is to be switched out, so it 
//  adds to the overall worst-case time of thread switches!.
//
void OEMSaveCoProcRegister( LPBYTE pArea )
{
#ifdef USING_XSCALEBROWSER
    if (XSCBwrThreadID == GetCurrentThreadId()) {
        XSCBwrExecutionTraceOff(0);
        XSCBwrSaveThreadContextArea.ThreadId = XSCBwrThreadID;
        XSCBwrSaveThreadContextArea.ContextPtr = (DWORD) pArea;
        Xllp_Save_WMMX_Regs((LPBYTE)&XSCBwrSaveThreadContextArea.Context_Area[0]);
        return;
    }
#endif  //USING_XSCALEBROWSER
    Xllp_Save_WMMX_Regs(pArea);
}

//------------------------------------------------------------------------------
//
//  Function:  OEMRestoreCoProcRegister
//
//  This function is required to support xdb browser's trace collection mechanism.
//  It is only called when both cbNkCoProcRegSize and fNKSaveCoProcReg are non-zero values.
//  This function is called every time a thread is to be switched in, so it 
//  adds to the overall worst-case time of thread switches!.
//
void OEMRestoreCoProcRegister( LPBYTE pArea)
{
#ifdef USING_XSCALEBROWSER
    if (XSCBwrSaveThreadContextArea.ContextPtr == (DWORD) pArea)  {

        Xllp_Restore_WMMX_Regs((LPBYTE)&XSCBwrSaveThreadContextArea.Context_Area[0]);

        if (XSCBwrThreadID == (DWORD) INVALID_HANDLE_VALUE)
            XSCBwrSaveThreadContextArea.ContextPtr = 0;
        else
            XSCBwrExecutionTraceOn(0);

        return;
    }
#endif  //USING_XSCALEBROWSER
    Xllp_Restore_WMMX_Regs(pArea);
}

#endif  //defined(USING_COPROCSUPPORT) || defined(USING_XSCALEBROWSER)
//------------------------------------------------------------------------------

⌨️ 快捷键说明

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