📄 monitor.c
字号:
VOID
PrintTlb(
ULONG Index,
ULONG EntryHi,
ULONG EntryLo,
ULONG PageMask
)
/*++
Routine Description:
Print TLB entry in user-friendly format
Arguments:
Index - supplies index of entry
EntryHi,EntryLo,PageMask - supply tlb registers
Return Value:
None.
--*/
{
//EdbgOutputDebugString("%02X: ",Index);
EdbgOutputDebugString("%X: ",Index);
//EdbgOutputDebugString("VA:%08X ",((EntryHi >> ENTRYHI_VPN2) << ENTRYHI_VPN2));
EdbgOutputDebugString("VA:%X ",((EntryHi >> ENTRYHI_VPN2) << ENTRYHI_VPN2));
//EdbgOutputDebugString("PA:%08X ",((EntryLo >> ENTRYLO_PFN) << 12));
EdbgOutputDebugString("PA:%X ",((EntryLo >> ENTRYLO_PFN) << 12));
PageMask >>= PAGEMASK_PAGEMASK;
switch (PageMask) {
case PAGEMASK_4KB:
EdbgOutputDebugString(" 4KB ");
break;
case PAGEMASK_16KB:
EdbgOutputDebugString(" 16KB ");
break;
case PAGEMASK_64KB:
EdbgOutputDebugString(" 64KB ");
break;
case PAGEMASK_256KB:
EdbgOutputDebugString("256KB ");
break;
case PAGEMASK_1MB:
EdbgOutputDebugString(" 1MB ");
break;
case PAGEMASK_4MB:
EdbgOutputDebugString(" 4MB ");
break;
case PAGEMASK_16MB:
EdbgOutputDebugString(" 16MB ");
break;
}
if (EntryLo & ENTRYLO_G) {
EdbgOutputDebugString("Global ");
}
if (EntryLo & ENTRYLO_V) {
EdbgOutputDebugString("Valid ");
}
if (EntryLo & ENTRYLO_D) {
EdbgOutputDebugString("Writable ");
}
if (((EntryLo >> ENTRYLO_C) & 3) == PAGE_UNCACHED) {
EdbgOutputDebugString("Uncached ");
}
if (((EntryLo >> ENTRYLO_C) & 3) == PAGE_NONCOHERENT_CACHED) {
EdbgOutputDebugString("Cached ");
}
EdbgOutputDebugString("\r\n");
}
VOID
TlbCommand(
IN PCHAR Argv[]
)
/*++
Routine Description:
Routine to probe and write the Tlb
Arguments:
Argv - supplies command line
Return Value:
None.
--*/
{
ULONG i;
ULONG EntryHi;
ULONG EntryLo0;
ULONG PageMask;
ULONG Index;
CHAR * Dummy;
if (Argc == 1) {
//
// No arguments - dump the TLB
//
for (i = 0; i < TB_SIZE; i++) {
TlbProbe(i,&EntryHi,&EntryLo0,&PageMask);
PrintTlb(i,EntryHi,EntryLo0,PageMask);
}
}
else if (Argc == 2) {
//
// One argument - dump the entry specified
//
Index = StrToUlong(Argv[1],&Dummy);
if (Index < TB_SIZE) {
TlbProbe(Index,&EntryHi,&EntryLo0,&PageMask);
PrintTlb(Index,EntryHi,EntryLo0,PageMask);
} else {
EdbgOutputDebugString("TLB Index too big - %d\r\n",Index);
}
}
else if (Argc == 6) {
//
// Arguments present - stuff into TLB
//
Index = StrToUlong(Argv[1],&Dummy);
EntryHi = ((StrToUlong(Argv[2],&Dummy)>>ENTRYHI_VPN2) << ENTRYHI_VPN2);
EntryLo0 = ((StrToUlong(Argv[3],&Dummy) >> 12) << ENTRYLO_PFN);
PageMask = StrToUlong(Argv[4],&Dummy);
if (*Dummy = 'm') {
//
// megabytes
//
switch (PageMask) {
case 1:
PageMask = PAGEMASK_1MB << PAGEMASK_PAGEMASK;
break;
case 4:
PageMask = PAGEMASK_4MB << PAGEMASK_PAGEMASK;
break;
case 16:
PageMask = PAGEMASK_16MB << PAGEMASK_PAGEMASK;
break;
}
} else {
//
// kilobytes
//
switch (PageMask) {
case 4:
PageMask = PAGEMASK_4KB << PAGEMASK_PAGEMASK;
break;
case 16:
PageMask = PAGEMASK_16KB << PAGEMASK_PAGEMASK;
break;
case 64:
PageMask = PAGEMASK_64KB << PAGEMASK_PAGEMASK;
break;
case 256:
PageMask = PAGEMASK_256KB << PAGEMASK_PAGEMASK;
break;
}
}
EntryLo0 |= (1 << ENTRYLO_V);
EntryLo0 |= (1 << ENTRYLO_D);
EntryLo0 |= (1 << ENTRYLO_G);
if (*Argv[5] == 'c') {
EntryLo0 |= PAGE_NONCOHERENT_CACHED << ENTRYLO_C;
} else {
EntryLo0 |= PAGE_UNCACHED << ENTRYLO_C;
}
TlbWrite(Index,EntryHi,EntryLo0,PageMask);
} else {
EdbgOutputDebugString("Usage: tlb [Index] [<VA> <PA> 4KB|16KB|64KB|256KB|1MB|4MB|16MB c|u]\r\n");
}
}
#endif // MONITOR_USED
#pragma warning( disable : 4710 )
////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Display Memory Command
//
void DispMem(IN PULONG pRegTable,
IN ULONG CallerSource)
{
CHAR Buffer[2][128];
ULONG BufferIndex;
PCHAR Argv[10];
PCHAR Tmp;
BOOLEAN CommandValid;
GETSTRING_ACTION Action;
Argv[0] = (PCHAR)NULL;
EdbgOutputDebugString("\r\n");
EdbgOutputDebugString("DD <address> for displaying DWORDS \r\n");
EdbgOutputDebugString("DW <address> for displaying WORDS \r\n");
EdbgOutputDebugString("DB <address> for displaying BYTES \r\n");
// Initialize Static variables.
//
DefaultAddress = UncachedBaseOfRAM();
DataSize = WORD_SIZE;
BufferIndex = 0;
do {
Action = FwGetString(Buffer[BufferIndex],128,NULL);
} while (Action != GetStringSuccess);
EdbgOutputDebugString(FW_CRLF_MSG);
tolower((int)Buffer[BufferIndex]);
// separate command line into tokens delimited by spaces
// load up Argv with pointers to arguments and put count in Argc
//
if (*Buffer[BufferIndex] != '\0') {
Tmp = Buffer[BufferIndex];
Argc = 0;
//
// Skip leading blanks
//
while ( *Tmp == ' ') {
Tmp++;
}
while ( *Tmp ) {
Argv[Argc++] = Tmp;
while ( *Tmp ) {
if (*Tmp == ' ') {
*Tmp++ = '\0';
while ( *Tmp == ' ') {
Tmp++;
}
break;
}
Tmp++;
}
}
//
// Increment index so that next command is read into the other
// buffer. And we preserve the previous one.
//
BufferIndex = (BufferIndex+1) & 0x1;
} else {
//
// repeat the last command already in Argv Argc
//
}
if (Argv[0] != (PCHAR) NULL) {
CurrentArg = 1;
CurrentCommand = GetCommand(Argv[0]);
switch(CurrentCommand) {
case DumpByte:
case DumpWord:
case DumpDouble:
DataSizeShift = (CurrentCommand - Dump -1);
DataSize = 1 << DataSizeShift;
DataSizeMask = DataSize-1;
case Dump:
CommandValid = DumpCommand(Argv,pRegTable);
break;
default:
break;
}
}
}
///////////////////////////////////////////////////////////////////////////////
VOID
Monitor(
IN PULONG pRegTable,
IN ULONG CallerSource
)
/*++
Routine Description:
This is the main dispatch routine to the various commands
that can be typed at the monitor prompt.
Arguments:
CallerSource - 0 if a UTLB or General exception occurred.
- 1 if an NMI_EXCEPTION occurred.
- 2 if a CACHE_EXCEPTION occurred.
- 3 if the caller is not an exception handler.
Return Value:
None.
--*/
{
CHAR Buffer[2][128];
//ULONG ParityDiag[3];
//PULONG ParDiag;
ULONG BufferIndex;
PCHAR Argv[10];
PCHAR Tmp;
BOOLEAN CommandValid;
GETSTRING_ACTION Action;
ULONG Index;
EdbgOutputDebugString(MON_PZ_MONITOR_MSG);
EdbgOutputDebugString("\n\r");
//
// Initialize command line to null.
//
Argv[0] = (PCHAR)NULL;
if (CallerSource != USER_SELECT) {
if (CallerSource == NMI_EXCEPTION) {
EdbgOutputDebugString(MON_NMI_MSG);
EdbgOutputDebugString(MON_EXCEPTION_MSG);
}
if (CallerSource == FAULT_EXCEPTION) {
EdbgOutputDebugString(MON_DOUBLE_FAULT_MSG);
EdbgOutputDebugString(MON_EXCEPTION_MSG);
}
//
// simulate a dump all registers command;
//
EdbgOutputDebugString(MON_PRESS_H_NOQ_MSG);
Argc = 1;
RegisterCommand(Argv, pRegTable);
Argc = 0;
}
else EdbgOutputDebugString(MON_PRESS_H_MSG);
EdbgOutputDebugString("\n\r");
//
// Initialize Static variables.
//
DefaultAddress = UncachedBaseOfRAM();
DataSize = WORD_SIZE;
BufferIndex = 0;
//
// loop forever getting commands and dispatching them
//
while(TRUE) {
//
// print prompt
//
EdbgOutputDebugString(">");
//
// read a command.
//
do {
Action = FwGetString(Buffer[BufferIndex],128,NULL);
} while (Action != GetStringSuccess);
EdbgOutputDebugString(FW_CRLF_MSG);
//
// convert string to lower case.
//
tolower((int)Buffer[BufferIndex]);
//
// separate command line into tokens delimited by spaces
// load up Argv with pointers to arguments and put count in Argc
//
if (*Buffer[BufferIndex] != '\0') {
Tmp = Buffer[BufferIndex];
Argc = 0;
//
// Skip leading blanks
//
while ( *Tmp == ' ') {
Tmp++;
}
while ( *Tmp ) {
Argv[Argc++] = Tmp;
while ( *Tmp ) {
if (*Tmp == ' ') {
*Tmp++ = '\0';
while ( *Tmp == ' ') {
Tmp++;
}
break;
}
Tmp++;
}
}
//
// Increment index so that next command is read into the other
// buffer. And we preserve the previous one.
//
BufferIndex = (BufferIndex+1) & 0x1;
} else {
//
// repeat the last command already in Argv Argc
//
}
//
// if first argument is not null, then dispatch to routines.
//
if (Argv[0] != (PCHAR) NULL) {
CurrentArg = 1;
CurrentCommand = GetCommand(Argv[0]);
switch(CurrentCommand) {
case DumpByte:
case DumpWord:
case DumpDouble:
DataSizeShift = (CurrentCommand - Dump -1);
DataSize = 1 << DataSizeShift;
DataSizeMask = DataSize-1;
case Dump:
CommandValid = DumpCommand(Argv,pRegTable);
break;
case EnterByte:
case EnterWord:
case EnterDouble:
DataSizeShift = (CurrentCommand - Enter -1);
DataSize = 1 << DataSizeShift;
DataSizeMask = DataSize-1;
case Enter:
CommandValid = EnterCommand(Argv,pRegTable);
break;
case OutputByte:
case OutputWord:
case OutputDouble:
DataSizeShift = (CurrentCommand - Output -1);
DataSize = 1 << DataSizeShift;
DataSizeMask = DataSize-1;
case Output:
CommandValid = OutputCommand(Argv,pRegTable);
break;
case InputByte:
case InputWord:
case InputDouble:
DataSizeShift = (CurrentCommand - Input -1);
DataSize = 1 << DataSizeShift;
DataSizeMask = DataSize-1;
case Input:
CommandValid = InputCommand(Argv,pRegTable);
break;
case Register:
CommandValid = RegisterCommand(Argv,pRegTable);
break;
case Zero:
CommandValid = ZeroCommand(Argv,pRegTable);
break;
case Fill:
CommandValid = FillCommand(Argv,pRegTable);
break;
case ModifyRegister:
CommandValid = ModifyRegisterCommand(Argv,pRegTable);
break;
case TlbTableDump:
TlbCommand(Argv);
break;
case CacheArrayDump:
CacheDump();
break;
case Help:
case Help2:
// modified by sudhakar
//for (Index = 0 ; *MON_HELP_TABLE[Index] != '.'; Index++) {
for (Index = 0 ; Index<17; Index++) {
EdbgOutputDebugString(MON_HELP_TABLE[Index]);
EdbgOutputDebugString(FW_CRLF_MSG);
}
break;
case Quit:
if ( (CallerSource == USER_SELECT) || (CallerSource == NMI_EXCEPTION )) {
return;
} else {
//
// We came because of an exception.
// The only way to exit is reseting the system.
//
EdbgOutputDebugString(MON_NO_RETURN_MSG);
break;
}
case JumpTo:
CommandValid = JumpCommand(Argv);
break;
case invalidcommand:
EdbgOutputDebugString(MON_UNRECOGNIZED_COMMAND_MSG);
//
// Clear the argument so that re-do last command
// doesn't repeat the erroneous command.
//
CommandValid = FALSE;
break;
}
if (!CommandValid) {
Argv[0] = (PCHAR) NULL;
}
}
}
}
#pragma warning( default : 4710 )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -