📄 misc.c
字号:
cp1 += 16;
printf("\n ");
}
}
}
if ((showascii) && (col > 1)) {
int space;
space = (3 * (17 - col)) + (col <= 8 ? 4 : 2);
while(space--)
putchar(' ');
prascii(cp1,col-1);
}
printf("\n");
return;
}
/* CommandLoop():
* This function is called at the end of monitor initialization.
* The monitor spends most of its time here, waiting for incoming
* characters on the console interface.
*/
void
CommandLoop(void)
{
static char cmdline[CMDLINESIZE];
volatile int *yy = 0xa0100004;
/*
while(1) {
yy++;
*yy += 0x01;
if( yy >= 0xa0100400 ) yy = 0xa0100004;
strcpy(cmdline,"flash write 0x1 $APPRAMBASE 100");
docommand(cmdline,0);
}
return 0;//zx debug
*/
while(1) {
stkchk("Cmdloop"); /* Verify valid monitor stack */
writeprompt(); /* Issue prompt */
memset(cmdline,0,CMDLINESIZE); /* Clear command line buffer */
//while(1)
// putchar(target_getchar());
if (getline(cmdline,CMDLINESIZE,INCLUDE_LINEEDIT) == 0)
{
continue;
//printf("getline error\r\n");
}
//else printf("stone1\r\n");
//strcpy(cmdline,"help");
docommand(cmdline,0);
#if INCLUDE_FLASH
LowerFlashProtectWindow();
#endif
}
}
/* mstatshowcom():
* Common stuff that can be printed by the mstat command (part of the
* target-specific code).
*/
void
mstatshowcom(void)
{
stkusage();
#if INCLUDE_ETHERNET
printf("Etheradd_ptr: 0x%lx\n ",(ulong)etheraddr);
#endif
printf("Moncomptr: 0x%lx\n",(ulong)&moncomptr);
printf("Assigned functions...\n");
printf(" getchar/putchar/gotachar: 0x%lx/0x%lx/0x%lx\n",
(ulong)remotegetchar,(ulong)remoteputchar,(ulong)remotegotachar);
printf(" dcacheFlush/icacheInvalidate: 0x%lx/0x%lx\n",
(ulong)dcacheFlush,(ulong)icacheInvalidate);
}
int monitorFlags;
struct monflag monflagtbl[] = {
{ NOMONHEADER, "nophdr" }, /* Don't print header at startup */
{ NODEFRAGPRN, "nopdf" }, /* Don't print defrag msg in tfsclean */
{ NOTFTPPRN, "noptftp" }, /* Don't print for tftp RRQ or WRQ */
{ NOMONCMDPRN, "nopmcmd" }, /* Don't print for incoming moncmd */
{ NOTFTPOVW, "notftpovw" }, /* Don't allow TFTP srvr to overwrite */
{ 0,0 }
};
/* InitMonitorFlags():
* If the shell variable MONFLAGS exists, then use the content of that
* variable to populate the value monitorFlags. The syntax of the shell
* variable is "xxx:yyyy:zzzz:abcd" where xxx,yyyy,zzzz and abcd are
* strings from the monflagtbl that represent some bit in the long that
* is to be set.
*/
void
InitMonitorFlags(void)
{
char *mf, *colon;
struct monflag *mfp;
monitorFlags = 0;
mf = getenv("MONFLAGS");
if (!mf)
return;
while(1) {
colon = strchr(mf,':');
if (colon)
*colon = 0;
mfp = monflagtbl;
while(mfp->flagname) {
if (!strcmp(mf,mfp->flagname)) {
monitorFlags |= mfp->bit;
break;
}
mfp++;
}
if (!mfp->flagname)
printf("MONFLAGS err: %s\n",mf);
if (colon)
*colon = ':';
else
break;
mf = colon+1;
}
}
/* exceptionAutoRestart():
* Serves three purposes:
* 1. Copies the verbose description of the exception to the
* shell variable EXCEPTION_TYPE.
* 2. If there is an EXCEPTION_SCRIPT shell variable, then see if the
* user wants it to be executed.
* 3. If there is no NO_EXCEPTION_RESTART variable, then
* call monrestart with the incoming value (usually INITIALIZE).
*/
void
exceptionAutoRestart(int restartvalue)
{
char *script;
char *arglist[2];
setenv("EXCEPTION_TYPE",ExceptionType2String(ExceptionType));
script = getenv("EXCEPTION_SCRIPT");
if ((script) &&
(!pollConsole("Press any key to stop exception script.\n"))) {
arglist[0] = script;
arglist[1] = (char *)0;
tfsrun(arglist,0);
}
if (!getenv("NO_EXCEPTION_RESTART")) {
if (!pollConsole("Press any key to stop auto restart.\n"))
monrestart(restartvalue);
}
}
/* getAppRamStart():
* First looks for the content of APPRAMBASE shell variable;
* if present, that string is converted to a long and returned,
* else the value of APPLICATION_RAMSTART is returned.
*/
ulong
getAppRamStart(void)
{
char *apprambase;
ulong value;
apprambase = getenv("APPRAMBASE");
if (apprambase)
value = strtoul(apprambase,0,0);
else
value = APPLICATION_RAMSTART;
return(value);
}
/* ticktock():
* Put out a ticker...
*/
void
ticktock(void)
{
static short tick;
char tock;
#if INCLUDE_ETHERNET
/* Don't do any ticker if the command was issued
* from UDP (i.e. moncmd)...
*/
if (IPMonCmdActive)
return;
#endif
switch(tick) {
case 1:
case 5:
tock = '|';
break;
case 2:
case 6:
tock = '/';
break;
case 3:
case 7:
tock = '-';
break;
case 4:
case 8:
tock = '\\';
break;
default:
tock = '|';
tick = 1;
break;
}
tick++;
printf("%c\b",tock);
}
/* inRange():
* This function is handed a range string and a value.
* If the value is within the range of the string specified, then
* return 1; else return 0.
* The incoming string can be a mix of ranges and values with each
* range and/or value separated by a comma and a range is specified
* by 2 numbers separated by a dash.
* Also, incoming ranges of "all" or "any" immediately return true
* and an incoming range of "none" or a null or empty pointer will
* return false.
*/
int
inRange(char *range, int value)
{
int lo, hi;
char rcopy[32], *rsp, *comma, *dash;
/* If incoming range is NULL, return zero.
*/
if ((range == 0) || (*range == 0) || (strcmp(range,"none") == 0))
return(0);
/* If the range string is "all" or "any", then immediately return true...
*/
if ((strcmp(range,"all") == 0) || (strcmp(range,"any") == 0))
return(1);
/* Scan the range string for valid characters:
*/
rsp = range;
while(*rsp) {
if ((*rsp == ',') || (*rsp == '-') ||
(*rsp == 'x') || isxdigit(*rsp))
rsp++;
else
break;
}
if (*rsp)
return(0);
/* If incoming range string exceeds size of copy buffer, return 0.
*/
if (strlen(range) > sizeof(rcopy)-1)
return(0);
strcpy(rcopy,range);
rsp = rcopy;
do {
comma = strchr(rsp,',');
if (comma)
*comma = 0;
dash = strchr(rsp,'-');
if (dash) {
lo = strtol(rsp,0,0);
hi = strtol(dash+1,0,0);
if ((value >= lo) && (value <= hi))
return(1);
}
else {
if (value == strtol(rsp,0,0))
return(1);
}
rsp = comma+1;
} while (comma);
return(0);
}
/* uMonInRam():
* This function returns 1 if the image of the running monitor is
* in RAM; else 0.
*/
int
uMonInRam(void)
{
static long testvar = 0xdeadbeef;
testvar = 0;
if (testvar == 0)
return(1);
else
return(0);
}
/* inUmonBssSpace()
* Return 1 if the address range falls within MicroMonitor's
* own RAM space.
*/
int
inUmonBssSpace(char *start,char *end)
{
static int nowarn;
if (nowarn || getenv("NO_UMONBSS_WARNING")) {
nowarn = 1;
return(0);
}
if (((start >= (char *)&bss_start) && (start < (char *)&bss_end)) ||
((end >= (char *)&bss_start) && (end < (char *)&bss_end)) ||
((start <= (char *)&bss_start) && (end >= (char *)&bss_end))) {
printf("\nWarning: addr range 0x%lx <-> 0x%lx violates uMon ram.\n",
(long)start,(long)end);
return(1);
}
return(0);
}
void
monrestart(int val)
{
/* Allow UART0 transmit FIFO to empty...
*/
flush_console_out();
intsoff();
warmstart(val);
}
void
appexit(int val)
{
AppExitStatus = val;
monrestart(APP_EXIT);
}
/* monWatchDog():
* This function is hooked to the monitor API so that the application
* can use the same function used by monitor code for exciting the
* watchdog hardware.
* Note that if there is no defined WATCHDOG_MACRO, then this function
* returns -1; else it executes the macro and returns 0. This
* return value can be used by the application to decide whether or
* not the call to mon_watchdog() even needs to occur.
*/
int
monWatchDog(void)
{
#ifdef WATCHDOG_ENABLED
WATCHDOG_MACRO;
return(0);
#else
return(-1);
#endif
}
/* putargv() & getargv():
* The getargv() function provides a hook allowing the downloaded
* application code to handle main(argc,argv) in a painless way.
* The Argv[] array location is returned by mon_getargv() and is
* assumed to contain the NULL terminated list of argv pointers...
* Immediately after the NULL termination is the data that the argv
* pointers are referencing.
*
* MONLIB NOTICE: getargv() is accessible through monlib.c.
*/
int
putargv(int argnum,char *argptr)
{
int i;
char buf[8];
if (argnum >= (sizeof(ArgvList)/sizeof(char *)))
return(-1);
if (argnum == 0) {
for(i=0;i<(sizeof(ArgvList)/sizeof(char *));i++) {
sprintf(buf,"ARG%d",i);
setenv(buf,0);
}
setenv("ARGC",0);
ArgvList[0] = (char *)0;
}
ArgvList[argnum] = argptr;
if (argptr) {
sprintf(buf,"ARG%d",argnum);
setenv(buf,ArgvList[argnum]);
}
else {
shell_sprintf("ARGC","%d",argnum);
}
return(0);
}
void
getargv(int *argc,char ***argv)
{
int i;
if (argv)
*argv = &ArgvList[0];
for(i=0;;i++)
if (ArgvList[i] == 0)
break;
if (argc)
*argc = i;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -