From: Arthur Chunqi Li Subject: [PATCH 1/2] kvm-unit-tests: Add a func to run instruction in emulator Date: Thu, 13 Jun 2013 23:16:17 +0800 Message-ID: <1371136578-4047-1-git-send-email-yzt356@gmail.com> Cc: gleb@redhat.com, pbonzini@redhat.com, jan.kiszka@web.de, Arthur Chunqi Li To: kvm@vger.kernel.org Return-path: Received: from mail-pb0-f48.google.com ([209.85.160.48]:50635 "EHLO mail-pb0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756552Ab3FMPQf (ORCPT ); Thu, 13 Jun 2013 11:16:35 -0400 Received: by mail-pb0-f48.google.com with SMTP id ma3so5012349pbc.35 for ; Thu, 13 Jun 2013 08:16:34 -0700 (PDT) Sender: kvm-owner@vger.kernel.org List-ID: Add a function trap_emulator to run an instruction in emulator. Set inregs first (%rax is invalid because it is used as return address), put instruction codec in alt_insn and call func with alt_insn_length. Get results in outregs. Signed-off-by: Arthur Chunqi Li --- x86/emulator.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/x86/emulator.c b/x86/emulator.c index 96576e5..4981bfb 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -11,6 +11,16 @@ int fails, tests; static int exceptions; +struct regs { + u64 rax, rbx, rcx, rdx; + u64 rsi, rdi, rsp, rbp; + u64 r8, r9, r10, r11; + u64 r12, r13, r14, r15; + u64 rip, rflags; +}; +static struct regs inregs, outregs; +extern struct regs save; + void report(const char *name, int result) { ++tests; @@ -685,6 +695,128 @@ static void test_shld_shrd(u32 *mem) report("shrd (cl)", *mem == ((0x12345678 >> 3) | (5u << 29))); } +extern u8 insn_start[], insn_end[]; +extern u8 insn_emulate_start[], insn_emulate_end[]; + +static void mk_insn_page(uint8_t *insn_page, uint8_t *alt_insn_page, + uint8_t *alt_insn, int alt_insn_length) +{ + int i, emul_offset; + for (i=1; i