Exemple #1
0
void mips_dyncom_run(cpu_t *cpu)
{
	mips_core_t *core = (mips_core_t*)cpu->cpu_data;
	addr_t phys_pc = core->pc;

	int rc = cpu_run(cpu);
	switch (rc) {
		case JIT_RETURN_NOERR:
			break;
		case JIT_RETURN_SINGLESTEP:
		case JIT_RETURN_FUNCNOTFOUND:
			cpu_tag(cpu, core->gpr[15]);
			cpu->dyncom_engine->cur_tagging_pos ++;
			cpu_translate(cpu, core->gpr[15]);

		/*
		 *	IF singlestep, we run it here, otherwise, break.
		 */
			if(cpu->dyncom_engine->flags_debug & CPU_DEBUG_SINGLESTEP)
			{
				rc = cpu_run(cpu);
				if(rc != JIT_RETURN_TRAP)
					break;
			}
			else
				break;
		case JIT_RETURN_TRAP:
			break;

		default:
			fprintf(stderr, "unknown return code:%d\n", rc);
			skyeye_exit(-1);
	}
	return;
}
Exemple #2
0
int main(int argc, char **argv)
{
    if (argc != 2) {
        printf("oops\n");
        return 1;
    }

    char *filename = argv[1];

    struct rom test_rom;
    struct cpu_6502 cpu;
    struct ppu ppu;

    cpu_setup(&cpu);
    ppu_setup(&ppu);
    cpu.ppu = &ppu;

    load_rom(&test_rom, filename);
    printf("Prog size %x\n", test_rom.prg_rom_data);
    cpu.rom_prg = test_rom.prg_rom_data;
    ppu.rom_chr = test_rom.chr_rom_data;
    printf("Prog size %x\n", cpu.rom_prg);

    cpu_reset(&cpu);
    cpu_run(&cpu);

    return 0;
}
Exemple #3
0
void arm_dyncom_run(cpu_t* cpu){
	arm_core_t* core = (arm_core_t*)cpu->cpu_data;
	addr_t phys_pc = core->Reg[15];
#if 0
	if(mmu_read_(core, core->pc, PPC_MMU_CODE, &phys_pc) != PPC_MMU_OK){
		/* we donot allow mmu exception in tagging state */
		fprintf(stderr, "In %s, can not translate the pc 0x%x\n", __FUNCTION__, core->pc);
		exit(-1);
	}
#endif

#if 0
	cpu->dyncom_engine->code_start = phys_pc;
        cpu->dyncom_engine->code_end = get_end_of_page(phys_pc);
        cpu->dyncom_engine->code_entry = phys_pc;
#endif

	int rc = cpu_run(cpu);
	switch (rc) {
                case JIT_RETURN_NOERR: /* JIT code wants us to end execution */
                        break;
                case JIT_RETURN_SINGLESTEP:
                case JIT_RETURN_FUNCNOTFOUND:
                        cpu_tag(cpu, core->Reg[15]);
                        cpu->dyncom_engine->functions = 0;
                        cpu_translate(cpu);
		 /*
                  *If singlestep,we run it here,otherwise,break.
                  */
                        if (cpu->dyncom_engine->flags_debug & CPU_DEBUG_SINGLESTEP){
                                rc = cpu_run(cpu);
                                if(rc != JIT_RETURN_TRAP)
                                        break;
                        }
                        else
                                break;
		case JIT_RETURN_TRAP:
			break;
		default:
                        fprintf(stderr, "unknown return code: %d\n", rc);
			skyeye_exit(-1);
        }// switch (rc)
	return;
}
Exemple #4
0
int main(void)
{
	creat_main_memory();
    creat_cache_memory();

	fill_instruction_for_cpu();
	cpu_run();

    return 0;
}
Exemple #5
0
int main() {
	try {
		int num_cpus = 1;
		vm_new(num_cpus);
		int cpu = 0;
		Registers* regs = cpu_map_registers(cpu);
		cpu_run(cpu);
	}
	catch (std::exception& e) {
		printf("error: %s\n", e.what());
	}
	vm_cleanup();
	return 0;
}
Exemple #6
0
int main (int argc, char *const argv[])
{
    parser_result_t *config;
    
    config = try_input(argc, argv);

    run_flags = config->flags;

    memory_load(config);

    cpu_run(config->ninst, config->pc);

    cpu_status();
    if (run_flags & FLAG_WATCHMEM)
        show_interval_memory(config->watch_begin, config->watch_end); 
    return 0;
}
Exemple #7
0
void cpu_test_store(context_t *ctx, uint8_t opcode, uint8_t value)
{
    cpu_setup_test(ctx, opcode);
    
    uint8_t* src = cpu_get_operand(ctx, opcode);
    uint8_t* dst = cpu_get_dest(ctx, opcode);
    
    assert(src != NULL);
    assert(dst != NULL);

    *src = value;

    cpu_run(ctx);

    fail_unless(*dst == *src && *dst == value,
        "Opcode 0x%02X: failed with src = %p, dst = %p", opcode, *src, *dst);
}
Exemple #8
0
void cli_cmd_stepover(size_t argc,const sASTNode **argv) {
	if(argc != 0 && argc != 1)
		cmds_throwEx(NULL);

	octa count = 1;
	if(argc == 1) {
		sCmdArg first = cmds_evalArg(argv[0],ARGVAL_INT,0,NULL);
		count = first.d.integer;
	}

	if(cpu_isHalted())
		cmds_throwEx("CPU is halted. Set the PC or reset the machine!\n");
	ev_register(EV_AFTER_EXEC,afterExec);
	while(count-- > 0) {
		level = 0;
		cpu_run();
	}
	ev_unregister(EV_AFTER_EXEC,afterExec);
}
Exemple #9
0
/**
* @brief  Main routine for MSC class application
* @param  None
* @retval int
*/
int main(void)
{
	NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0xC000);//初始化启动项
	gpio_init();//初始化所有定义的gpio寄存器
	cpu_run();
	flash_stop();
