/*********************************************************************** * * umon_exception() & umon_swi_handler(): * These two functions are the default exception handlers used by the * low level code in vectors_arm.s. * The SWI handler is slightly different because it is passed the address * of the exception plus the SWI number. */ void umon_exception(ulong addr, ulong type) { ExceptionAddr = addr; ExceptionType = type; monrestart(EXCEPTION); }
void umon_swi_handler(ulong addr, ulong swinum) { ExceptionAddr = addr; ExceptionType = EXCTYPE_SWI; SwiNum = swinum; monrestart(EXCEPTION); }
/* The default (absolute minimum) action to be taken by this function * is to call monrestart(INITIALIZE). It would be better if there was * some target-specific function that would really cause the target * to reset... * UMON-TODO: revise it */ void target_reset(void) { flushDcache(0,0); disableDcache(); invalidateIcache(0,0); disableIcache(); monrestart(INITIALIZE); }
/* exception(): * This is the first 'C' function called out of a monitor-installed * exception handler. */ void exception(void) { /* ADD_CODE_HERE */ /* Populating these two values is target specific. * Refer to other target-specific examples for details. * In some cases, these values are extracted from registers * already put into the register cache by the lower-level * portion of the exception handler in vectors_template.s */ ExceptionAddr = 0; ExceptionType = 0; /* Allow the console uart fifo to empty... */ flushconsole(); monrestart(EXCEPTION); }
/* 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); }