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

📄 amd64_trans.c

📁 思科路由器仿真器,用来仿7200系列得,可以在电脑上模拟路由器-Cisco router simulator, used to fake a 7200 series can be simulated
💻 C
📖 第 1 页 / 共 5 页
字号:
{   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 */   insn_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 */   insn_fetch_and_emit(cpu,b,1);   return(0);}/* BGTZL (Branch On Greater Than Zero Likely) */static int mips64_emit_BGTZL(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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 */   insn_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);}/* BLEZ (Branch On Less or Equal Than Zero) */static int mips64_emit_BLEZ(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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_GT, 0, 1);   /* insert the instruction in the delay slot */   insn_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 */   insn_fetch_and_emit(cpu,b,1);   return(0);}/* BLEZL (Branch On Less or Equal Than Zero Likely) */static int mips64_emit_BLEZL(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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_GT, 0, 1);   /* insert the instruction in the delay slot */   insn_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);}/* BLTZ (Branch On Less Than Zero) */static int mips64_emit_BLTZ(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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 isn't 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_NS, 0, 1);   /* insert the instruction in the delay slot */   insn_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 */   insn_fetch_and_emit(cpu,b,1);   return(0);}/* BLTZAL (Branch On Less Than Zero And Link) */static int mips64_emit_BLTZAL(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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 isn't 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_NS, 0, 1);   /* insert the instruction in the delay slot */   insn_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 */   insn_fetch_and_emit(cpu,b,1);   return(0);}/* BLTZALL (Branch On Less Than Zero And Link Likely) */static int mips64_emit_BLTZALL(cpu_mips_t *cpu,insn_block_t *b,                               mips_insn_t insn){   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 isn't 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_NS, 0, 1);   /* insert the instruction in the delay slot */   insn_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);}/* BLTZL (Branch On Less Than Zero Likely) */static int mips64_emit_BLTZL(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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 isn't 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_NS, 0, 1);   /* insert the instruction in the delay slot */   insn_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);}/* BNE (Branch On Not Equal) */static int mips64_emit_BNE(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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_E, 0, 1);   /* insert the instruction in the delay slot */   insn_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 */   insn_fetch_and_emit(cpu,b,1);   return(0);}/* BNEL (Branch On Not Equal Likely) */static int mips64_emit_BNEL(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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_E, 0, 1);   /* insert the instruction in the delay slot */   insn_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);}/* BREAK */static int mips64_emit_BREAK(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){	   u_int code = bits(insn,6,25);   amd64_mov_reg_imm(b->jit_ptr,AMD64_RSI,code);   amd64_mov_reg_reg(b->jit_ptr,AMD64_RDI,AMD64_R15,8);   mips64_emit_basic_c_call(b,mips64_exec_break);   insn_block_push_epilog(b);   return(0);}/* CACHE */static int mips64_emit_CACHE(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){           int base   = bits(insn,21,25);   int op     = bits(insn,16,20);   int offset = bits(insn,0,15);   mips64_emit_memop(b,MIPS_MEMOP_CACHE,base,offset,op,0);   return(0);}/* CFC0 */static int mips64_emit_CFC0(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){	   int rt = bits(insn,16,20);   int rd = bits(insn,11,15);   mips64_emit_cp_xfr_op(b,rt,rd,cp0_exec_cfc0);   return(0);}/* CTC0 */static int mips64_emit_CTC0(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){	   int rt = bits(insn,16,20);   int rd = bits(insn,11,15);   mips64_emit_cp_xfr_op(b,rt,rd,cp0_exec_ctc0);   return(0);}/* DADDIU */static int mips64_emit_DADDIU(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   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_RCX,val);   amd64_alu_reg_membase(b->jit_ptr,X86_ADD,AMD64_RCX,                         AMD64_R15,REG_OFFSET(rs));   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rt),AMD64_RCX,8);   return(0);}/* DADDU: rd = rs + rt */static int mips64_emit_DADDU(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){	   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_RCX,AMD64_R15,REG_OFFSET(rs),8);   amd64_alu_reg_membase(b->jit_ptr,X86_ADD,AMD64_RCX,                         AMD64_R15,REG_OFFSET(rt));   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rd),AMD64_RCX,8);   return(0);}/* DIV */static int mips64_emit_DIV(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   int rs = bits(insn,21,25);   int rt = bits(insn,16,20);   /* eax = gpr[rs] */   amd64_clear_reg(b->jit_ptr,AMD64_RDX);   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),4);   /* ecx = gpr[rt] */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RCX,AMD64_R15,REG_OFFSET(rt),4);   /* eax = quotient (LO), edx = remainder (HI) */   amd64_div_reg_size(b->jit_ptr,AMD64_RCX,1,4);   /* store LO */   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RAX,X86_EAX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,OFFSET(cpu_mips_t,lo),                         AMD64_RAX,8);   /* store HI */   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RDX,X86_EDX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,OFFSET(cpu_mips_t,hi),                         AMD64_RDX,8);   return(0);}/* DIVU */static int mips64_emit_DIVU(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){   int rs = bits(insn,21,25);   int rt = bits(insn,16,20);   /* eax = gpr[rs] */   amd64_clear_reg(b->jit_ptr,AMD64_RDX);   amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rs),4);   /* ecx = gpr[rt] */   amd64_mov_reg_membase(b->jit_ptr,AMD64_RCX,AMD64_R15,REG_OFFSET(rt),4);   /* eax = quotient (LO), edx = remainder (HI) */   amd64_div_reg_size(b->jit_ptr,AMD64_RCX,0,4);   /* store LO */   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RAX,X86_EAX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,OFFSET(cpu_mips_t,lo),                         AMD64_RAX,8);   /* store HI */   amd64_movsxd_reg_reg(b->jit_ptr,AMD64_RDX,X86_EDX);   amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,OFFSET(cpu_mips_t,hi),                         AMD64_RDX,8);   return(0);}/* DMFC0 */static int mips64_emit_DMFC0(cpu_mips_t *cpu,insn_block_t *b,mips_insn_t insn){	   int rt = bits(insn,16,20);   int rd = bits(insn,11,15);

⌨️ 快捷键说明

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