//	rs485_recv();//使能485接受数据
	FLASH_ON();
	remote_init();
	LOOP_ON();//使能环流
//	uart_init(9600);//设置波特率为9600  串口初始化
	delay_ms(1);//定时器
	SPI_Flash_Init();//初始化spi flash外围驱动
	get_cfg_from_flash();//得到配置信息 (获取cfg文件的配置)
	get_line_from_flash();	 	
	message_state |= MESSAGE_LINE_NEW;
	message_state |= MESSAGE_LEFT_NEW;
	message_state |= MESSAGE_RIGHT_NEW;
	message_state |= MESSAGE_BRAKE_NEW;
	alloc_memory(); //初始化缓存
	
	wwdg_init(0x7F, 0x5F, WWDG_Prescaler_8); //计数器值为7f,窗口寄存器为5f,分频数为8 (使用窗口看门狗的原因是他可以被中断)
	while (1)
	{
		if(uart_get_flag)
		{
			uart_get_flag = 0;
			data_process();
			LED_OK = 1;
		}
		get_disp_state();		//左转右转还有刹车的判断报站;
		if(bflag)
		{
			LED_DispString(1, 1, disp_buff);    //固定显示
		}
		else
		{
			
			
			LED_ScrollDispHZ(1, 1, disp_buff);//滚动显示
		}
	}
}
Exemple #10
0
int main(int argc, char **argv)
{

	if(argc < 2)
	{
		fprintf(stderr, "Usage: %s [mem file]\n", argv[0]);
		exit(1);
	}

	cpu_t c = {0};
	c.mem = malloc(MEMSZ);

	int f = open(argv[1], O_RDONLY);
	if(f == -1)
	{
		fprintf(stderr, "Failed to open mem file!\n");
		exit(1);
	}

	read(f, c.mem, MEMSZ);
	close(f);

	cpu_run(&c);
}
Exemple #11
0
int
main(int ac, char **av, char **ep)
{
	int rc;
	cpu_t *cpu;
	xec_guest_info_t guest_info;
	xec_mem_if_t *mem_if;
	xec_monitor_t *monitor;
	xec_us_syscall_if_t *us_syscall;
	m88k_uintptr_t stack_top;
	nix_env_t *env;
	bool debugging = false;

	aspace_lock();

	if (ac < 2) {
		fprintf(stderr, "usage: %s <executable> [args...]\n", *av);
		exit(EXIT_FAILURE);
	}

	/* Initialize xec, nix and loader. */
	xec_init();
	obsd41_init();
	loader_init();

	/* Create CPU */
	cpu = cpu_new(CPU_ARCH_M88K, CPU_FLAG_ENDIAN_BIG, 0);
	if (cpu == NULL) {
		fprintf(stderr, "error: failed initializing M88K architecture.\n");
		exit(EXIT_FAILURE);
	}

	/* Create XEC bridge mem-if */
	mem_if = run88_new_mem_if();

	/* Create the XEC US Syscall */
	us_syscall = obsd41_us_syscall_create(mem_if);
	if (us_syscall == NULL) {
		fprintf(stderr, "error: failed creating xec userspace syscall.\n");
		exit(EXIT_FAILURE);
	}

	/* Create NIX env */
	env = nix_env_create(mem_if);
	if (env == NULL) {
		fprintf(stderr, "error: failed creating nix environment.\n");
		exit(EXIT_FAILURE);
	}

	/* Load the executable */
	rc = loader_load(mem_if, av[1]);
	if (rc != LOADER_SUCCESS) {
		fprintf(stderr, "error: cannot load executable '%s', error=%d.\n", av[1], rc);
		exit(EXIT_FAILURE);
	}

	/* Setup arguments */
	g_uframe_log = xec_log_register("uframe");

#ifndef DEBUGGER
	xec_log_disable("nix");
	xec_log_disable("openbsd41");
	xec_log_disable("uframe");
	xec_log_disable(NULL);
#endif

	openbsd_m88k_setup_uframe(cpu, mem_if, ac - 1, av + 1, ep, &stack_top);

	/* Setup the CPU */
	cpu_set_flags_codegen(cpu, CPU_CODEGEN_OPTIMIZE|CPU_CODEGEN_TAG_LIMIT);
	cpu_set_flags_debug(cpu, CPU_DEBUG_NONE);
	//cpu_set_flags_debug(cpu, CPU_DEBUG_SINGLESTEP_BB);
	cpu_set_flags_hint(cpu, CPU_HINT_TRAP_RETURNS_TWICE);
	cpu_set_ram(cpu, RAM);

	/* Create XEC bridge monitor */
	guest_info.name = cpu->info.name;
	guest_info.endian = (cpu->info.common_flags & CPU_FLAG_ENDIAN_MASK)
		== CPU_FLAG_ENDIAN_BIG ? XEC_ENDIAN_BIG : XEC_ENDIAN_LITTLE;
	guest_info.byte_size = cpu->info.byte_size;
	guest_info.word_size = cpu->info.word_size;
	guest_info.page_size = cpu->info.default_page_size;
	monitor = xec_monitor_create(&guest_info, mem_if, cpu->rf.grf, NULL);
	if (monitor == NULL) {
		fprintf(stderr, "error: failed createc xec monitor.\n");
		exit(EXIT_FAILURE);
	}

	/* Setup registers for execution */
	PC = g_ahdr.entry;

	R[31] = stack_top; // Stack Pointer
	R[1]  = -1;        // Return Address

	cpu->code_start = g_ahdr.tstart;
	cpu->code_end   = g_ahdr.tstart + g_ahdr.tsize;
	cpu->code_entry = g_ahdr.entry;

	cpu_tag(cpu, cpu->code_entry);

	dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);

