/* Must be called with CPUS_LOCK held! */ int _papi_hwi_initialize_cpu( CpuInfo_t **dest, unsigned int cpu_num ) { APIDBG("Entry: dest: %p, *dest: %p, cpu_num: %d\n", dest, *dest, cpu_num); int retval; CpuInfo_t *cpu; int i; if ( ( cpu = allocate_cpu(cpu_num) ) == NULL ) { *dest = NULL; return PAPI_ENOMEM; } /* Call the component to fill in anything special. */ for ( i = 0; i < papi_num_components; i++ ) { if (_papi_hwd[i]->cmp_info.disabled) continue; retval = _papi_hwd[i]->init_thread( cpu->context[i] ); if ( retval ) { free_cpu( &cpu ); *dest = NULL; return retval; } } insert_cpu( cpu ); *dest = cpu; return PAPI_OK; }
int _papi_hwi_initialize_cpu( CpuInfo_t ** dest, unsigned int cpu_num ) { THRDBG("Entry: dest: %p, *dest: %p, cpu_num: %d\n", dest, *dest, cpu_num); int retval; CpuInfo_t *cpu; int i; if ( ( cpu = allocate_cpu(cpu_num) ) == NULL ) { *dest = NULL; return ( PAPI_ENOMEM ); } /* Call the substrate to fill in anything special. */ for ( i = 0; i < papi_num_components; i++ ) { retval = _papi_hwd[i]->init( cpu->context[i] ); if ( retval ) { free_cpu( &cpu ); *dest = NULL; return ( retval ); } } insert_cpu( cpu ); *dest = cpu; return ( PAPI_OK ); }
int main(int argc, char *argv[]) { int ch; cpu_t *cpu = init_cpu(); char *sys_file; while ((ch = getopt(argc, argv, "df:")) != EOF) { switch (ch) { case 'd': cpu->debug = true; break; case 'f': sys_file = strdup(optarg); break; } } argc -= optind; argv += optind; init_disk(cpu->port0, "/tmp/disk0"); load_cpu(cpu, sys_file); while (true) run_cpu(cpu); free_cpu(cpu); return 0; }
int main(int argc,char *argv[]){ int exitcode = 0; t_state state, *s=&state; /* Parse command line and pass any relevant arguments to CPU record */ parse_cmd_line(argc,argv, &cmd_line_args); fprintf(stderr,"ION (MIPS32 clone) core emulator (" __DATE__ ")\n\n"); if(!init_cpu(s, &cmd_line_args)){ fprintf(stderr,"Trouble allocating memory, quitting!\n"); exit(71); }; /* Read binary object files into memory*/ if(!read_binary_files(s, &cmd_line_args)){ exit(66); } fprintf(stderr,"\n\n"); /* Open the CPU console output file if not stdout. */ if (cmd_line_args.conout_filename!=NULL) { cpuconout = fopen(cmd_line_args.conout_filename, "w"); if (cpuconout==NULL){ fprintf(stderr,"Trouble opening console log file '%s', quitting.\n", cmd_line_args.conout_filename); exitcode = 2; goto main_quit; } } else { cpuconout = stdout; } init_trace_buffer(s, &cmd_line_args); /* NOTE: Original mlite supported loading little-endian code, which this program doesn't. The endianess-conversion code has been removed. */ /* Simulate a CPU reset */ reset_cpu(s); /* Simulate the work of the uClinux bootloader */ if(cmd_line_args.memory_map == MAP_UCLINUX){ /* FIXME this 'bootloader' is a stub, flesh it out */ s->pc = 0x80002400; } /* Enter debug command interface; will only exit clean with user command */ do_debug(s, cmd_line_args.no_prompt); main_quit: /* Close and deallocate everything and quit */ close_trace_buffer(s); free_cpu(s); if (cmd_line_args.conout_filename!=NULL && cpuconout!=NULL) fclose(cpuconout); exit(0); }
int _papi_hwi_shutdown_cpu( CpuInfo_t *cpu ) { APIDBG("Entry: cpu: %p, cpu_num: %d\n", cpu, cpu->cpu_num); free_cpu( &cpu ); return PAPI_OK; }
int main(int argc, char * argv[]) { cpu* local_cpu = create_cpu(); // Load program: load_program(local_cpu->program, "C:\\Users\\Daniel\\Documents\\Projects\\snowbird\\programs\\div"); // Run Program: run_cpu(local_cpu); free_cpu(local_cpu); }
int _papi_hwi_shutdown_cpu( CpuInfo_t * cpu ) { THRDBG("Entry: cpu: %p, cpu_num: %d\n", cpu, cpu->cpu_num); int retval = PAPI_OK; int i, failure = 0; remove_cpu( cpu ); THRDBG( "Shutting down cpu %d at %p\n", cpu->cpu_num, cpu ); for ( i = 0; i < papi_num_components; i++ ) { retval = _papi_hwd[i]->shutdown( cpu->context[i] ); if ( retval != PAPI_OK ) failure = retval; } free_cpu( &cpu ); return ( failure ); }
// sudo apt-get install libncurses5-dev // http://stackoverflow.com/questions/4025891/create-a-function-to-check-for-key-press-in-unix-using-ncurses // https://viget.com/extend/game-programming-in-c-with-the-ncurses-library int main(int argc, char **argv) { char *debug_filename = NULL; char *input_filename = NULL; int c; opterr = 0; while ((c = getopt(argc, argv, "d:p:")) != -1) { switch (c) { case 'd': debug_filename = optarg; break; case 'p': input_filename = optarg; break; case '?': fprintf(stderr, "Unknown option: %c\n", optopt); print_usage(); return 1; default: print_usage(); return 1; } } if (optind < argc || input_filename == NULL || (ends_with(input_filename, required_input_ext, 0) != 1)) { print_usage(); return 1; } FILE *input_file = fopen(input_filename, "rb"); if (!input_file) { fprintf(stderr, "Fatal error when opening input file: '%s'\n", argv[1]); exit(1); } FILE *debug_file = NULL; if (debug_filename) { debug_file = fopen(debug_filename, "w"); } chip_8_cpu cpu = initialize_cpu(); initialize_memory(cpu, input_file); fclose(input_file); execute_loop(cpu, debug_file); free_cpu(cpu); return EXIT_SUCCESS; }
/** Read binary code and data files */ static int read_binary_files(t_state *s, t_args *args){ FILE *in; uint8_t *target; uint32_t bytes=0, i, files_read=0; /* read map file if requested */ if(args->map_filename!=NULL){ if(read_map_file(args->map_filename, &map_info)<0){ printf("Trouble reading map file '%s', quitting!\n", args->map_filename); return 0; } printf("Read %d functions from the map file; call trace enabled.\n\n", map_info.num_functions); } /* read object code binaries */ for(i=0;i<NUM_MEM_BLOCKS;i++){ bytes = 0; if(args->bin_filename[i]!=NULL){ in = fopen(args->bin_filename[i], "rb"); if(in == NULL){ free_cpu(s); printf("Can't open file %s, quitting!\n",args->bin_filename[i]); return(0); } /* FIXME load offset 0x2000 for linux kernel hardcoded! */ //bytes = fread((s->blocks[i].mem + 0x2000), 1, s->blocks[i].size, in); target = (uint8_t *)(s->blocks[i].mem + args->offset[i]); while(!feof(in) && ((bytes+1024+args->offset[i]) < (s->blocks[i].size))){ bytes += fread(&(target[bytes]), 1, 1024, in); if(errno!=0){ printf("ERROR: file load failed with code %d ('%s')\n", errno, strerror(errno)); free_cpu(s); return 0; } } fclose(in); /* Now reverse the endianness of the data we just read, if it's necessary. */ /* FIXME handle little-endian stuff (?) */ //reverse_endianess(target, bytes); files_read++; } fprintf(stderr,"%-16s [size= %6dKB, start= 0x%08x] loaded %d bytes.\n", s->blocks[i].area_name, s->blocks[i].size/1024, s->blocks[i].start, bytes); } if(!files_read){ free_cpu(s); fprintf(stderr,"No binary object files read, quitting\n"); return 0; } return files_read; }
void shutdown_cpu(chip_8_cpu cpu, int error_code) { free_cpu(cpu); endwin(); exit(error_code); }