static void cmd_run(int argc, char **argp, void *data) { cpu_instance_t *cpu = ((cmd_data_t *)data)->cpu; unsigned int i = 0; clock_t start = clock(); clock_t stop; cpu_set_flag(cpu, CPU_FLAGS_RUN); lprintf(LOG_VERBOSE, "Running...\n"); while (cpu->flags & CPU_FLAGS_RUN) { i++; cpu_step(cpu); if (i % 1000 == 0) { vr12_fade(); #ifdef HAVE_SDL sdl_update(); #endif } } stop = clock(); lprintf(LOG_NORMAL, "Halted at %.4o.\n", cpu->pc); lprintf(LOG_NORMAL, "Did %i instructions in %f seconds (%f i/s)\n", i, ((double)(stop - start))/((double)CLOCKS_PER_SEC), ((double)i * (double)CLOCKS_PER_SEC)/((double)(stop - start)) ); }
void *debug_cpu_thread (void *arg) { memset(&shoe.dbg, 0, sizeof(shoe.dbg)); shoe.dbg.mode = DEBUG_MODE_STOPPED; pthread_t server_thread_pid; pthread_create(&server_thread_pid, NULL, debug_server_thread, NULL); /* * The CPU only runs once the debugger is connected, and the * emulator has started */ pthread_mutex_lock(&shoe.cpu_thread_lock); while (!shoe.dbg.connected) usleep(1000); while (1) { if (shoe.dbg.mode == DEBUG_MODE_RUNNING) { if (!shoe.dbg.ignore_interrupts && (shoe.cpu_thread_notifications & 0xff)) { process_pending_interrupt(); } if (shoe.cpu_thread_notifications & SHOEBILL_STATE_STOPPED) { continue; } cpu_step(); } else if (shoe.dbg.mode == DEBUG_MODE_STOPPED) { //pthread_yield_np(); } else if (shoe.dbg.mode == DEBUG_MODE_STEP) { cpu_step(); shoe.dbg.mode = DEBUG_MODE_STOPPED; } } }
ARMSIM_STATUS as_execute(ARMSIM_CTX *ctx, size_t cycles, size_t *finished) { if(!ctx->entry_set){ return AS_BAD_ENTRY; } as_log(ctx, "Entering as_execute\n",0); int start_steps = get_steps(ctx); int current_steps = start_steps; if(cycles == 0){ run(ctx); } else { for (; current_steps - start_steps < cycles && current_steps == get_steps(ctx); ++current_steps) { cpu_step(ctx); } } (*finished) = (unsigned int)(get_steps(ctx) - start_steps); as_log(ctx, "Leaving as_execute\n",0); return AS_OK; }
void *_cpu_thread (void *arg) { pthread_mutex_lock(&shoe.cpu_thread_lock); while (1) { if (shoe.cpu_thread_notifications) { // If there's an interrupt pending if (shoe.cpu_thread_notifications & 0xff) { // process_pending_interrupt() may clear SHOEBILL_STATE_STOPPED process_pending_interrupt(); } if (shoe.cpu_thread_notifications & SHOEBILL_STATE_STOPPED) { continue; // FIXME: yield or block on a condition variable here } } cpu_step(); } }
static void cmd_step(int argc, char **argp, void *data) { cpu_step(((cmd_data_t *)data)->cpu); }
int main(int argc, char *argv[]) { cpu_t *cpu = cpu_create(); uint8_t opcode; FILE *file = NULL; char *dump_ram = NULL; char *dump_flash = NULL; char **buffer = NULL; int i; if(argc != 2 && argc != 4 && argc != 6) { puts("usage: fsim <in> [--dumpram|-r <ram filename>] [--dumpflash|-f <flash filename>]"); return EXIT_SUCCESS; } for (i = 2; i < argc; i++) { if (memcmp("--dumpram", argv[i], 9) == 0 || memcmp("-r", argv[i], 2) == 0) { buffer = &dump_ram; } else if (memcmp("--dumpflash", argv[i], 11) == 0 || memcmp("-f", argv[i], 2) == 0) { buffer = &dump_flash; } else if (buffer) { *buffer = argv[i]; buffer = NULL; } else { printf("unknown option \"%s\"\n", argv[i]); return EXIT_FAILURE; } } if (buffer) { puts("Not all options set"); return EXIT_FAILURE; } file = fopen(argv[1], "r"); if(!file) { printf("could not open file \"%s\"",argv[1]); return EXIT_FAILURE; } fread(cpu->flash, sizeof(cpu->flash), 1, file); fclose(file); file = NULL; printf("First 160 bytes of flash:"); for(i = 0;i < 160; i++) { if (i % 16 == 0) { printf("\n%08x:", i + 0x01000000); } if (i % 2 == 0) { printf(" "); } printf("%02x", cpu->flash[i]); } printf("\n\n"); while(!cpu->status) { opcode = cpu_step(cpu); } switch (cpu->status) { case 2: printf("Illegal opcode \"%02x\"\n", opcode); break; case 1: puts(""); puts("####################"); puts("# ## #"); puts("#### Halted CPU ####"); puts("# ## #"); puts("####################"); puts(""); break; default: printf("Unknown exit status %d", cpu->status); } puts("Register Dump:"); printf("A = %08x\n", cpu->a); printf("X = %08x\n", cpu->x); printf("PC = %08x\n", cpu->pc); printf("SP = %08x\n", cpu->sp); printf("z = %01d\n", cpu->z); printf("n = %01d\n", cpu->n); printf("i = %01d\n", cpu->i); printf("if = %02x\n", cpu->interrupt_flags); printf("iv = %08x\n", cpu->interrupt_vector); puts(""); dump_stack(cpu, 10); if (dump_flash) { file = fopen(dump_flash, "w"); if(!file) { printf("could not open flash file \"%s\"", dump_flash); } else { fwrite(cpu->flash, sizeof(cpu->flash), 1, file); fclose(file); printf("Dumped flash to \"%s\"\n", dump_flash); } } if (dump_ram) { file = fopen(dump_ram, "w"); if(!file) { printf("could not open ram file \"%s\"", dump_ram); } else { fwrite(cpu->ram, sizeof(cpu->ram), 1, file); fclose(file); printf("Dumped ram to \"%s\"\n", dump_ram); } } cpu = cpu_free(cpu); return 0; }