#ifdef DEBUGGER
	debugging = true;
#else
	fprintf(stderr, "Translating..."); fflush(stderr);
	cpu_translate(cpu);
	fprintf(stderr, "done.\n");
#endif

	aspace_unlock();

	for (;;) {
		if (debugging) {
			rc = cpu_debugger(cpu, debug_function);
			if (rc < 0) {
				debugging = false;
				continue;
			}
		} else {
			rc = cpu_run(cpu, debug_function);
		}

		switch (rc) {
			case JIT_RETURN_NOERR: /* JIT code wants us to end execution */
				break;

			case JIT_RETURN_FUNCNOTFOUND:
#ifndef DEBUGGER
				fprintf(stderr, "%s: error: 0x%llX not found!\n", __func__, (unsigned long long)PC);
				fprintf(stderr, "Translating..."); fflush(stderr);
				cpu_tag(cpu, PC);
				cpu_flush(cpu);
				cpu_translate(cpu);
				fprintf(stderr, "done.\n");
#else
				dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);

				if (PC == (uint32_t)(-1U))
					goto exit_loop;

				// bad :(
				fprintf(stderr, "%s: warning: 0x%llX not found!\n", __func__, (unsigned long long)PC);
				fprintf(stderr, "PC: ");
				for (size_t i = 0; i < 16; i++)
					fprintf(stderr, "%02X ", RAM[PC+i]);
				fprintf(stderr, "\n");
				exit(EXIT_FAILURE);
#endif
				break;

			case JIT_RETURN_TRAP:
//				printf("TRAP %u / %u!\n", TRAPNO, R[13]);
				if (TRAPNO == 0x80 && R[13] == 1) // exit
					goto exit_loop;

//				printf("BEFORE:\n");
//				dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);
				xec_us_syscall_dispatch(us_syscall, monitor);
//				printf("AFTER:\n");
//				dump_state(RAM, (m88k_grf_t*)cpu->rf.grf);
				break;

			case JIT_RETURN_SINGLESTEP:
				break;

			default:
				fprintf(stderr, "unknown return code: %d\n", rc);
				goto exit_loop;
		}

		if (cpu->flags_debug & (CPU_DEBUG_SINGLESTEP | CPU_DEBUG_SINGLESTEP_BB))
			cpu_flush(cpu);
	}

