Пример #1
0
BasicBlock *
cpu_translate_singlestep_bb(cpu_t *cpu, BasicBlock *bb_ret, BasicBlock *bb_trap)
{
	addr_t entry = cpu->f.get_pc(cpu, cpu->rf.grf);
	addr_t pc = entry;

	BasicBlock *cur_bb = create_basicblock(cpu, pc, cpu->cur_func, BB_TYPE_NORMAL);

	tag_t tag;
	BasicBlock *bb_target = NULL, *bb_next = NULL, *bb_cont = NULL;
	do {
//printf("%s:%d\n", __func__, __LINE__);
		addr_t new_pc, next_pc;

		if (LOGGING)
			disasm_instr(cpu, pc);

		cpu->f.tag_instr(cpu, pc, &tag, &new_pc, &next_pc);

		/* get target basic block */
		if (tag & TAG_RET)
			bb_target = bb_ret;
		if (tag & (TAG_CALL|TAG_BRANCH)) {
			if (new_pc == NEW_PC_NONE) { /* translate_instr() will set PC */
				bb_target = bb_ret;
			} else {
				if (new_pc == entry)	/* tight loop */
					bb_target = cur_bb;
				else
					bb_target = create_singlestep_return_basicblock(cpu, new_pc, bb_ret);
			}
		}
		/* get not-taken basic block */
		if (tag & TAG_CONDITIONAL)
			bb_next = create_singlestep_return_basicblock(cpu, next_pc, bb_ret);

		bb_cont = translate_instr(cpu, pc, tag, bb_target, bb_trap, bb_next, cur_bb);

		pc = next_pc;
		
	} while (is_inside_code_area(cpu, pc) && /* end of code section */
			bb_cont); /* last intruction jumped away */

	return cur_bb;
}
Пример #2
0
int
cpu_run(cpu_t *cpu, debug_function_t debug_function)
{
	addr_t pc = 0, orig_pc = 0;
	uint32_t i;
	int ret;
	bool success;
	bool do_translate = true;

	/* try to find the entry in all functions */
	while(true) {
		if (do_translate) {
			cpu_translate(cpu);
			pc = cpu->f.get_pc(cpu, cpu->rf.grf);
		}

		orig_pc = pc;
		success = false;
		for (i = 0; i < cpu->functions; i++) {
			fp_t FP = (fp_t)cpu->fp[i];
			update_timing(cpu, TIMER_RUN, true);
			breakpoint();
			ret = FP(cpu->RAM, cpu->rf.grf, cpu->rf.frf, debug_function);
			update_timing(cpu, TIMER_RUN, false);
			pc = cpu->f.get_pc(cpu, cpu->rf.grf);
			if (ret != JIT_RETURN_FUNCNOTFOUND)
				return ret;
			if (!is_inside_code_area(cpu, pc))
				return ret;
			if (pc != orig_pc) {
				success = true;
				break;
			}
		}
		if (!success) {
			LOG("{%" PRIx64 "}", pc);
			cpu_tag(cpu, pc);
			do_translate = true;
		}
	}
}
Пример #3
0
/**
 * @brief search the function of current address in map.If find,run it.Other wise,return.
 *
 * @param cpu CPU core structure
 * @param debug_function debug function 
 *
 * @return the return value of JIT Function
 */
int
cpu_run(cpu_t *cpu)
{
	addr_t pc = 0, orig_pc = 0;
	uint64_t icounter, orig_icounter;
	uint32_t i;
	int ret;
	bool success;
	bool do_translate = true;
	fp_t pfunc = NULL;

	/* try to find the entry in all functions */
	while(true) {
		pc = cpu->f.get_pc(cpu, cpu->rf.grf);
#ifdef HASH_FAST_MAP
		fast_map hash_map = cpu->dyncom_engine->fmap;
		pfunc = (fp_t)hash_map[pc & 0x1fffff];
		if(pfunc)
			do_translate = false;
		else
			return JIT_RETURN_FUNCNOTFOUND;
#else
		fast_map &func_addr = cpu->dyncom_engine->fmap;
		fast_map::const_iterator it = func_addr.find(pc);
		if (it != func_addr.end()) {
			pfunc = (fp_t)it->second;
			do_translate = false;
		} else{
			LOG("jitfunction not found:key=0x%x\n", pc);
			return JIT_RETURN_FUNCNOTFOUND;
		}
#endif
		//LOG("find jitfunction:key=0x%x\n", pc);

		//orig_pc = pc;
		//orig_icounter = REG(SR(ICOUNTER));
		//success = false;
		UPDATE_TIMING(cpu, TIMER_RUN, true);
		//breakpoint();
#if PRINT_REG
		for (int i = 0; i < 16; i++) {
			LOG("%d:%x ", i, *(uint32_t*)((uint8_t*)cpu->rf.grf + 4*i));
		}
		LOG("\n");
		LOG("############### Begin to execute JIT\n");
#endif
		ret = pfunc(cpu->dyncom_engine->RAM, cpu->rf.grf, cpu->rf.srf, cpu->rf.frf, read_memory, write_memory);
		//*(uint32_t*)((uint8_t*)cpu->rf.grf + 8) = 0;
		//ret = FP(cpu->dyncom_engine->RAM, cpu->rf.grf, cpu->rf.frf, debug_function);
#if PRINT_REG
		for (int i = 0; i < 16; i++) {
			LOG("%d:%x ", i, *(uint32_t*)((uint8_t*)cpu->rf.grf + 4*i));
		}
		LOG("pc : %x\n ret : %x", cpu->f.get_pc(cpu, cpu->rf.grf), ret);
		LOG("\n");
#endif
		UPDATE_TIMING(cpu, TIMER_RUN, false);
		//pc = cpu->f.get_pc(cpu, cpu->rf.grf);
		//icounter = REG(SR(ICOUNTER));
		//pc = 0x4d495354;
		//return ret;
		if (ret != JIT_RETURN_FUNCNOTFOUND)
			return ret;
#if 0
		if (!is_inside_code_area(cpu, pc))
			return ret;
#endif
#if 0
		/* simulator run new instructions ? */
		if (icounter != orig_icounter) {
			success = true;
			//break;
		}
		//}
		if (!success) {
			LOG("{%llx}", pc);
			cpu_tag(cpu, pc);
			do_translate = true;
		}
#endif
	}
}