/* ======================================================================== emulate: This routine contains the main loop that handles active emulation and maintenance tasks. ======================================================================== */ void emulate(void) { unsigned int i,j; unsigned int v; int nxtmaint=1; int ins; starttime=msclock(); lock_remote(); while(!gExitApp) { /* Run appropriate emulation loop base on ReMem support */ if (gReMem) while (!gExitLoop) { /* Check for active debug monitor windows */ if (gDebugActive) { do_debug_stuff(); if (gExitLoop) break; } /* Instruction emulation contained in header file */ #undef NO_REMEM #include "cpu.h" #include "do_instruct.h" // Check if next inst is SIM if ((get_memory8(PC) == 0xF3) || ((IM & 0x2A) == 0x20) || ((IM & 0x4C) == 0x40)) { check_interrupts(); } // Check for return from interrupt if (gIntActive) { if (SP == gIntSP) gIntActive = FALSE; } if (gSingleStep) { if (!gIntActive) { gSingleStep = 0; } } /* Do maintenance tasks (Windows events, interrupts, etc.) */ #ifdef __APPLE__ if(!(--nxtmaint)) #else if(!(--nxtmaint & 0x3FF)) #endif { unlock_remote(); gOsDelay = nxtmaint == 0; throttle(cycle_delta); maint(); ser_poll(); check_interrupts(); if (gOsDelay) nxtmaint=gMaintCount; lock_remote(); } #if 0 exec_remem_instruction(); if (gExitLoop) break; #endif } if (!gReMem) { while (!gExitLoop) { /* Check for active debug monitor windows */ if (gDebugActive) { do_debug_stuff(); if (gExitLoop) break; } /* Instruction emulation contained in header file */ #define NO_REMEM #include "cpu.h" #include "do_instruct.h" // Check if next inst is SIM or RS-232 waiting if ((get_memory8(PC) == 0xF3) || ((IM & 0x2A) == 0x20) || ((IM & 0x4C) == 0x40)) { check_interrupts(); } // Check for return from interrupt if (gIntActive) { if (SP == gIntSP) gIntActive = FALSE; } if (gSingleStep) { if (!gIntActive) { gSingleStep = 0; } } /* Do maintenance tasks (Windows events, interrupts, etc.) */ #ifdef __APPLE__ if(!(--nxtmaint)) #else if(!(--nxtmaint & 0x3FF)) #endif { unlock_remote(); gOsDelay = nxtmaint == 0; throttle(cycle_delta); maint(); ser_poll(); check_interrupts(); if (gOsDelay) nxtmaint=gMaintCount; lock_remote(); } } } gExitLoop = 0; } unlock_remote(); }
int main(void) { unsigned image; init_omap3530beagle(); ser_putstr((char *)"\n\nQNX Neutrino Initial Program Loader for Texas Instruments OMAP3530 Beagle Board\n"); while (1) { image = QNX_LOAD_ADDRESS; ser_putstr((char *)"Commands:\n\n"); ser_putstr((char *)"Press 'D' for serial download, using the 'sendnto' utility\n"); ser_putstr((char *)"Press 'F' to boot an OS image from NAND flash\n"); ser_putstr((char *)"Press 'U' to Copy an OS image to NAND flash\n"); ser_putstr((char *)"Press 'I' to Update the IPL\n"); switch (ser_getchar()) { case 'D': case 'd': ser_putstr((char *)"Send image now...\n"); if (image_download_ser(image)) { ser_putstr((char *)"Download failed...\n"); continue; } else ser_putstr((char *)"Download OK...\n"); image = image_scan(image, image + 0x200); break; case 'F': case 'f': ser_putstr((char *)"reading from NAND flash ........\n"); if (read_image_from_nand(NAND_RESERVED_BLOCK_START, NAND_RESERVED_BLOCK_END, (unsigned)image) !=0 ) { ser_putstr((char *)"Read from NAND flash failed...\n"); continue; } image = image_scan(image, image+0x200); break; case 'U': case 'u': ser_putstr((char *)"send the ifs now...\n"); if (image_download_ser(image)) { ser_putstr((char *)"download failed...\n"); continue; }else{ ser_putstr((char *)"download OK...\n"); //read all left bytes while(ser_poll()){ ser_getchar(); } ser_putstr((char *)"Writing IFS image to NAND flash from block 4 ......\n"); if (upgrade_nand_flash(NAND_RESERVED_BLOCK_START, NAND_RESERVED_BLOCK_END, (unsigned)image) != 0 ) { ser_putstr((char *)"IFS image upgrading failed...\n"); } else { ser_putstr((char *)"Upgrade IFS OK...\n"); } continue; } break; case 'I': case 'i': ser_putstr((char *)"Send the IPL image, using the 'sendnto' utility...\n"); if (image_download_ser(image)) { ser_putstr((char *)"Download failed...\n"); continue; } else { ser_putstr((char *)"Download OK...\n"); ser_putstr((char *)"Writing IPL to NAND flash @ blk0 ......\n"); if (upgrade_IPL((unsigned)image) != 0 ) { ser_putstr((char *)"IPL upgrading failed...\n"); } else { ser_putstr((char *)"Update IPL OK\n"); } //read all left bytes while (ser_poll()) { ser_getchar(); } continue; } break; default: continue; } if (image != 0xffffffff) { //before we go, we need to unlock the top 128MB NAND // this will automatically lock all other blocks nand_unlock_blocks(1024, 2047); ser_putstr((char *)"Found image @ 0x"); ser_puthex(image); ser_putstr((char *)"\n"); image_setup(image); ser_putstr((char *)"Jumping to startup @ 0x"); ser_puthex(startup_hdr.startup_vaddr); ser_putstr((char *)"\n\n"); image_start(image); /* Never reach here */ return 0; }else{ ser_putstr((char *)"image_scan failed...\n"); } } return 0; }