exit_loop:
	cpu_free(cpu);

	fprintf(stderr, ">> run88 success\n");
	exit(EXIT_SUCCESS);
}
Exemple #12
0
int main(int argc,char **argv) {
	if(sizeof(byte) != 1 || sizeof(wyde) != 2 || sizeof(tetra) != 4 || sizeof(octa) != 8)
		error("Type-sizes are wrong. Please change the typedefs in common.h for your platform!");

	bool interactive = false;
	for(int i = 1; i < argc; i++) {
		if(strcmp(argv[i],"-i") == 0)
			interactive = true;
		else if(strncmp(argv[i],"--postcmds=",sizeof("--postcmds=") - 1) == 0)
			postCmds = argv[i] + sizeof("--postcmds=") - 1;
		else if(strncmp(argv[i],"--script=",sizeof("--script=") - 1) == 0) {
			script = argv[i] + sizeof("--script=") - 1;
			interactive = true;
		}
		else if(strncmp(argv[i],"--start=",sizeof("--start=") - 1) == 0) {
			octa cpc = mstrtoo(argv[i] + sizeof("--start=") - 1,NULL,0);
			cfg_setStartAddr(cpc);
		}
		else if(strcmp(argv[i],"--user") == 0) {
			cfg_setUserMode(true);
			cfg_setStartAddr(0x1000);
			cfg_setRAMSize((octa)32 * 1024 * 1024 * 1024);
		}
		else if(strcmp(argv[i],"--test") == 0)
			cfg_setTestMode(true);
		else if(strcmp(argv[i],"-t") == 0) {
			if(i >= argc - 1)
				error(usage,argv[0]);
			cfg_setTermCount(mstrtoo(argv[i + 1],NULL,0));
			i++;
		}
		else if(strcmp(argv[i],"-l") == 0) {
			if(i >= argc - 1)
				error(usage,argv[0]);
			cfg_setProgram(argv[i + 1]);
			i++;
		}
		else if(strcmp(argv[i],"-r") == 0) {
			if(i >= argc - 1)
				error(usage,argv[0]);
			cfg_setROM(argv[i + 1]);
			cfg_setStartAddr(MSB(64) | ROM_START_ADDR);
			i++;
		}
		else if(strcmp(argv[i],"-d") == 0) {
			if(i >= argc - 1)
				error(usage,argv[0]);
			cfg_setDiskImage(argv[i + 1]);
			i++;
		}
		else if(strcmp(argv[i],"-o") == 0) {
			if(i >= argc - 1)
				error(usage,argv[0]);
			cfg_setOutputFile(argv[i + 1]);
			i++;
		}
		else if(strcmp(argv[i],"-m") == 0) {
			if(i >= argc - 1)
				error(usage,argv[0]);
			cfg_setRAMSize(mstrtoo(argv[i + 1],NULL,0) * 1024 * 1024);
			i++;
		}
		else if(strcmp(argv[i],"-c") == 0)
			cfg_setUseDspKbd(true);
		else if(strcmp(argv[i],"-p") == 0) {
			if(i >= argc - 1)
				error(usage,argv[0]);
			gdbport = atoi(argv[i + 1]);
			i++;
		}
		else if(strcmp(argv[i],"-b") == 0)
			cfg_setUseBacktracing(true);
		else if(strcmp(argv[i],"-s") == 0) {
			const char *mapNames[MAX_MAPS];
			for(int x = 0; x < MAX_MAPS; x++)
				mapNames[x] = NULL;
			if(i == argc - 1 || mapNames[0] != NULL)
				error(usage,argv[0]);
			for(int x = 0; x < MAX_MAPS && i < argc - 1; x++) {
				mapNames[x] = argv[++i];
				if(mapNames[x][0] == '-') {
					mapNames[x] = NULL;
					i--;
					break;
				}
			}
			cfg_setMaps(mapNames);
		}
		else
			error(usage,argv[0]);
	}

	// in non-interactive mode, either a program or ROM is required
	if(!interactive && cfg_getProgram() == NULL && cfg_getROM() == NULL)
		error(usage,argv[0]);

	// catch exceptions that are not catched by anybody else. it may occur an exception during
	// initialization for example.
	jmp_buf env;
	int ex = setjmp(env);
	if(ex != EX_NONE)
		mprintf("Exception: %s\n",ex_toString(ex,ex_getBits()));
	else {
		ex_push(&env);
		sim_init();
		if(gdbport != -1)
			gdbstub_init(gdbport);
		else if(interactive) {
			cons_init();
			if(script)
				cons_exec(script,true);
			cons_start();
			cons_shutdown();
		}
		else {
			cpu_run();
			if(postCmds)
				postcmds_perform(postCmds);
		}
	}
	ex_pop();
	sim_shutdown();

	// ignore errors raised by the gcov stuff
	fclose(stderr);
	return EXIT_SUCCESS;
}
Exemple #13
0
void computer_start (computer_t *computer)
{
	cpu_run (computer->cpu);
}
Exemple #14
0
void
emu_run(emu_t *emu)
{
    cpu_run(emu->cpu, 0x8000);
}
Exemple #15
0
/***************************************************************************

  Run the emulation. Start the various subsystems and the CPU emulation.
  Returns non zero in case of error.

***************************************************************************/
int run_machine(const char *gamename)
{
	int res = 1;


	if (vh_open() == 0)
	{
		if (*drv->vh_start == 0 || (*drv->vh_start)() == 0)	/* start the video hardware */
		{
			if (*drv->sh_start == 0 || (*drv->sh_start)() == 0)	/* start the audio hardware */
			{
				FILE *f;
				char name[100];
				int i,incount, keycount;


				incount = 0;
				while (gamedrv->input_ports[incount].default_value != -1) incount++;

				/* read dipswitch settings from disk */
				sprintf(name,"%s/%s.dsw",gamename,gamename);
				if ((f = fopen(name,"rb")) != 0)
				{
					/* use name as temporary buffer */
					if (fread(name,1,incount,f) == incount)
					{
						for (i = 0;i < incount;i++)
							gamedrv->input_ports[i].default_value = ((unsigned char)name[i]);
					}
					fclose(f);
				}

				keycount = 0;
				while (gamedrv->keysettings[keycount].num != -1) keycount++;

				/* read dipswitch settings from disk */
				sprintf(name,"%s/%s.key",gamename,gamename);
				if ((f = fopen(name,"rb")) != 0)
				{
					/* use name as temporary buffer */
					if (fread(name,1,keycount,f) == keycount)
					{
						for (i = 0;i < keycount;i++)
							gamedrv->input_ports[ gamedrv->keysettings[i].num ].keyboard[ gamedrv->keysettings[i].mask ] = ((unsigned char)name[i]);
					}
					fclose(f);
				}

				/* we have to load the hi scores, but this will be done while */
				/* the game is running */
				hiscoreloaded = 0;
				sprintf(hiscorename,"%s/%s.hi",gamename,gamename);

				cpu_run();	/* run the emulation! */

				if (*drv->sh_stop) (*drv->sh_stop)();
				if (*drv->vh_stop) (*drv->vh_stop)();

				/* write hi scores to disk */
				if (hiscoreloaded != 0 && *gamedrv->hiscore_save)
					(*gamedrv->hiscore_save)(hiscorename);

				/* write dipswitch settings to disk */
				sprintf(name,"%s/%s.dsw",gamename,gamename);
				if ((f = fopen(name,"wb")) != 0)
				{
					/* use name as temporary buffer */
					for (i = 0;i < incount;i++)
						name[i] = gamedrv->input_ports[i].default_value;

					fwrite(name,1,incount,f);
					fclose(f);
				}

				/* write key settings to disk */
				sprintf(name,"%s/%s.key",gamename,gamename);
				if ((f = fopen(name,"wb")) != 0)
				{
					/* use name as temporary buffer */
					for (i = 0;i < keycount;i++)
						name[i] = gamedrv->input_ports[ gamedrv->keysettings[i].num ].keyboard[ gamedrv->keysettings[i].mask ];

					fwrite(name,1,keycount,f);
					fclose(f);
				}

				res = 0;
			}
			else printf("Unable to start audio emulation\n");
		}
		else printf("Unable to start video emulation\n");

		vh_close();
	}
	else printf("Unable to initialize display\n");

	return res;
}
Exemple #16
0
/***************************************************************************

  Run the emulation. Start the various subsystems and the CPU emulation.
  Returns non zero in case of error.

***************************************************************************/
int run_machine(void)
{
	int res = 1;


	if (vh_open() == 0)
	{
		tilemap_init();
		sprite_init();
		gfxobj_init();
		if (drv->vh_start == 0 || (*drv->vh_start)() == 0)      /* start the video hardware */
		{
			if (sound_start() == 0) /* start the audio hardware */
			{
				int	region;

				real_scrbitmap = artwork_overlay ? overlay_real_scrbitmap : Machine->scrbitmap;

				/* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */
				for (region = 0; region < MAX_MEMORY_REGIONS; region++)
				{
					if (Machine->memory_region_type[region] & REGIONFLAG_DISPOSE)
					{
						int i;

						/* invalidate contents to avoid subtle bugs */
						for (i = 0;i < memory_region_length(region);i++)
							memory_region(region)[i] = rand();
						free(Machine->memory_region[region]);
						Machine->memory_region[region] = 0;
					}
				}

				if (settingsloaded == 0)
				{
					/* if there is no saved config, it must be first time we run this game, */
					/* so show the disclaimer. */
//sq					if (showcopyright(real_scrbitmap)) goto userquit;
				}

//sq				if (showgamewarnings(real_scrbitmap) == 0)  /* show info about incorrect behaviour (wrong colors etc.) */
				{
					/* shut down the leds (work around Allegro hanging bug in the DOS port) */
					osd_led_w(0,1);
					osd_led_w(1,1);
					osd_led_w(2,1);
					osd_led_w(3,1);
					osd_led_w(0,0);
					osd_led_w(1,0);
					osd_led_w(2,0);
					osd_led_w(3,0);

					init_user_interface();

					/* disable cheat if no roms */
					if (!gamedrv->rom) options.cheat = 0;

					if (options.cheat) InitCheat();

					if (drv->nvram_handler)
					{
						void *f;

						f = osd_fopen(Machine->gamedrv->name,0,OSD_FILETYPE_NVRAM,0);
						(*drv->nvram_handler)(f,0);
						if (f) osd_fclose(f);
					}

					cpu_run();      /* run the emulation! */

					if (drv->nvram_handler)
					{
						void *f;

						if ((f = osd_fopen(Machine->gamedrv->name,0,OSD_FILETYPE_NVRAM,1)) != 0)
						{
							(*drv->nvram_handler)(f,1);
							osd_fclose(f);
						}
					}

					if (options.cheat) StopCheat();

					/* save input ports settings */
					save_input_port_settings();
				}

userquit:
				/* the following MUST be done after hiscore_save() otherwise */
				/* some 68000 games will not work */
				sound_stop();
				if (drv->vh_stop) (*drv->vh_stop)();
				overlay_free();
				backdrop_free();

				res = 0;
			}
			else if (!bailing)
			{
				bailing = 1;
				printf("Unable to start audio emulation\n");
			}
		}
		else if (!bailing)
		{
			bailing = 1;
			printf("Unable to start video emulation\n");
		}

		gfxobj_close();
		sprite_close();
		tilemap_close();
		vh_close();
	}
	else if (!bailing)
	{
		bailing = 1;
		printf("Unable to start video emulation\n");
	}

	return res;
}
Exemple #17
0
int main(int argc, char **argv)
{
	/* Initial information */
	fprintf(stderr, "\n");
	fprintf(stderr, "; Multi2Sim %s - A Simulation Framework for CPU-GPU Heterogeneous Computing\n",
		VERSION);
	fprintf(stderr, "; Please use command 'm2s --help' for a list of command-line options.\n");
	fprintf(stderr, "; Last compilation: %s %s\n", __DATE__, __TIME__);
	fprintf(stderr, "\n");

	/* Read command line */
	sim_read_command_line(&argc, argv);

	/* CPU disassembler tool */
	if (*cpu_disasm_file_name)
		ke_disasm(cpu_disasm_file_name);

	/* GPU disassembler tool */
	if (*gpu_disasm_file_name)
		gk_disasm(gpu_disasm_file_name);

	/* OpenGL disassembler tool */
	if (*opengl_disasm_file_name)
		gl_disasm(opengl_disasm_file_name, opengl_disasm_shader_index);	

	/* GPU visualization tool */
	if (*gpu_visual_file_name)
		vgpu_run(gpu_visual_file_name);
	
	/* Memory hierarchy visualization tool */
	if (*visual_file_name)
		vmem_run(visual_file_name);

	/* Network simulation tool */
	if (*net_sim_network_name)
		net_sim(net_debug_file_name);

	/* Debug */
	debug_init();
	isa_inst_debug_category = debug_new_category(isa_inst_debug_file_name);
	isa_call_debug_category = debug_new_category(isa_call_debug_file_name);
	elf_debug_category = debug_new_category(elf_debug_file_name);
	net_debug_category = debug_new_category(net_debug_file_name);
	ld_debug_category = debug_new_category(loader_debug_file_name);
	sys_debug_category = debug_new_category(syscall_debug_file_name);
	ctx_debug_category = debug_new_category(ctx_debug_file_name);
	mem_debug_category = debug_new_category(mem_debug_file_name);
	opencl_debug_category = debug_new_category(opencl_debug_file_name);
	gpu_isa_debug_category = debug_new_category(gpu_isa_debug_file_name);
	gpu_stack_debug_category = debug_new_category(gpu_stack_debug_file_name);  /* GPU-REL */
	gpu_faults_debug_category = debug_new_category(gpu_faults_debug_file_name);  /* GPU-REL */
	gpu_pipeline_debug_category = debug_new_category(gpu_pipeline_debug_file_name);
	error_debug_category = debug_new_category(error_debug_file_name);
	esim_debug_init(esim_debug_file_name);

	/* Trace */
	trace_init(trace_file_name);
	mem_trace_category = trace_new_category();

	/* Initialization for functional simulation */
	esim_init();
	ke_init();
	net_init();

	/* Initialization for detailed simulation */
	if (cpu_sim_kind == cpu_sim_detailed)
		cpu_init();
	if (gpu_sim_kind == gpu_sim_detailed)
		gpu_init();

	/* Memory hierarchy initialization, done after we initialized CPU cores
	 * and GPU compute units. */
	mem_system_init();

	/* Load programs */
	cpu_load_progs(argc, argv, ctxconfig_file_name);

	/* Simulation loop */
	if (ke->running_list_head)
	{
		if (cpu_sim_kind == cpu_sim_detailed)
			cpu_run();
		else
			ke_run();
	}

	/* Flush event-driven simulation */
	esim_process_all_events(0);

	/* Dump statistics summary */
	sim_stats_summary();

	/* Finalization of memory system */
	mem_system_done();

	/* Finalization of detailed CPU simulation */
	if (cpu_sim_kind == cpu_sim_detailed)
	{
		esim_debug_done();
		cpu_done();
	}

	/* Finalization of detailed GPU simulation */
	if (gpu_sim_kind == gpu_sim_detailed)
		gpu_done();

	/* Finalization */
	net_done();
	esim_done();
	trace_done();
	ke_done();
	debug_done();
	mhandle_done();

	/* End */
	return 0;
}
Exemple #18
0
int main(int argc, char *argv[])
{
  int c;
  struct state *state = NULL;
#if TEST_BUILD
  struct test_case *test_case;
#endif
  prefs_init();

  while(1) {
    int option_index = 0;
    static struct option long_options[] = {
      {"cart",                  required_argument, 0, OPT_CART },
      {"force-extreme-disasm",  no_argument,       0, OPT_FORCE_EXTREME_DISASM },
      {"crop-screen",           no_argument,       0, OPT_CROP_SCREEN },
      {"loglevels" ,            required_argument, 0, OPT_LOGLEVELS },
      {"audio-device" ,         required_argument, 0, OPT_AUDIO_DEVICE },
#if TEST_BUILD
      {"test-case",             required_argument, 0, OPT_TEST_MODE},
#endif
      {0,                       0,                 0, 0 }
    };
    c = getopt_long(argc, argv, "a:b:c:t:s:hdpyVAMvq", long_options, &option_index);
    if(c == -1) break;

    switch(c) {
    case 'a':
      prefs_set("diskimage", optarg);
      break;
    case 'b':
      prefs_set("diskimage2", optarg);
      break;
    case 'c':
      prefs_set("hdimage", optarg);
      break;
    case 't':
      prefs_set("tosimage", optarg);
      break;
    case 's':
      prefs_set("stateimage", optarg);
      break;
    case OPT_CART:
      prefs_set("cartimage", optarg);
      break;
    case OPT_FORCE_EXTREME_DISASM:
      cprint_all = 1;
      break;
    case OPT_CROP_SCREEN:
      crop_screen = 1;
      break;
    case OPT_LOGLEVELS:
      diag_set_module_levels(optarg);
      break;
    case OPT_AUDIO_DEVICE:
      if(!strncmp("list", optarg, 4)) {
        audio_device = -1;
      } else {
        audio_device = atoi(optarg);
      }
      break;
#if TEST_BUILD
    case OPT_TEST_MODE:
      test_case_name = xstrdup(optarg);
      test_mode = 1;
      break;
#endif
    case 'd':
      debugger = 1;
      break;
    case 'p':
      ppmoutput = 1;
      break;
    case 'y':
      psgoutput = 1;
      break;
    case 'v':
      verbosity++;
      break;
    case 'q':
      verbosity = MAX(1, verbosity-1);
      break;
    case 'V':
      vsync_delay = 1;
      break;
    case 'A':
      play_audio = 1;
      break;
    case 'M':
      monitor_sm124 = 1;
      break;
    case 'h':
    default:
      printf("Usage: %s [-AdMpqvVy] [-a diskimage1] [-b diskimage2] [-c hdimage] [-t tosimage] [-s stateimage]\n",
	     argv[0]);
      exit(-1);
      break;
    }
  }

  /* Do not crop screen while debugging */
  if(debugger) {
    crop_screen = 0;
  }
  
  if((prefs.diskimage == NULL) && (argv[optind] != NULL))
    prefs_set("diskimage", argv[optind]);

  SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO);

