kerninst.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 188 行

C
188
字号
/* Copyright (c) 1999-2000 Microsoft Corporation.  All rights reserved. */
#ifdef WINCECODETEST
#include "windows.h"
#include "schedlog.h"

#define __KERNINST__
#include "tagaddrs.h"

// AMC code
#ifndef __CT__
#include "ct.h"
#endif

#ifndef __CT_CE__
#include "ct_ce.h"
#endif

//------------------------------------------------------------------------------
// AMC code: global definitions and initialization of AMC port pointers
// Placed at PCI address that is mapped to PLX Technology 9050 card.
// Must be specified as the virtual addresses that map to the physical addresses
// specified in oeminit.asm file.
//------------------------------------------------------------------------------
#define AMC_CTRL_PORT ((volatile unsigned long *)AMC_CTRL_PORT_ADDR)
#define AMC_DATA_PORT ((volatile unsigned long *)AMC_DATA_PORT_ADDR)

static unsigned long amc_ctrl_dummy_port;
static unsigned long amc_data_dummy_port;
volatile unsigned long *amc_ctrl_port = &amc_ctrl_dummy_port;
volatile unsigned long *amc_data_port = &amc_data_dummy_port;

// These are used for the process/thread information, so they are always
// pointed to the correct address.
static volatile unsigned long *kern_ctrl_port = AMC_CTRL_PORT;
static volatile unsigned long *kern_data_port = AMC_DATA_PORT;

static HANDLE ThreadHandle = 0;
static HANDLE ProcessHandle = 0;
static HANDLE* pThreadHandle = &ThreadHandle;
static HANDLE* pProcessHandle = &ProcessHandle;

// AMC: code added for Initialization of kernel function
// pointers for kernel call-back hooks to CodeTEST.
//
// To activate the hooks, you have to set the kernel's function
// pointers to point to the OAL's implementation of the functions. 
// This is done with the function ThreadProcLogInitialize(), called inside
// OEMInit() function, located in this file.

typedef void (* LogThreadCreate_t)(DWORD, DWORD);
typedef void (* LogThreadDelete_t)(DWORD, DWORD);
typedef void (* LogProcessCreate_t)(DWORD);
typedef void (* LogProcessDelete_t)(DWORD);
typedef void (* LogThreadSwitch_t)(DWORD, DWORD);

extern LogThreadCreate_t pLogThreadCreate;
extern LogThreadDelete_t pLogThreadDelete;
extern LogProcessCreate_t pLogProcessCreate;
extern LogProcessDelete_t pLogProcessDelete;
extern LogThreadSwitch_t pLogThreadSwitch;

//void ThreadProcLogInitialize();

//------------------------------------------------------------------------------
// LogThreadCreate
//------------------------------------------------------------------------------
void LogThreadCreate(DWORD dwThreadID, DWORD dwProcID)
{
    // AMC: added to support CodeTEST
    // convert ID to handle
    SchedLogTranslate(dwThreadID, &ThreadHandle, 0, NULL);

    *kern_data_port = (UINT32)ThreadHandle;  // output Thread handle twice
    *kern_data_port = (UINT32)ThreadHandle;
    *kern_ctrl_port = TASK_CREATE | TASK_NAME_TYPE_INTEGER;
} // end of LogThreadCreate

//------------------------------------------------------------------------------
// LogThreadDelete
//------------------------------------------------------------------------------
void LogThreadDelete(DWORD dwThreadID, DWORD dwProcID)
{
    // AMC: added to support CodeTEST
    // convert ID to handle
    SchedLogTranslate(dwThreadID, &ThreadHandle, 0, NULL);

    *kern_data_port = (UINT32)ThreadHandle;  // output Thread handle twice
    *kern_data_port = (UINT32)ThreadHandle;
    *kern_ctrl_port = TASK_DELETE | TASK_NAME_TYPE_INTEGER;
}  // end of LogThreadDelete


//------------------------------------------------------------------------------
// LogProcessCreate
//------------------------------------------------------------------------------
void LogProcessCreate(DWORD dwProcID)
{
    // AMC: added to support CodeTEST
    // convert ID to handle
    SchedLogTranslate(0, NULL, dwProcID, &ProcessHandle);

    *kern_data_port = (UINT32)ProcessHandle;  // output process handle twice
    *kern_data_port = (UINT32)ProcessHandle;
    // process is mapped to CodeTest task
    *kern_ctrl_port = TASK_CREATE | TASK_NAME_TYPE_INTEGER;
}  // end of LogProcessCreate


//------------------------------------------------------------------------------
// LogProcessDelete
//------------------------------------------------------------------------------
void LogProcessDelete(DWORD dwProcID)
{
    // AMC: added to support CodeTEST
    // convert ID to handle
    SchedLogTranslate(0, NULL, dwProcID, &ProcessHandle);

    *kern_data_port = (UINT32)ProcessHandle;  // output process handle twice
    *kern_data_port = (UINT32)ProcessHandle;
    // process is mapped to CodeTest task
    *kern_ctrl_port = TASK_DELETE | TASK_NAME_TYPE_INTEGER;
} // end of LogProcessDelete


//------------------------------------------------------------------------------
// LogThreadSwitch
//------------------------------------------------------------------------------
void LogThreadSwitch(DWORD dwThreadID, DWORD dwProcID)
{
    // AMC: added to support CodeTEST
    // convert ID to handle
    SchedLogTranslate(dwThreadID, pThreadHandle, dwProcID, pProcessHandle);

    *kern_data_port = (UINT32)ThreadHandle; // output thread handle twice
    *kern_data_port = (UINT32)ThreadHandle;
    *kern_ctrl_port = TASK_SWITCH | TASK_NAME_TYPE_INTEGER;
} // end of LogThreadSwitch


//------------------------------------------------------------------------------
// ThreadProcLogInitialize
//------------------------------------------------------------------------------
void ThreadProcLogInitialize()
{
    pLogThreadCreate = LogThreadCreate;
    pLogThreadDelete = LogThreadDelete;
    pLogProcessCreate = LogProcessCreate;
    pLogProcessDelete = LogProcessDelete;
    pLogThreadSwitch = LogThreadSwitch;
} // end of ThreadProcLogInitialize


//------------------------------------------------------------------------------
// ThreadProcLogDeinitialize
//------------------------------------------------------------------------------
void ThreadProcLogDeinitialize()
{
    pLogThreadCreate = NULL;
    pLogThreadDelete = NULL;
    pLogProcessCreate = NULL;
    pLogProcessDelete = NULL;
    pLogThreadSwitch = NULL;
} // end of ThreadProcLogDeinitialize


//------------------------------------------------------------------------------
// CT_Profile
//------------------------------------------------------------------------------
void CT_Profile(DWORD Start)
{
    // if starting profiling, hook up port to proper address, else to dummy
    if (Start)
    {
        amc_ctrl_port = AMC_CTRL_PORT;
        amc_data_port = AMC_DATA_PORT;
    }
    else
    {
        amc_ctrl_port = &amc_ctrl_dummy_port;
        amc_data_port = &amc_data_dummy_port;
    }
}

//-----------------------------------
// end of CodeTEST init hooks code
//-----------------------------------
#endif

⌨️ 快捷键说明

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