?? sysd_s.cpp
字號:
//***********************************************************************/
// Author : Garry
// Original Date : Jul,03 2005
// Module Name : SYSD_S.CPP
// Module Funciton :
// This module countains system diag application's implemen-
// tation code.
// This file countains the shell command or application
// code,as it's name has ended by "_S".
// Last modified Author :
// Last modified Date :
// Last modified Content :
// 1.
// 2.
// Lines number :
//***********************************************************************/
#ifndef __STDAFX_H__
#include "..\INCLUDE\StdAfx.h"
#endif
#ifndef __SYSD_S_H__
#include "..\INCLUDE\SYSD_S.H"
#endif
#ifndef __PCI_DRV_H__
#include "..\INCLUDE\PCI_DRV.H"
#endif
#include "..\INCLUDE\STAT_S.H"
//
//Pre-declare routines.
//
static DWORD CommandParser(LPSTR);
static DWORD memcheck(__CMD_PARA_OBJ*);
static DWORD cintperf(__CMD_PARA_OBJ*);
static DWORD exit(__CMD_PARA_OBJ*);
static DWORD help(__CMD_PARA_OBJ*);
static DWORD beep(__CMD_PARA_OBJ*);
static DWORD overload(__CMD_PARA_OBJ*);
static DWORD pcilist(__CMD_PARA_OBJ*);
static DWORD devinfo(__CMD_PARA_OBJ*);
static DWORD cpuload(__CMD_PARA_OBJ*);
static DWORD devlist(__CMD_PARA_OBJ*);
//
//The following is a map between command and it's handler.
//
static struct __SYS_DIAG_CMD_MAP{
LPSTR lpszCommand;
DWORD (*CommandHandler)(__CMD_PARA_OBJ*);
LPSTR lpszHelpInfo;
}SysDiagCmdMap[] = {
{"memcheck", memcheck, " memcheck : Check the consistant of the physical memory."},
{"beep", beep, " beep : Beep a while to test the sound system."},
{"overload", overload, " overload : Set a overload event to test the cint performance."},
{"cintperf", cintperf, " cintperf : Print out the last system clock interrupt's CPU clock."},
{"pcilist", pcilist, " pcilist : List all PCI device(s) of the system."},
{"devinfo", devinfo, " devinfo : Print out information about a PCI device."},
{"cpuload", cpuload, " cpuload : Display CPU statistics information."},
{"devlist", devlist, " devlist : List all devices' information in the system."},
{"exit", exit, " exit : Exit the application."},
{"help", help, " help : Print out this screen."},
{NULL, NULL, NULL}
};
//
//The following is a helper routine,it only prints out a "#" character as prompt.
//
static VOID PrintPound()
{
WORD wr = 0x0700;
wr += '#';
ChangeLine();
GotoHome();
PrintCh(wr);
}
//
//This is the application's entry point.
//
DWORD SysDiagStart(LPVOID)
{
BYTE strCmdBuffer[MAX_BUFFER_LEN];
BYTE ucCurrentPtr = 0;
BYTE bt;
WORD wr = 0x0700;
__KERNEL_THREAD_MESSAGE Msg;
DWORD dwRetVal;
PrintPound(); //Print out the prompt.
while(TRUE)
{
if(GetMessage(&Msg))
{
if(MSG_KEY_DOWN == Msg.wCommand) //This is a key down message.
{
bt = LOBYTE(LOWORD(Msg.dwParam));
switch(bt)
{
case VK_RETURN: //This is a return key.
if(0 == ucCurrentPtr) //There is not any character before this key.
{
PrintPound();
break;
}
else
{
strCmdBuffer[ucCurrentPtr] = 0; //Set the terminal flag.
dwRetVal = CommandParser(strCmdBuffer);
switch(dwRetVal)
{
case SYS_DIAG_CMD_PARSER_TERMINAL: //Exit command is entered.
goto __TERMINAL;
case SYS_DIAG_CMD_PARSER_INVALID: //Can not parse the command.
PrintLine(" Invalid command.");
//PrintPound();
break;
case SYS_DIAG_CMD_PARSER_FAILED:
PrintLine("Failed to process the command.");
break;
case SYS_DIAG_CMD_PARSER_SUCCESS: //Process the command successfully.
//PrintPound();
break;
default:
break;
}
ucCurrentPtr = 0; //Re-initialize the buffer pointer.
PrintPound();
}
break;
case VK_BACKSPACE:
if(ucCurrentPtr)
{
ucCurrentPtr --;
GotoPrev();
}
break;
default:
if(ucCurrentPtr < MAX_BUFFER_LEN) //The command buffer is not overflow.
{
strCmdBuffer[ucCurrentPtr] = bt;
ucCurrentPtr ++;
wr += bt;
PrintCh(wr);
wr = 0x0700;
}
break;
}
}
else
{
if(Msg.wCommand == KERNEL_MESSAGE_TIMER)
{
PrintLine("Timer message received.");
}
}
}
}
__TERMINAL:
return 0L;
}
//
//The following routine processes the input command string.
//It is called by SysDiagStart.
//
static DWORD CommandParser(LPSTR lpszCmdLine)
{
DWORD dwRetVal = SYS_DIAG_CMD_PARSER_INVALID;
DWORD dwIndex = 0L;
__CMD_PARA_OBJ* lpCmdParamObj = NULL;
if((NULL == lpszCmdLine) || (0 == lpszCmdLine[0])) //Parameter check
return SYS_DIAG_CMD_PARSER_INVALID;
lpCmdParamObj = FormParameterObj(lpszCmdLine);
if(NULL == lpCmdParamObj) //Can not form a valid command parameter object.
{
return SYS_DIAG_CMD_PARSER_FAILED;
}
if(0 == lpCmdParamObj->byParameterNum) //There is not any parameter.
{
return SYS_DIAG_CMD_PARSER_FAILED;
}
//
//The following code looks up the command map,to find the correct handler that handle
//the current command.If find,then calls the handler,else,return SYS_DIAG_CMD_PARSER_INVALID
//to indicate the failure.
//
while(TRUE)
{
if(NULL == SysDiagCmdMap[dwIndex].lpszCommand)
{
dwRetVal = SYS_DIAG_CMD_PARSER_INVALID;
break;
}
if(StrCmp(SysDiagCmdMap[dwIndex].lpszCommand,lpCmdParamObj->Parameter[0])) //Find the handler.
{
dwRetVal = SysDiagCmdMap[dwIndex].CommandHandler(lpCmdParamObj);
break;
}
else
{
dwIndex ++;
}
}
//__TERMINAL:
if(NULL != lpCmdParamObj)
ReleaseParameterObj(lpCmdParamObj);
return dwRetVal;
}
//
//The exit command's handler.
//
static DWORD exit(__CMD_PARA_OBJ* lpCmdObj)
{
return SYS_DIAG_CMD_PARSER_TERMINAL;
}
//
//The memcheck command's handler.
//
static DWORD memcheck(__CMD_PARA_OBJ* lpCmdObj)
{
return SYS_DIAG_CMD_PARSER_SUCCESS;
}
//
//The help command's handler.
//
static DWORD help(__CMD_PARA_OBJ* lpCmdObj)
{
DWORD dwIndex = 0L;
while(TRUE)
{
if(NULL == SysDiagCmdMap[dwIndex].lpszHelpInfo)
break;
PrintLine(SysDiagCmdMap[dwIndex].lpszHelpInfo);
dwIndex ++;
}
return SYS_DIAG_CMD_PARSER_SUCCESS;
}
//
//The cintperf command's handler.
//
static DWORD cintperf(__CMD_PARA_OBJ* lpCmdObj)
{
BYTE strBuffer[18];
DWORD dwFlags;
__PERF_RECORDER Pr;
__ENTER_CRITICAL_SECTION(NULL,dwFlags);
Pr = TimerIntPr;
__LEAVE_CRITICAL_SECTION(NULL,dwFlags);
u64Hex2Str(&Pr.u64Result,strBuffer);
PrintLine("Last clock circle counter : ");
PrintLine(strBuffer);
u64Hex2Str(&Pr.u64Max,strBuffer);
PrintLine("Max clock circle counter : ");
PrintLine(strBuffer);
return SYS_DIAG_CMD_PARSER_SUCCESS;
}
//
//The overload command's handler.
//
static DWORD overload(__CMD_PARA_OBJ* lpCmdObj)
{
DWORD dwTimerNum = 10;
DWORD dwTimerID = 00200000;
DWORD dwTimeSpan = 100;
__COMMON_OBJECT* lpTimerObject = NULL;
if((NULL == lpCmdObj) || (lpCmdObj->byParameterNum < 2)) //Parameter check.
{
PrintLine(" Please input the beep time,in millionsecond.");
return SYS_DIAG_CMD_PARSER_INVALID;
}
if(!Str2Hex(lpCmdObj->Parameter[1],&dwTimerNum)) //Get the time span to beep.
{
PrintLine(" Invalid time parameter.");
return SYS_DIAG_CMD_PARSER_INVALID;
}
while(dwTimerNum)
{
lpTimerObject = System.SetTimer((__COMMON_OBJECT*)&System,
KernelThreadManager.lpCurrentKernelThread,
dwTimerID,
dwTimeSpan,
NULL,
NULL,
TIMER_FLAGS_ONCE);
if(NULL == lpTimerObject) //Failed to set timer.
{
PrintLine(" Can not set timer,please try again.");
return SYS_DIAG_CMD_PARSER_FAILED;
}
dwTimerNum --;
}
return SYS_DIAG_CMD_PARSER_SUCCESS;
}
//
//The beep command's handler.
//
static DWORD beep(__CMD_PARA_OBJ* lpCmdObj)
{
__KERNEL_THREAD_MESSAGE Msg;
DWORD dwTimerID = 00100000;
DWORD dwTimeSpan = 0L;
__COMMON_OBJECT* lpTimerObject = NULL;
UCHAR ucCtrlByte;
if((NULL == lpCmdObj) || (lpCmdObj->byParameterNum < 2)) //Parameter check.
{
PrintLine(" Please input the beep time,in millionsecond.");
return SYS_DIAG_CMD_PARSER_INVALID;
}
if(!Str2Hex(lpCmdObj->Parameter[1],&dwTimeSpan)) //Get the time span to beep.
{
PrintLine(" Invalid time parameter.");
return SYS_DIAG_CMD_PARSER_INVALID;
}
//
//Now,the variable dwTimeSpan countains the time to beep.
//
lpTimerObject = System.SetTimer((__COMMON_OBJECT*)&System,
KernelThreadManager.lpCurrentKernelThread,
dwTimerID,
dwTimeSpan,
NULL,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -