/* start(): * Called at the end of reset.s as the first C function after processor * bootup. It is passed a state that is used to determine whether or not * the CPU is restarting as a result of a warmstart or a coldstart. If * the restart is a coldstart, then state will be INITIALIZE. if the * restart is a warmstart, then there are a few typical values of state, * the most common of which are APP_EXIT and EXCEPTION. * * The bss_start and bss_end variables are usually defined in the * target-specific linker memory-map definition file. They symbolically * identify the beginning and end of the .bss section. Many compilers * support intrinsic tags for this; however, since it is apparently not * consistent from one toolset to the next; I chose to make up my own * tags so that this file never changes from one toolset to the next. * * The FORCE_BSS_INIT definition can be established in the target-specific * config.h file to force .bss space initialization regardless of warm/cold * start. */ void start(int state) { char buf[48]; #ifdef FORCE_BSS_INIT state = INITIALIZE; #endif /* Based on the incoming value of 'state' we may or may not initialize * monitor-owned ram. Ideally, we only want to initialize * monitor-owned ram when 'state' is INITIALIZE (power-up or reset); * however, to support the case where the incoming state variable may * be corrupted, we also initialize monitor-owned ram when 'state' * is anything unexpected... */ switch(state) { case EXCEPTION: case APP_EXIT: break; case INITIALIZE: default: umonBssInit(); break; } /* Now that the BSS clear loop has been done, we can copy the * value of state (either a register or on stack) to the global * variable (in BSS) StateOfMonitor... */ StateOfMonitor = state; /* Step through different phases of startup... */ init0(); init1(); init2(); /* Depending on the type of startup, alert the console and do * further initialization as needed... */ switch(StateOfMonitor) { case INITIALIZE: reginit(); init3(); break; case APP_EXIT: EthernetStartup(0,0); if(!MFLAGS_NOEXITSTATUS()) { printf("\nApplication Exit Status: %d (0x%x)\n", AppExitStatus,AppExitStatus); } break; case EXCEPTION: EthernetStartup(0,0); printf("\n%s: '%s'\n",EXCEPTION_HEADING, ExceptionType2String(ExceptionType)); printf(" Occurred near 0x%lx",ExceptionAddr); if(AddrToSym(-1,ExceptionAddr,buf,0)) { printf(" (within %s)",buf); } printf("\n\n"); exceptionAutoRestart(INITIALIZE); break; default: printf("Unexpected monitor state: 0x%x (sp @ 0x%x)\n", StateOfMonitor, buf); /* To attempt to recover from the bad state, just do * what INITIALIZE would do... */ reginit(); init3(); break; } #ifdef LOCK_FLASH_PROTECT_RANGE /* Issue the command that will cause the range of sectors * designated by FLASH_PROTECT_RANGE to be locked. This only * works if the flash device is capable of being locked. */ sprintf(buf,"flash lock %s",FLASH_PROTECT_RANGE); docommand(buf,0); #endif #ifdef PRE_COMMANDLOOP_HOOK PRE_COMMANDLOOP_HOOK(); #endif /* Enter the endless loop of command processing: */ CommandLoop(); printf("ERROR: CommandLoop() returned\n"); monrestart(INITIALIZE); }
int Strace(int argc,char *argv[]) { char *symfile, fname[64]; TFILE *tfp; ulong *framepointer, pc, fp, offset; int tfd, opt, maxdepth, pass, verbose, bullseye; tfd = fp = 0; maxdepth = 20; verbose = 0; pc = ExceptionAddr; while ((opt=getopt(argc,argv,"d:F:P:rs:v")) != -1) { switch(opt) { case 'd': maxdepth = atoi(optarg); break; case 'F': fp = strtoul(optarg,0,0); break; case 'P': pc = strtoul(optarg,0,0); break; case 'r': showregs(); break; case 'v': verbose = 1; break; default: return(0); } } if (!fp) getreg("A6", (ulong *)&framepointer); else framepointer = (ulong *)fp; /* Start by detecting the presence of a symbol table file... */ symfile = getenv("SYMFILE"); if (!symfile) symfile = SYMFILE; tfp = tfsstat(symfile); if (tfp) { tfd = tfsopen(symfile,TFS_RDONLY,0); if (tfd < 0) tfp = (TFILE *)0; } /* Show current position: */ printf(" 0x%08lx",pc); if (tfp) { AddrToSym(tfd,pc,fname,&offset); printf(": %s()",fname); if (offset) printf(" + 0x%lx",offset); } putchar('\n'); /* Now step through the stack frame... */ bullseye = pass = 0; while(maxdepth) { /* ADD_CODE_HERE */ } if (!maxdepth) printf("Max depth termination\n"); if (tfp) { tfsclose(tfd,0); } return(0); }
void prof_ShowStats(int minhit, int more) { int i, tfd, linecount; ulong notused; char symname[64]; struct pdata *pptr; printf("FuncCount Cfg: tbl: 0x%08lx, size: 0x%x\n", (ulong)prof_FuncTbl, prof_FuncTot); printf("TidCount Cfg: tbl: 0x%08lx, size: 0x%x\n", (ulong)prof_TidTbl, prof_TidTot); printf("PcCount Cfg: tbl: 0x%08lx, size: 0x%x\n", (ulong)prof_PcTbl, prof_PcTot*prof_PcWidth); if(prof_CallCnt == 0) { printf("No data collected%s", prof_Enabled == 0 ? " (profiling disabled)\n" : "\n"); return; } linecount = 0; tfd = prof_GetSymFile(); if((prof_FuncTbl) && (prof_FuncTot > 0)) { printf("\nFUNC_PROF stats:\n"); pptr = prof_FuncTbl; for(i=0; i<prof_FuncTot; pptr++,i++) { if(pptr->pcount < minhit) { continue; } if((tfd < 0) || (AddrToSym(tfd,pptr->data,symname,¬used) == 0)) { printf(" %08lx : %d\n",pptr->data,pptr->pcount); } else { printf(" %-25s: %d\n",symname,pptr->pcount); } if((more) && (++linecount >= more)) { linecount = 0; if(More() == 0) { goto showdone; } } } } if((prof_TidTbl) && (prof_TidTot > 0)) { printf("\nTID_PROF stats:\n"); pptr = prof_TidTbl; for(i=0; i<prof_TidTot; pptr++,i++) { if(pptr->pcount < minhit) { continue; } printf(" %08lx : %d\n",pptr->data,pptr->pcount); if((more) && (++linecount >= more)) { linecount = 0; if(More() == 0) { goto showdone; } } } } if(prof_PcTbl) { ushort *sp; ulong *lp; sp = (ushort *)prof_PcTbl; lp = (ulong *)prof_PcTbl; printf("\nPC_PROF stats:\n"); for(i=0; i<prof_PcTot; i++) { switch(prof_PcWidth) { case 2: if(*sp >= minhit) { printf(" %08x : %d\n", (int)sp + prof_PcDelta,*sp); linecount++; } sp++; break; case 4: if(*lp >= minhit) { printf(" %08x : %ld\n", (int)lp + prof_PcDelta,*lp); linecount++; } lp++; break; } if((more) && (linecount >= more)) { linecount = 0; if(More() == 0) { goto showdone; } } } } showdone: putchar('\n'); if(prof_BadSymCnt) { printf("%d out-of-range symbols\n",prof_BadSymCnt); } if(prof_TidOverflow) { printf("%d tid overflow attempts\n",prof_TidOverflow); } if(prof_PcOORCnt) { printf("%d pc out-of-range hits\n",prof_PcOORCnt); } printf("%d total profiler calls\n",prof_CallCnt); if(tfd >= 0) { tfsclose(tfd,0); } return; }