KVM: x86 emulator: add CBW/CWDE/CDQE instruction emulation
PATCH 1/1 KVM: x86 emulator: add CBW/CWDE/CDQE instruction emulation
Add CBW/CWDE/CDQE instruction emulation.(opcode 0x98) Used by FreeBSD's boot loader.
Signed-off-by Wei Yongjun <[email protected]>
--- arch/x86/kvm/emulate.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
arch/x86/kvm/emulate.c +8 -1
@@ -2290,7 +2290,7 @@ static struct opcode opcode_table[256] = {/* 0x90 - 0x97 */ X8 (D (SrcAcc | DstReg)),/* 0x98 - 0x9F */ -N ,N ,D (SrcImmFAddr | No64),N , +D (DstAcc | SrcNone),N ,D (SrcImmFAddr | No64),N ,D (ImplicitOps | Stack),D (ImplicitOps | Stack),N ,N ,/* 0xA0 - 0xA7 */ D(ByteOp | DstAcc | SrcMem | Mov | MemAbs), D(DstAcc | SrcMem | Mov | MemAbs),
@@ -3011,6 +3011,13 @@ special_insn:if (c->dst.addr.reg == &c->regs[VCPU_REGS_RAX ])break ; goto xchg; +case 0x98 :/* cbw/cwde/cdqe */ +switch (c->op_bytes) { +case 2 : c->dst.val = (s8 )c->dst.val;break ; +case 4 : c->dst.val = (s16 )c->dst.val;break ; +case 8 : c->dst.val = (s32 )c->dst.val;break ; + } +break ;case 0x9c :/* pushf */ c->src.val = (unsigned long ) ctxt->eflags;emulate_push (ctxt, ops);
Signature · 1 line
1.7.0.4
PATCH 1/1 test: Add real mode test for cbw/cwde instruction
Signed-off-by Wei Yongjun <[email protected]>
--- x86/realmode.c | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-)
x86/realmode.c +27 -0
@@ -1236,6 +1236,32 @@ void test_loopcc(void)print_serial ("LOOPcc short Test 3: PASS\n" ); } +void test_cbw (void ) +{ +struct regs inregs = {0 }, outregs; + +MK_INSN (cbw,"mov $0xFE, %eax \n\t" +"cbw\n\t" ); +MK_INSN (cwde,"mov $0xFFFE, %eax \n\t" +"cwde\n\t" ); + +exec_in_big_real_mode (&inregs, &outregs, + insn_cbw, + insn_cbw_end - insn_cbw); +if (outregs.eax !=0xFFFE ) +print_serial ("cbw test1: FAIL\n" ); +else +print_serial ("cbw test 1: PASS\n" ); + +exec_in_big_real_mode (&inregs, &outregs, + insn_cwde, + insn_cwde_end - insn_cwde); +if (outregs.eax !=0xFFFFFFFE ) +print_serial ("cwde test1: FAIL\n" ); +else +print_serial ("cwde test 1: PASS\n" ); +} +void realmode_start (void ) {test_null ();
@@ -1264,6 +1290,7 @@ void realmode_start(void)test_div ();test_idiv ();test_loopcc (); +test_cbw ();exit (0 ); }
Signature · 1 line
1.7.0.4
Avi Kivity
AppliedRe: [PATCH] test: Add real mode test for cbw/cwde instruction
Quoted 1 line · Wei Yongjun
Signed-off-by Wei Yongjun <[email protected]>
Applied, thanks.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.