📄 mips64_amd64_trans.c
字号:
/* 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);}/* BGTZL (Branch On Greater Than Zero Likely) */DECLARE_INSN(BGTZL){ 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,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) */DECLARE_INSN(BLEZ){ 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 */ 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);}/* BLEZL (Branch On Less or Equal Than Zero Likely) */DECLARE_INSN(BLEZL){ 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 */ 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);}/* BLTZ (Branch On Less Than Zero) */DECLARE_INSN(BLTZ){ 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 */ 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);}/* BLTZAL (Branch On Less Than Zero And Link) */DECLARE_INSN(BLTZAL){ 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 */ 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);}/* BLTZALL (Branch On Less Than Zero And Link Likely) */DECLARE_INSN(BLTZALL){ 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 */ 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);}/* BLTZL (Branch On Less Than Zero Likely) */DECLARE_INSN(BLTZL){ 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 */ 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);}/* BNE (Branch On Not Equal) */DECLARE_INSN(BNE){ 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 */ 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);}/* BNEL (Branch On Not Equal Likely) */DECLARE_INSN(BNEL){ 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 */ 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);}/* BREAK */DECLARE_INSN(BREAK){ 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); mips64_jit_tcb_push_epilog(b); return(0);}/* CACHE */DECLARE_INSN(CACHE){ 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 */DECLARE_INSN(CFC0){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); mips64_emit_cp_xfr_op(b,rt,rd,mips64_cp0_exec_cfc0); return(0);}/* CTC0 */DECLARE_INSN(CTC0){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); mips64_emit_cp_xfr_op(b,rt,rd,mips64_cp0_exec_ctc0); return(0);}/* DADDIU */DECLARE_INSN(DADDIU){ 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 */DECLARE_INSN(DADDU){ 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 */DECLARE_INSN(DIV){ 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 */DECLARE_INSN(DIVU){ 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 */DECLARE_INSN(DMFC0){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); mips64_emit_cp_xfr_op(b,rt,rd,mips64_cp0_exec_dmfc0); return(0);}/* DMFC1 */DECLARE_INSN(DMFC1){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); mips64_emit_cp_xfr_op(b,rt,rd,mips64_exec_dmfc1); return(0);}/* DMTC0 */DECLARE_INSN(DMTC0){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); mips64_emit_cp_xfr_op(b,rt,rd,mips64_cp0_exec_dmtc0); return(0);}/* DMTC1 */DECLARE_INSN(DMTC1){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); mips64_emit_cp_xfr_op(b,rt,rd,mips64_exec_dmtc1); return(0);}/* DSLL */DECLARE_INSN(DSLL){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); int sa = bits(insn,6,10); amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rt),8); amd64_shift_reg_imm(b->jit_ptr,X86_SHL,AMD64_RAX,sa); amd64_mov_membase_reg(b->jit_ptr,AMD64_R15,REG_OFFSET(rd),AMD64_RAX,8); return(0);}/* DSLL32 */DECLARE_INSN(DSLL32){ int rt = bits(insn,16,20); int rd = bits(insn,11,15); int sa = bits(insn,6,10); amd64_mov_reg_membase(b->jit_ptr,AMD64_RAX,AMD64_R15,REG_OFFSET(rt),8); amd64_shift_reg_imm(b->jit_ptr,X86_SHL,AMD64_RAX,sa+32);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -