📄 console.c
字号:
/* console.cpp
*
*------------------------------------------------------------
*
* I N T E L P R O P R I E T A R Y
*
* COPYRIGHT (c) 1998 BY INTEL CORPORATION. ALL RIGHTS
* RESERVED. NO PART OF THIS PROGRAM OR PUBLICATION MAY
* BE REPRODUCED, TRANSMITTED, TRANSCRIBED, STORED IN A
* RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER
* LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,
* MAGNETIC, OPTICAL, CHEMICAL, MANUAL, OR OTHERWISE, WITHOUT
* THE PRIOR WRITTEN PERMISSION OF :
*
* INTEL CORPORATION
*
* 2200 MISSION COLLEGE BLVD
*
* SANTA CLARA, CALIFORNIA 95052-8119
*
*------------------------------------------------------------
* system: SA1200
* subsystem: console
* author: Henry Qian 12/22/98
* revisions:
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "os.h"
ConsoleCommand consoleCommand[] = {
{"help", help, "Print this list"},
{"i", i, "Summary of tasks' TCBs"},
{"ti", ti, "Detail info for task <tid>"},
{"r", r, "Read memory from <addr>"},
{"n", n, "Read memory from next"},
{"m", m, "Modify memory at <addr>"},
{"list", list, "Disassemble at <addr>"},
{(char*)0, 0, 0}
};
#define MAXLINE 120
char cmdLine[MAXLINE+1];
/*
** void consoleTask(void*)
**
** DESCRIPTION
** Console task has lowest priority, and will run after
** all other tasks have started.
**
** RETURNS
** None.
*/
void consoleTask(void* IGNORE)
{
while (1)
{
printf("EA> ");
if ((gets(cmdLine) == 0) || (strlen(cmdLine) > MAXLINE))
printf("error: <%s>\n", cmdLine);
if (strlen(cmdLine) > 0)
doCommand(cmdLine);
}
}
/*
** void doCommand(void)
**
** DESCRIPTION
** An EA port command executor
**
** RETURNS
** None.
*/
void doCommand(char* cmdLine)
{
int cmd_size;
ConsoleCommand* cmd = consoleCommand;
while(cmd->name != 0)
{
cmd_size = strlen(cmd->name);
if ((strncmp(cmdLine, cmd->name, cmd_size) == 0) &&
( (cmdLine[cmd_size] == '\0') ||
(cmdLine[cmd_size] == ' ')))
{
cmd->func(&cmdLine[cmd_size]);
return;
}
cmd++; /* next console command */
/* At the end of this command entry table, it could be
* dynamically linked to user command entry table.
* cmd->name == 0 indicates the end of this table.
* cmd->func points to user command table if there's any.
*/
if ((cmd->name == 0) && (cmd->func != 0))
cmd = (ConsoleCommand*)(cmd->func);
}
printf(" -- Command not found\n");
}
/*
** void consoleConnect(ConsoleCommand*)
**
** DESCRIPTION
** Connect user console command table.
**
** RETURNS
** None.
*/
void consoleConnect(ConsoleCommand* userCommand)
{
ConsoleCommand* cmd = consoleCommand;
while(cmd->name != 0)
{
cmd++; /* next console command */
/* At the end of this command entry table, it could be
* dynamically linked to user command entry table.
* cmd->name == 0 indicates the end of this table.
* cmd->func points to user command table if there's any.
*/
if ((cmd->name == 0) && (cmd->func != 0))
cmd = (ConsoleCommand*)(cmd->func);
}
/* Now we are at the very end of table.
* Connect to userCommand table.
* Make sure userCommand table has a good format,
* otherwise the console would crash.
*/
cmd->func = (PFC)userCommand;
}
/*
** void help(void*)
**
** DESCRIPTION
** print console command list
**
** RETURNS
** None.
*/
void help(char* IGNORE)
{
ConsoleCommand* cmd = consoleCommand;
while(cmd->name != 0)
{
printf("%20s - %s\n", cmd->name, cmd->help);
cmd++; /* next console command */
/* At the end of this command entry table, it could be
* dynamically linked to user command entry table.
* cmd->name == 0 indicates the end of this table.
* cmd->func points to user command table if there's any.
*/
if ((cmd->name == 0) && (cmd->func != 0))
{
cmd = (ConsoleCommand*)(cmd->func);
printf("\n");
}
}
}
/*
** void i(void*)
**
** DESCRIPTION
**
** RETURNS
** None.
*/
void i(char* IGNORE)
{
uCOS_ShowAllTasks();
}
/*
** void ti(void*)
**
** DESCRIPTION
**
** RETURNS
** None.
*/
void ti(char* param)
{
unsigned int tid;
int retval = getParam(¶m, &tid);
if (retval != 0)
printf(" - format: ti <tid>\n");
else
uCOS_ShowTaskDetail(tid);
}
/*
** void r(void*)
**
** DESCRIPTION
**
** RETURNS
** None.
*/
unsigned int nextAddr = 0;
void r(char* param)
{
int ii;
unsigned int addr;
if (getParam(¶m, &addr) != 0)
printf(" - format: r <addr>\n");
else
{
addr &= 0xFFFFFFFC; // round up to word boundary
for (ii = 0; ii < 4; ii++)
{
printf("0x%08X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
addr,
*(unsigned int*)(addr + 0x0),
*(unsigned int*)(addr + 0x4),
*(unsigned int*)(addr + 0x8),
*(unsigned int*)(addr + 0xC));
addr += 0x10; // next line.
}
nextAddr = addr; // for n() to use.
}
}
/*
** void n(void*)
**
** DESCRIPTION
**
** RETURNS
** None.
*/
void n(char* param)
{
int ii;
if (nextAddr == 0)
return; // r() should be called first.
nextAddr &= 0xFFFFFFFC; // round up to word boundary
for (ii = 0; ii < 4; ii++)
{
printf("0x%08X: 0x%08X 0x%08X 0x%08X 0x%08X\n",
nextAddr,
*(unsigned int*)(nextAddr + 0x0),
*(unsigned int*)(nextAddr + 0x4),
*(unsigned int*)(nextAddr + 0x8),
*(unsigned int*)(nextAddr + 0xC));
nextAddr += 0x10; // next line.
}
}
/*
** void m(void*)
**
** DESCRIPTION
**
** RETURNS
** None.
*/
void m(char* param)
{
unsigned int addr;
unsigned int data;
if ((getParam(¶m, &addr) != 0) ||
(getParam(¶m, &data) != 0))
printf(" - format: m <addr> <data>\n");
else
{
addr &= 0xFFFFFFFC; // round up to word boundary
*(unsigned int*)addr = data;
}
}
#define NUM_OF_INSTR 10
extern void print_insn_arm(unsigned int pc, long given);
unsigned int addrToList = 0;
/*
** void list(void*)
**
** DESCRIPTION
**
** RETURNS
** None.
*/
void list(char* param)
{
int ii;
unsigned int addr;
unsigned int instr;
if (getParam(¶m, &addr) == 0)
addrToList = addr;
for (ii = 0; ii < NUM_OF_INSTR; ii++)
{
instr = *(unsigned int*)addrToList;
printf(" 0x%08x %08x ", addrToList, instr);
print_insn_arm(addrToList, instr);
addrToList += 4;
printf("\n");
}
}
/*
** int getParam(char** str, unsigned int* value)
**
** DESCRIPTION
** converts the input string which is assumed to be a
** numerical value into an integer and moves the pointer
** down the string**
**
** RETURNS
** 1: meet the end of string, value is invalid
** 0: value has a good data.
*/
int getParam(char** str, unsigned int* value)
{
char* beforeMoveThePointer;
while ((**str == ',') | (**str == ' '))
(*str)++;
beforeMoveThePointer = *str;
*value = strtoul(*str, str, 0);
if (beforeMoveThePointer == *str)
return(1); // meet end of string, invalid value.
else
return(0); // successful
}
/*
** int getStringParam(char** str, char* subString)
**
** DESCRIPTION
** converts the input string which is assumed to be a
** numerical value into an integer and moves the pointer
** down the string**
**
** RETURNS
** 1: meet the end of string, value is invalid
** 0: value has a good data.
*/
int getStringParam(char** str, char* subString)
{
unsigned int retval = 0;
unsigned int len;
while ((**str == ',') | (**str == ' '))
(*str)++;
len = strcspn(*str, ", ");
if ((len == 0) | (len > MAXNAME))
retval = 1;
else
{
strncpy(subString, *str, len);
subString[len] = 0;
*str += len;
}
return(retval);
}
/* end of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -