⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mips64_amd64_trans.c

📁 思科路由器仿真器,用来仿7200系列得,可以在电脑上模拟路由器
💻 C
📖 第 1 页 / 共 5 页
字号:
}/*  * Increment count register and trigger the timer IRQ if value in compare  * register is the same. */void mips64_inc_cp0_count_reg(mips64_jit_tcb_t *b){      amd64_inc_membase(b->jit_ptr,AMD64_R15,OFFSET(cpu_mips_t,cp0_virt_cnt_reg));#if 0 /* TIMER_IRQ */   u_char *test1;   /* increment the virtual count register */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,                         AMD64_R15,OFFSET(cpu_mips_t,cp0_virt_cnt_reg),4);   amd64_inc_reg_size(b->jit_ptr,AMD64_RAX,4);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,                         OFFSET(cpu_mips_t,cp0_virt_cnt_reg),                         AMD64_RAX,4);   /* check with the virtual compare register */    amd64_alu_reg_membase_size(b->jit_ptr,X86_CMP,AMD64_RAX,                              AMD64_R15,OFFSET(cpu_mips_t,cp0_virt_cmp_reg),4);   test1 = b->jit_ptr;   amd64_branch8(b->jit_ptr, X86_CC_NE, 0, 1);   /* we have to trigger the timer irq  */   amd64_mov_reg_reg(b->jit_ptr,AMD64_RDI,AMD64_R15,8);   mips64_emit_basic_c_call(b,mips64_trigger_timer_irq);   amd64_patch(test1,b->jit_ptr);#endif}/* Check if there are pending IRQ */void mips64_check_pending_irq(mips64_jit_tcb_t *b){   u_char *test1;   /* Check the pending IRQ flag */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,                         AMD64_R15,OFFSET(cpu_mips_t,irq_pending),4);   amd64_test_reg_reg_size(b->jit_ptr,AMD64_RAX,AMD64_RAX,4);   test1 = b->jit_ptr;   amd64_branch8(b->jit_ptr, X86_CC_Z, 0, 1);   /* Update PC */   mips64_set_pc(b,b->start_pc+((b->mips_trans_pos-1)<<2));   /* Trigger the IRQ */   amd64_mov_reg_reg(b->jit_ptr,AMD64_RDI,AMD64_R15,8);   mips64_emit_basic_c_call(b,mips64_trigger_irq);   mips64_jit_tcb_push_epilog(b);   amd64_patch(test1,b->jit_ptr);}/* Increment the number of executed instructions (performance debugging) */void mips64_inc_perf_counter(mips64_jit_tcb_t *b){    amd64_inc_membase_size(b->jit_ptr,                          AMD64_R15,OFFSET(cpu_mips_t,perf_counter),4);}/* ADD */DECLARE_INSN(ADD){	   int rs = bits(insn,21,25);   int rt = bits(insn,16,20);   int rd = bits(insn,11,15);      amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_alu_reg_membase(b->jit_ptr,X86_ADD,AMD64_RAX,AMD64_R15,                         REG_OFFSET(rt));   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RAX,X86_EAX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rd),AMD64_RAX,8);   return(0);}/* ADDI */DECLARE_INSN(ADDI){   int rs  = bits(insn,21,25);   int rt  = bits(insn,16,20);   int imm = bits(insn,0,15);   m_uint64_t val = sign_extend(imm,16);   /* TODO: Exception handling */   mips64_load_imm(b,AMD64_RAX,val);   amd64_alu_reg_membase(b->jit_ptr,X86_ADD,AMD64_RAX,                         AMD64_R15,REG_OFFSET(rs));   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RAX,X86_EAX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rt),AMD64_RAX,8);   return(0);}/* ADDIU */DECLARE_INSN(ADDIU){   int rs  = bits(insn,21,25);   int rt  = bits(insn,16,20);   int imm = bits(insn,0,15);   m_uint64_t val = sign_extend(imm,16);   mips64_load_imm(b,AMD64_RAX,val);   if (rs != 0) {      amd64_alu_reg_membase(b->jit_ptr,X86_ADD,AMD64_RAX,                            AMD64_R15,REG_OFFSET(rs));   }   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RDX,X86_EAX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rt),AMD64_RDX,8);   return(0);}/* ADDU */DECLARE_INSN(ADDU){	   int rs = bits(insn,21,25);   int rt = bits(insn,16,20);   int rd = bits(insn,11,15);      amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_alu_reg_membase(b->jit_ptr,X86_ADD,AMD64_RAX,AMD64_R15,                         REG_OFFSET(rt));   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RAX,X86_EAX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rd),AMD64_RAX,8);   return(0);}/* AND */DECLARE_INSN(AND){   int rs = bits(insn,21,25);   int rt = bits(insn,16,20);   int rd = bits(insn,11,15);   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_alu_reg_membase(b->jit_ptr,X86_AND,AMD64_RAX,AMD64_R15,                         REG_OFFSET(rt));   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rd),AMD64_RAX,8);   return(0);}/* ANDI */DECLARE_INSN(ANDI){   int rs  = bits(insn,21,25);   int rt  = bits(insn,16,20);   int imm = bits(insn,0,15);   mips64_load_imm(b,AMD64_RAX,imm);   amd64_alu_reg_membase(b->jit_ptr,X86_AND,AMD64_RAX,                         AMD64_R15,REG_OFFSET(rs));   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rt),AMD64_RAX,8);   return(0);}/* B (Branch, virtual instruction) */DECLARE_INSN(B){   int offset = bits(insn,0,15);   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,1);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   return(0);}/* BAL (Branch and Link, virtual instruction) */DECLARE_INSN(BAL){   int offset = bits(insn,0,15);   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /* set the return address (instruction after the delay slot) */   mips64_set_ra(b,b->start_pc + ((b->mips_trans_pos + 1) << 2));   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,1);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,0);   return(0);}/* BEQ (Branch On Equal) */DECLARE_INSN(BEQ){   int rs = bits(insn,21,25);   int rt = bits(insn,16,20);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /*     * compare gpr[rs] and gpr[rt].     */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_alu_reg_membase(b->jit_ptr,X86_CMP,AMD64_RAX,                         AMD64_R15,REG_OFFSET(rt));   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_NE, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,2);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   /* if the branch is not taken, we have to execute the delay slot too */   mips64_jit_fetch_and_emit(cpu,b,1);   return(0);}/* BEQL (Branch On Equal Likely) */DECLARE_INSN(BEQL){   int rs = bits(insn,21,25);   int rt = bits(insn,16,20);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);      /*     * compare gpr[rs] and gpr[rt].     */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_alu_reg_membase(b->jit_ptr,X86_CMP,AMD64_RAX,                         AMD64_R15,REG_OFFSET(rt));   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_NE, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,1);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   return(0);}/* BEQZ (Branch On Equal Zero) */DECLARE_INSN(BEQZ){   int rs = bits(insn,21,25);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /*     * compare gpr[rs] with 0.     */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_test_reg_reg(b->jit_ptr,AMD64_RAX,AMD64_RAX);   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_NZ, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,2);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   /* if the branch is not taken, we have to execute the delay slot too */   mips64_jit_fetch_and_emit(cpu,b,1);   return(0);}/* BNEZ (Branch On Not Equal Zero) */DECLARE_INSN(BNEZ){   int rs = bits(insn,21,25);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /*     * compare gpr[rs] with 0.     */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_test_reg_reg(b->jit_ptr,AMD64_RAX,AMD64_RAX);   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_Z, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,2);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   /* if the branch is not taken, we have to execute the delay slot too */   mips64_jit_fetch_and_emit(cpu,b,1);   return(0);}/* BGEZ (Branch On Greater or Equal Than Zero) */DECLARE_INSN(BGEZ){   int rs = bits(insn,21,25);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /* If sign bit is set, don't take the branch */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_test_reg_reg(b->jit_ptr,AMD64_RAX,AMD64_RAX);   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_S, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,2);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   /* if the branch is not taken, we have to execute the delay slot too */   mips64_jit_fetch_and_emit(cpu,b,1);   return(0);}/* BGEZAL (Branch On Greater or Equal Than Zero And Link) */DECLARE_INSN(BGEZAL){   int rs = bits(insn,21,25);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /* set the return address (instruction after the delay slot) */   mips64_set_ra(b,b->start_pc + ((b->mips_trans_pos + 1) << 2));   /* If sign bit is set, don't take the branch */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_test_reg_reg(b->jit_ptr,AMD64_RAX,AMD64_RAX);   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_S, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,2);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   /* if the branch is not taken, we have to execute the delay slot too */   mips64_jit_fetch_and_emit(cpu,b,1);   return(0);}/* BGEZALL (Branch On Greater or Equal Than Zero And Link Likely) */DECLARE_INSN(BGEZALL){   int rs = bits(insn,21,25);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /* set the return address (instruction after the delay slot) */   mips64_set_ra(b,b->start_pc + ((b->mips_trans_pos + 1) << 2));   /* If sign bit is set, don't take the branch */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_test_reg_reg(b->jit_ptr,AMD64_RAX,AMD64_RAX);   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_S, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,1);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   return(0);}/* BGEZL (Branch On Greater or Equal Than Zero Likely) */DECLARE_INSN(BGEZL){   int rs = bits(insn,21,25);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /* If sign bit is set, don't take the branch */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_test_reg_reg(b->jit_ptr,AMD64_RAX,AMD64_RAX);   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_S, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,1);   /* set the new pc in cpu structure */   mips64_set_jump(cpu,b,new_pc,1);   amd64_patch(test1,b->jit_ptr);   return(0);}/* BGTZ (Branch On Greater Than Zero) */DECLARE_INSN(BGTZ){   int rs = bits(insn,21,25);   int offset = bits(insn,0,15);   u_char *test1;   m_uint64_t new_pc;   /* compute the new pc */   new_pc = b->start_pc + (b->mips_trans_pos << 2);   new_pc += sign_extend(offset << 2,18);   /* compare reg to zero */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),8);   amd64_clear_reg(b->jit_ptr,AMD64_RCX);   amd64_alu_reg_reg(b->jit_ptr,X86_CMP,AMD64_RAX,AMD64_RCX);   test1 = b->jit_ptr;   amd64_branch32(b->jit_ptr, X86_CC_LE, 0, 1);   /* insert the instruction in the delay slot */   mips64_jit_fetch_and_emit(cpu,b,2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -