📄 monitor.c
字号:
* Input: None
* Output: None
* Synopsis: Get a line of input, and call the corresponding command.
*****************************************************************************/
int ParseLine(void) {
int i;
char line[CMD_LINE_SIZE], *cur_line, tmp_line[CMD_LINE_SIZE];
unsigned argv[MAX_ARGS];
char *token;
char IllegalCommand;
int argc;
#if(SH_PLATFORM==PLATFORM_ASPEN)
Write_LED_Data("ASPEN", 0x202);
#elif (SH_PLATFORM==PLATFORM_BIGSUR)
Write_LED_Data("BIGSUR", 0x202);
#endif
WriteOutput("> ");
// Get a line of input into the string line till you get a carriage return.
ReadInput(line);
Write_LED_Data(line, 0x203);
// cur_line points to the current position within the line.
cur_line = line;
// Get rid of the empty space in the beginning of the line.
while(*cur_line == '\t' || *cur_line == ' ')
cur_line ++;
// All lines beginning with a '#' are ignored. This indicates that this
// line is a comment line. This does not seem very useful at present
// since the user is giving the input manually, but will be useful later
// if we use some mechanism to give input thru command scripts to the
// monitor.
if(*cur_line == '#')
return 0;
/* Keep a copy of line so that you can parse command line arguments
* both before calling a command and after calling a command.
*/
strcpy(tmp_line, line);
token = StrTok(cur_line, DELIM_STR);
// Empty line.
if(token == NULL)
return 0;
// Now match this token among the list of tokens supported by the debugger.
i = 0;
IllegalCommand = TRUE;
while(CmdTable[i].name != '\0') {
if(!StrICmp(token, CmdTable[i].name)) {
// Execute the associated function.
IllegalCommand = FALSE;
/* Now while token is not null, keep reading arguments off the command line. */
argc = 0;
token = StrTok(NULL, DELIM_STR);
while(token != NULL) {
argv[argc++] = ToHex(token);
token = StrTok(NULL, DELIM_STR);
}
/* The function may also call StrTok to get tokens from the line
* start from the token after the command name. For that i call
* StrTok once here, to get the command name off from the line.
*/
token = StrTok(tmp_line, DELIM_STR);
/* Now subsequent StrTok's will give the parameters of the command */
WriteDbgOutput(DEB_INFO, ("Calling (0x%x)(%d, %d, %d, 0x%x)\n", CmdTable[i].func, CmdTable[i].sub_command, CmdTable[i].name, CmdTable[i].expected_argc, argc, argv));
/* IF it is a Command_Exit, return 1 */
if(CmdTable[i].func == Command_Exit) {
return 1;
}
(*(CmdTable[i].func))(CmdTable[i].sub_command, CmdTable[i].expected_argc, argc, argv);
break;
}
i++;
}
// Print Error message.
if(IllegalCommand) {
WriteOutput("Illegal Command. Line %d, Command: %s\n", CurrentLine, line);
}
return 0;
}
/******************************************************************************
* Function: Command_SetBaud
* Input: baud rate to be set as argv[1]
* Output: None.
* Purpose: Set the baud rate.
*****************************************************************************/
void Command_SetBaud(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
unsigned new_baud = 0;
char dummy_str[10];
// If you change this string, change the case statement below appropriately.
char *supported = "Supported baud rates are: 9600, 19200, 38400, 57600, 115200.\n";
// Print the current baud rate.
WriteOutput("Current baud rate is %d\n", OEMSetDebugSerialBaudRate(0));
// If no argument was given, just print valid baud rates.
if(argc == 0) {
WriteOutput(supported);
return;
}
// Get the new baud rate.
new_baud = argv[0];
// Hex -> Dec
// Now this baud rate is the input value interpreted as hex, though actually
// the value was given as decimal. So i convert it back to string and
// interpret it as decimal.
ToStr(new_baud, dummy_str);
WriteDbgOutput(DEB_INFO, ("dummy_str = %s\n", dummy_str));
new_baud = ToDec(dummy_str);
WriteDbgOutput(DEB_INFO, ("new_baud = %d\n", new_baud));
switch(new_baud) {
case 9600:
case 19200:
case 38400:
case 57600:
case 115200:
WriteDbgOutput(DEB_INFO, ("Setting Baud rate to %d\n", new_baud));
OEMSetDebugSerialBaudRate(new_baud);
break;
default:
WriteOutput("Invalid baud rate %d\n", new_baud);
WriteOutput(supported);
return;
}
}
/******************************************************************************
* Function: Command_Write
* Input: size: size of data to be written
* Next Token contains the address.
* Next Token contains the data to be written.
* Output: None.
* Purpose: Write b/w/l at the address mentioned.
*****************************************************************************/
void Command_Write(int size) {
char *token;
char DataStr[8];
unsigned Addr, Data;
// Get address to be displayed.
token = StrTok(NULL, DELIM_STR);
// Convert this address to hex.
Addr = ToHex(token);
// Get Data to be written.
token = StrTok(NULL, DELIM_STR);
// If token is NULL, then go into a loop and read and write data at
// subsequent addresses. Else write single data.
if(token != NULL) {
// Convert this Data to hex.
Data = ToHex(token);
switch(size) {
case 1:
*(unsigned char *)Addr = Data;
break;
case 2:
Addr &= 0xFFFFFFFE;
*(unsigned short *)Addr = Data;
break;
case 4:
Addr &= 0xFFFFFFFC;
*(unsigned long *)Addr = Data;
break;
}
}
else {
while(TRUE) {
// Print the Data at the current location.
switch(size) {
case 1:
WriteOutput(F_L ": " F_B " ", Addr, *(unsigned char *)Addr);
ReadInput(DataStr);
if(DataStr[0] == '.')
return;
if(DataStr[0] == '\0')
break;
if(DataStr[0] == '^') {
Addr -= 2 * size;
break;
}
Data = ToHex(DataStr);
*(unsigned char *)Addr = Data;
break;
case 2:
Addr &= 0xFFFFFFFE;
WriteOutput(F_L ": " F_S " ", Addr, *(unsigned short *)Addr);
ReadInput(DataStr);
if(DataStr[0] == '.')
return;
if(DataStr[0] == '\0')
break;
if(DataStr[0] == '^') {
Addr -= 2 * size;
break;
}
Data = ToHex(DataStr);
*(unsigned short *)Addr = Data;
break;
case 4:
Addr &= 0xFFFFFFFC;
WriteOutput(F_L ": " F_L " ", Addr, *(unsigned long *)Addr);
ReadInput(DataStr);
if(DataStr[0] == '.')
return;
if(DataStr[0] == '\0')
break;
if(DataStr[0] == '^') {
Addr -= 2 * size;
break;
}
Data = ToHex(DataStr);
// WriteOutput("Writing %X to %X\r\n", Data, Addr);
*(unsigned long *)Addr = Data;
break;
}
Addr += size;
}
}
}
/******************************************************************************
* Function: Command_Display
* Input: None. Next Token contains the address.
* Output: None.
* Purpose: Read and Display 8 dwords starting from address.
*****************************************************************************/
void Command_Display(int size) {
char *token;
unsigned Addr;
unsigned count, displayed;
// Get address to be displayed.
token = StrTok(NULL, DELIM_STR);
// Convert this address to hex.
Addr = ToHex(token);
if(size == 0) {
count = 32;
}
else {
// Default number of data to print is 1.
count = 1;
token = StrTok(NULL, DELIM_STR);
if(token != NULL)
count = ToHex(token);
count = count * size;
}
// Align Address.
switch(size) {
case 1:
// No alignment needed.
break;
case 2:
Addr &= 0xFFFFFFFE;
break;
case 0:
case 4:
Addr &= 0xFFFFFFFC;
break;
}
displayed = 0; // number of bytes displayed yet.
// Now display count data starting at address Addr. 16 bytes per line.
while(displayed < count) {
if(displayed == 0)
WriteOutput(F_L ": ", Addr);
else if(0 == (displayed % 16))
WriteOutput("\r\n" F_L ": ", Addr);
switch(size) {
case 1:
WriteOutput(F_B " ", *(unsigned char *)Addr);
displayed += 1;
Addr += 1;
break;
case 2:
WriteOutput(F_S " ", *(unsigned short *)Addr);
displayed += 2;
Addr += 2;
break;
case 4:
case 0:
WriteOutput(F_L " ", *(unsigned long *)Addr);
displayed += 4;
Addr += 4;
break;
}
}
WriteOutput("\r\n");
}
/******************************************************************************
* Function: Command_Disassemble
* Input: None. Next Token contains the address.
* Output: None.
* Purpose: Disassemble starting from specified address.
*****************************************************************************/
void Command_Disasm(unsigned sub_command, unsigned expected_argc, unsigned argc, unsigned *argv)
{
unsigned Addr;
unsigned count, i;
static unsigned old_addr = 0xA0000000;
// Default number of instructions to disassemble.
count = 10;
switch(argc) {
case 2: count = argv[1]; /* Fall Through */
case 1: Addr = argv[0];
break;
case 0: Addr = old_addr;
break;
default: WriteOutput("Command_Disasm called with invalid number of arguments (%d).\n", argc);
return;
}
for(i = 0; i < count; i++) {
Disasm((ADDR) (Addr+i*2), (char *)(Addr + i*2), 1);
}
old_addr = Addr + i*2;
}
/************************************************************************************
* Function: Command_Help
* Input: None.
* Output: None.
* Purpose: Prints Help
***********************************************************************************/
void Command_Help(void) {
int i = 0;
Write_LED_Data("Help", 0x210);
// Print the help. Try writing all the command alphabetically.
WriteOutput("Boot Monitor Help.\r\n");
WriteOutput("(All commands are case insensitive, All values are in Hex unless specified.)\r\n\n");
WriteOutput("=============================================================================\r\n");
WriteOutput("Command Purpose\r\n");
WriteOutput("-----------------------------------------------------------------------------\r\n");
WriteOutput("Complete Commands\r\n");
WriteOutput("=============================================================================\r\n");
while(CmdTable[i].name != '\0') {
if(CmdTable[i].help_string) {
WriteOutput("%s.\r\n", CmdTable[i].help_string);
}
i ++;
}
WriteOutput("\r\n");
WriteOutput("Basic Commands\r\n");
WriteOutput("=============================================================================\r\n");
i = 0;
while(CmdTable[i].name != '\0') {
if(CmdTable[i].basic_command && CmdTable[i].help_string) {
WriteOutput("%s.\r\n", CmdTable[i].help_string);
}
i ++;
}
WriteOutput("=============================================================================\r\n");
WriteOutput("\r\n");
}
/************************************************************************************
* Function: Command_Identify
* Input: None.
* Output: None.
* Purpose: Prints SDB Information List so that device may be identified.
***********************************************************************************/
void Command_Identify(void) {
WriteOutput("Company : Hitachi Semiconductor (America) Inc.\r\n");
WriteOutput("Support : Application Engineering\r\n");
WriteOutput(" Tom Yu\r\n");
WriteOutput(" (408) 456-2110\r\n");
WriteOutput(" Tom.Yu@hsa.hitachi.com\r\n");
WriteOutput("Harp SDB Specification : 5.5\r\n");
WriteOutput("Hardware PCB Revision : 4\r\n");
WriteOutput("Boot Monitor Revision : ROM Bootloader Version 1.0\r\n");
WriteOutput(" Built %s\r\n", __DATE__);
WriteOutput("Processor ID : Hitachi SH4\r\n");
WriteOutput("Processor Version : HD6417750\r\n");
WriteOutput("Upgrade Instructions : Contact Hitachi Sales\r\n");
WriteOutput("Configuration : Debug Serial\r\n");
WriteOutput(" Parallel Port\r\n");
WriteOutput(" LAN91C100FD 10/100 Mb Ethernet MAC Rev 0x3268\r\n");
WriteOutput(" V360EPC-33LP PCI bridge Rev A1\r\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -