static int handle_instruction_and_prog(struct kvm_vcpu *vcpu) { int rc, rc2; vcpu->stat.exit_instr_and_program++; rc = handle_instruction(vcpu); rc2 = handle_prog(vcpu); if (rc == -ENOTSUPP) vcpu->arch.sie_block->icptcode = 0x04; if (rc) return rc; return rc2; }
int main(void) { static int opcode, operand, num_instruct; int instruction = 0; num_instruct = load_instructions(); system("cls"); do { dump_memory(); read_and_parse_sml(instruction, &opcode, &operand); handle_instruction(&instruction, opcode, operand); system("cls"); } while ((HALT != opcode) && (instruction < num_instruct)); if (HALT == opcode) printf("HALTED\n"); else printf("No more instructions\n"); system("pause"); return 0; }
/* generate intermediate code for basic block 'tb'. */ static void gen_intermediate_code_internal( CPUNios2State *env, TranslationBlock *tb, int search_pc) { DisasContext dc1, *dc = &dc1; int num_insns; int max_insns; uint32_t next_page_start; int j, lj = -1; uint16_t *gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; /* Initialize DC */ dc->env = env; dc->cpu_R = cpu_R; dc->is_jmp = DISAS_NEXT; dc->pc = tb->pc; dc->tb = tb; /* Dump the CPU state to the log */ if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("--------------\n"); log_cpu_state(env, 0); } /* Set up instruction counts */ num_insns = 0; max_insns = tb->cflags & CF_COUNT_MASK; if (max_insns == 0) { max_insns = CF_COUNT_MASK; } next_page_start = (tb->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; gen_icount_start(); do { /* Mark instruction start with associated PC */ if (search_pc) { j = gen_opc_ptr - gen_opc_buf; if (lj < j) { lj++; while (lj < j) { gen_opc_instr_start[lj++] = 0; } } gen_opc_pc[lj] = dc->pc; gen_opc_instr_start[lj] = 1; gen_opc_icount[lj] = num_insns; } LOG_DIS("%8.8x:\t", dc->pc); if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) { gen_io_start(); } /* Decode an instruction */ handle_instruction(dc); dc->pc += 4; num_insns++; /* Translation stops when a conditional branch is encountered. * Otherwise the subsequent code could get translated several times. * Also stop translation when a page boundary is reached. This * ensures prefetch aborts occur at the right place. */ } while (!dc->is_jmp && gen_opc_ptr < gen_opc_end && !env->singlestep_enabled && !singlestep && dc->pc < next_page_start && num_insns < max_insns); if (tb->cflags & CF_LAST_IO) { gen_io_end(); } /* Indicate where the next block should start */ switch (dc->is_jmp) { case DISAS_NEXT: /* Save the current PC back into the CPU register */ tcg_gen_movi_tl(cpu_R[R_PC], dc->pc); tcg_gen_exit_tb(0); break; default: case DISAS_JUMP: case DISAS_UPDATE: /* The jump will already have updated the PC register */ tcg_gen_exit_tb(0); break; case DISAS_TB_JUMP: /* nothing more to generate */ break; } /* End off the block */ gen_icount_end(tb, num_insns); *gen_opc_ptr = INDEX_op_end; /* Mark instruction starts for the final generated instruction */ if (search_pc) { j = gen_opc_ptr - gen_opc_buf; lj++; while (lj <= j) { gen_opc_instr_start[lj++] = 0; } } else { tb->size = dc->pc - tb->pc; tb->icount = num_insns; } #ifdef DEBUG_DISAS if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { qemu_log("----------------\n"); qemu_log("IN: %s\n", lookup_symbol(tb->pc)); log_target_disas(tb->pc, dc->pc - tb->pc, 0); qemu_log("\nisize=%d osize=%td\n", dc->pc - tb->pc, gen_opc_ptr - gen_opc_buf); } #endif }
int main(int argc, char **argv) { int ch; int fd; char * filename = NULL; int interval = 1; int i = 0; signal(SIGUSR1, handle_usr1); signal(SIGUSR2, handle_usr2); (void)memset(&cpu, 0, sizeof(cpu)); while ((ch = getopt(argc, argv, "qvi:f:")) != -1) { switch (ch) { case 'f': filename = optarg; break; case 'i': interval = atoi(optarg); break; case 'v': verbose++; break; case 'q': verbose--; break; default: usage(argv[0]); } } if (filename == NULL) usage(argv[0]); fd = open(filename, O_RDONLY); if (fd < 0) { perror("error opening file"); exit(EXIT_FAILURE); } /* big endian data files */ for (i = 0; i < 0x10000; i++) { uint8_t byte; if (read(fd, &byte, sizeof(byte)) < 0) { break; } cpu.memory[i] = byte << 8; if (read(fd, &byte, sizeof(byte)) < 0) { break; } cpu.memory[i] += byte; } while(1) { word value = cpu.memory[cpu.PC++]; instruction i = decode_instruction(value); handle_instruction(i); if (verbose) dump_registers(); sleep(interval); while(halt) {}; } exit(EXIT_SUCCESS); }
equation* equation_factory::scalar_equation(std::string eq){ equation* ret = new equation(); ret->isVector = false; ret->self = eq; //look into shunting-yard algorithm // '(' -> 100, ')' -> 101 std::stack<int> ops; char k = 0; unsigned int i = 0; for(i=0; i<eq.size(); ++i){ k = eq[i]; switch(k){ case 'x': case 'X': ret->everything.push_back('V'); ret->variables.push_back('X'); break; case 'y': case 'Y': ret->everything.push_back('V'); ret->variables.push_back('Y'); break; case 'z': case 'Z': ret->everything.push_back('V'); ret->variables.push_back('Z'); break; case '+': case '-': case '*': case '/': case '^': case '(': case ')': case 'S': case 's': case 'T': case 't': case 'C': case 'c': case 'L': case 'l': case 'E': case 'e': case '~':{ int skip = handle_instruction(&ops, ret, k, eq, i); i += skip; break; } case ' '://deliberately ignore whitespaces case '\n': case '\t': break; } if(num_part(k)){ std::string build; while(num_part(k)){ build += k; k = eq[++i]; } i--; //went too far, the end condition on the loop will move formward, so we are moving this back one. float num = (float)atof(build.c_str()); ret->everything.push_back('L'); ret->literals.push_back(num); } } while(ops.size() > 0){ ret->everything.push_back('I'); ret->instructions.push_back(ops.top()); ops.pop(); } ret->elen = ret->everything.size()-1; ret->ilen = ret->instructions.size()-1; ret->vlen = ret->variables.size()-1; ret->llen = ret->literals.size()-1; ret->evr_direct = ret->everything.data(); ret->inst_direct = ret->instructions.data(); ret->var_direct = ret->variables.data(); ret->lit_direct = ret->literals.data(); return ret; }