#if TEST_BUILD
  if(test_mode) {
    test_case = test_init(test_case_name);
    if(test_case) {
      if(test_case->cartridge_name) {
        prefs_set("cartimage", test_case->cartridge_name);
      }
      if(test_case->floppy_name) {
        prefs_set("diskimage", test_case->floppy_name);
      }
    } else {
      printf("DEBUG: Could not load test case %s\n", test_case_name);
      exit(-3);
    }
  }
#endif
  
  /* Must run before hardware module inits */
  mmu_init();

  /* This must also be run before hardware modules.
     It gives a dummy area for some memory regions to not
     cause bus errors */
  mmu_fallback_init(); 

  /* Actual hardware */
  ram_init();
  rom_init();
  cpu_init();
  if(prefs.cartimage) {
    cartridge_init(prefs.cartimage);
  } else {
    cartridge_init(NULL);
  }
  psg_init();
  midi_init();
  acia_init();
  ikbd_init();
#if INCLUDE_RTC
  rtc_init();
#endif
  dma_init();
  fdc_init();
  hdc_init(prefs.hdimage);
  mfp_init();
  screen_disable(0);
  glue_init();
  shifter_init();
  if(debugger) {
    debug_init();
    cpu_halt_for_debug();
  }
  screen_init();
  
  floppy_init(prefs.diskimage, prefs.diskimage2);

  if(prefs.stateimage) {
    state = state_load(prefs.stateimage);
  }

  if(state != NULL)
    state_restore(state);

  memset(&reset, 0, sizeof reset);
  reset.sa_sigaction = reset_action;
  sigaction(SIGHUP, &reset, NULL);

  while(cpu_run(CPU_RUN));
  return 0;
}
Exemple #19
0
int
main(int argc, char **argv)
{
	char *executable;
	cpu_arch_t arch;
	cpu_t *cpu;
	uint8_t *RAM;
	FILE *f;
	int ramsize;

	int singlestep = SINGLESTEP_NONE;
	int log = 1;
	int print_ir = 0;

	/* parameter parsing */
	if (argc < 2) {
		printf("Usage: %s [--print-ir] <binary>\n", argv[0]);
		return 0;
	}
	if (!strcmp(argv[1], "--print-ir")) {
		print_ir = 1;
		argv++;
	}
	executable = argv[1];
	arch = CPU_ARCH_I386;

	ramsize = 1*1024*1024;
	RAM = (uint8_t*)malloc(ramsize);

	cpu = cpu_new(arch, 0, 0);

	cpu_set_flags_codegen(cpu, CPU_CODEGEN_OPTIMIZE);
	cpu_set_flags_debug(cpu, 0
		| (print_ir? CPU_DEBUG_PRINT_IR : 0)
		| (print_ir? CPU_DEBUG_PRINT_IR_OPTIMIZED : 0)
		| (log? CPU_DEBUG_LOG :0)
		| (singlestep == SINGLESTEP_STEP? CPU_DEBUG_SINGLESTEP    : 0)
		| (singlestep == SINGLESTEP_BB?   CPU_DEBUG_SINGLESTEP_BB : 0)
		);

	cpu_set_ram(cpu, RAM);
	
	/* load code */
	if (!(f = fopen(executable, "rb"))) {
		printf("Could not open %s!\n", executable);
		return 2;
	}
	cpu->code_start = START;
	cpu->code_end = cpu->code_start + fread(&RAM[cpu->code_start], 1, ramsize-cpu->code_start, f);
	fclose(f);
	cpu->code_entry = cpu->code_start + ENTRY;

	cpu_tag(cpu, cpu->code_entry);

	cpu_translate(cpu); /* force translation now */

	printf("\n*** Executing...\n");

	printf("GUEST run..."); fflush(stdout);

	cpu_run(cpu, debug_function);

	printf("done!\n");

	cpu_free(cpu);

	return 0;
}
Exemple #20
0
int
main(int argc, char **argv)
{
	char *s_arch;
	char *executable;
	cpu_arch_t arch;
	cpu_t *cpu;
	uint8_t *RAM;
	FILE *f;
	int ramsize;
	int r1, r2;
	uint64_t t1, t2, t3, t4;
	unsigned start_no = START_NO;

	int singlestep = SINGLESTEP_NONE;
	int log = 1;
	int print_ir = 1;

	/* parameter parsing */
	if (argc < 3) {
		printf("Usage: %s executable [arch] [itercount] [entries]\n", argv[0]);
		return 0;
	}
	s_arch = argv[1];
	executable = argv[2];
	if (argc >= 4)
		start_no = atoi(argv[3]);
	if (!strcmp("mips", s_arch))
		arch = CPU_ARCH_MIPS;
	else if (!strcmp("m88k", s_arch))
		arch = CPU_ARCH_M88K;
	else if (!strcmp("arm", s_arch))
		arch = CPU_ARCH_ARM;
	else if (!strcmp("fapra", s_arch))
		arch = CPU_ARCH_FAPRA;
	else {
		printf("unknown architecture '%s'!\n", s_arch);
		return 0;
	}

	ramsize = 5*1024*1024;
	RAM = (uint8_t*)malloc(ramsize);

	cpu = cpu_new(arch, 0, 0);

	cpu_set_flags_codegen(cpu, CPU_CODEGEN_OPTIMIZE);
	cpu_set_flags_debug(cpu, 0
		| (print_ir? CPU_DEBUG_PRINT_IR : 0)
		| (print_ir? CPU_DEBUG_PRINT_IR_OPTIMIZED : 0)
		| (log? CPU_DEBUG_LOG :0)
		| (singlestep == SINGLESTEP_STEP? CPU_DEBUG_SINGLESTEP    : 0)
		| (singlestep == SINGLESTEP_BB?   CPU_DEBUG_SINGLESTEP_BB : 0)
		);

	cpu_set_ram(cpu, RAM);
	
	/* load code */
	if (!(f = fopen(executable, "rb"))) {
		printf("Could not open %s!\n", executable);
		return 2;
	}
	cpu->code_start = START;
	cpu->code_end = cpu->code_start + fread(&RAM[cpu->code_start], 1, ramsize-cpu->code_start, f);
	fclose(f);
	cpu->code_entry = cpu->code_start + ENTRY;

	cpu_tag(cpu, cpu->code_entry);

	cpu_translate(cpu); /* force translation now */

	printf("\n*** Executing...\n");

	printf("number of iterations: %u\n", start_no);

	uint32_t *reg_pc, *reg_lr, *reg_param, *reg_result;
	switch (arch) {
		case CPU_ARCH_M88K:
			reg_pc = &((m88k_grf_t*)cpu->rf.grf)->sxip;
			reg_lr = &((m88k_grf_t*)cpu->rf.grf)->r[1];
			reg_param = &((m88k_grf_t*)cpu->rf.grf)->r[2];
			reg_result = &((m88k_grf_t*)cpu->rf.grf)->r[2];
			break;
		case CPU_ARCH_MIPS:
			reg_pc = &((reg_mips32_t*)cpu->rf.grf)->pc;
			reg_lr = &((reg_mips32_t*)cpu->rf.grf)->r[31];
			reg_param = &((reg_mips32_t*)cpu->rf.grf)->r[4];
			reg_result = &((reg_mips32_t*)cpu->rf.grf)->r[4];
			break;
		case CPU_ARCH_ARM:
			reg_pc = &((reg_arm_t*)cpu->rf.grf)->pc;
			reg_lr = &((reg_arm_t*)cpu->rf.grf)->r[14];
			reg_param = &((reg_arm_t*)cpu->rf.grf)->r[0];
			reg_result = &((reg_arm_t*)cpu->rf.grf)->r[0];
			break;
		case CPU_ARCH_FAPRA:
			reg_pc = &((reg_fapra32_t*)cpu->rf.grf)->pc;
			reg_lr = &((reg_fapra32_t*)cpu->rf.grf)->r[0];
			reg_param = &((reg_fapra32_t*)cpu->rf.grf)->r[3];
			reg_result = &((reg_fapra32_t*)cpu->rf.grf)->r[3];
			break;
		default:
			fprintf(stderr, "architecture %u not handled.\n", arch);
			exit(EXIT_FAILURE);
	}

	*reg_pc = cpu->code_entry;
	*reg_lr = RET_MAGIC;
	*reg_param = start_no;

	printf("GUEST run..."); fflush(stdout);

	t1 = abs_time();
	cpu_run(cpu, debug_function);
	t2 = abs_time();
	r1 = *reg_result;

	printf("done!\n");

	printf("HOST  run..."); fflush(stdout);
	t3 = abs_time();
	r2 = fib(start_no);
	t4 = abs_time();
	printf("done!\n");

  cpu_free(cpu);

	printf("Time GUEST: %lld\n", t2-t1);
	printf("Time HOST:  %lld\n", t4-t3);
	printf("Result HOST:  %d\n", r2);
	printf("Result GUEST: %d\n", r1);
	printf("GUEST required \033[1m%.2f%%\033[22m of HOST time.\n",  (float)(t2-t1)/(float)(t4-t3)*100);
	if (r1 == r2)
		printf("\033[1mSUCCESS!\033[22m\n\n");
	else
		printf("\033[1mFAILED!\033[22m\n\n");

	return 0;
}