From patchwork Wed Jun 21 12:45:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9801733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2A83460329 for ; Wed, 21 Jun 2017 12:47:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1760E285C7 for ; Wed, 21 Jun 2017 12:47:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B24B285C9; Wed, 21 Jun 2017 12:47:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 70EF2285C7 for ; Wed, 21 Jun 2017 12:47:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNf0L-00045X-Hh; Wed, 21 Jun 2017 12:45:05 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNf0K-00045O-QG for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 12:45:04 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 43/12-02956-05A6A495; Wed, 21 Jun 2017 12:45:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJIsWRWlGSWpSXmKPExsXS6fjDS9c/yyv SoOWDgsX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmrGv5y1bwSW1io0/DrI1MF6U7WLk5BASyJPY ubefrYuRg4NXwE5iUj83SFhCwFDi9MKbLCA2i4CqRMO65awgNpuAukTbs+2sIOUiAgYS544mg ZjMAvoS29aBVQsLWEi8vriDGWK4ncSG3Y8YIYYLSvzdIQwSZgYKdxy7wD6BkXsWQmYWkgyErS Xx8NctFghbW2LZwtfMs8B2SUss/8cBYZpJ7OwIxVThKPH0WeQCRo5VjBrFqUVlqUW6RpZ6SUW Z6RkluYmZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiBwcgABDsYDywKPMQoycGkJMpb7u0VKcSX lJ9SmZFYnBFfVJqTWnyIUYaDQ0mClzsTKCdYlJqeWpGWmQOMC5i0BAePkgivWwBQmre4IDG3O DMdInWKUZdjw+r1X5iEWPLy81KlxHmvZAAVCYAUZZTmwY2AxeglRlkpYV5GoKOEeApSi3IzS1 DlXzGKczAqCfOuSQeawpOZVwK36RXQEUxAR7w44gFyREkiQkqqgVHH+1Z8nVvEJTlvP9FsZbY vqi47f6+XcjL49mzOgcuzPzEH1E6p2sy2Yq6I+HYWeZ6VmTc5fXtkmVLKV9l1z1gc1jvtrPmZ TZfr85cHRgb8WrWl8c3Zixfl9mu6eXUfMeiX7bn/cVLhuQUzkkP3pNT91FmzM2iNlJi87lqjv dY1dtlPePYx2SqxFGckGmoxFxUnAgB+A8oozAIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1498049101!68347503!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 20689 invoked from network); 21 Jun 2017 12:45:03 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 21 Jun 2017 12:45:03 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 21 Jun 2017 06:45:01 -0600 Message-Id: <594A866C020000780016542E@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.2 Date: Wed, 21 Jun 2017 06:45:00 -0600 From: "Jan Beulich" To: "xen-devel" References: <594A866C020000780016542E@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH] x86emul: correct CF output of SHLD/SHRD X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP CF reflects the last bit shifted out, i.e. can't possibly be derived from the result value. Signed-off-by: Jan Beulich --- This will only apply cleanly on top of https://lists.xenproject.org/archives/html/xen-devel/2017-06/msg02137.html x86emul: correct CF output of SHLD/SHRD CF reflects the last bit shifted out, i.e. can't possibly be derived from the result value. Signed-off-by: Jan Beulich --- This will only apply cleanly on top of https://lists.xenproject.org/archives/html/xen-devel/2017-06/msg02137.html --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -783,6 +783,29 @@ int main(int argc, char **argv) printf("okay\n"); #endif + printf("%-40s", "Testing shld $1,%ecx,(%edx)..."); + res[0] = 0x12345678; + regs.edx = (unsigned long)res; + regs.ecx = 0x9abcdef0; + instr[0] = 0x0f; instr[1] = 0xa4; instr[2] = 0x0a; instr[3] = 0x01; + for ( i = 0; i < 0x20; ++i ) + { + uint32_t r = res[0], f, m = X86_EFLAGS_ARITH_MASK & ~X86_EFLAGS_AF; + + asm ( "shld $1,%2,%0; pushf; pop %1" + : "+rm" (r), "=rm" (f) : "r" (regs.ecx) ); + regs.eflags = f ^ m; + regs.eip = (unsigned long)&instr[0]; + rc = x86_emulate(&ctxt, &emulops); + if ( (rc != X86EMUL_OKAY) || + (regs.eip != (unsigned long)&instr[4]) || + (res[0] != r) || + ((regs.eflags ^ f) & m) ) + goto fail; + regs.ecx <<= 1; + } + printf("okay\n"); + printf("%-40s", "Testing movbe (%ecx),%eax..."); instr[0] = 0x0f; instr[1] = 0x38; instr[2] = 0xf0; instr[3] = 0x01; regs.eflags = 0x200; --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -6424,7 +6424,7 @@ x86_emulate( (src.val >> (width - shift))); _regs.eflags &= ~(X86_EFLAGS_OF | X86_EFLAGS_SF | X86_EFLAGS_ZF | X86_EFLAGS_PF | X86_EFLAGS_CF); - if ( (dst.val >> ((b & 8) ? (shift - 1) : (width - shift))) & 1 ) + if ( (dst.orig_val >> ((b & 8) ? (shift - 1) : (width - shift))) & 1 ) _regs.eflags |= X86_EFLAGS_CF; if ( ((dst.val ^ dst.orig_val) >> (width - 1)) & 1 ) _regs.eflags |= X86_EFLAGS_OF; --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -783,6 +783,29 @@ int main(int argc, char **argv) printf("okay\n"); #endif + printf("%-40s", "Testing shld $1,%ecx,(%edx)..."); + res[0] = 0x12345678; + regs.edx = (unsigned long)res; + regs.ecx = 0x9abcdef0; + instr[0] = 0x0f; instr[1] = 0xa4; instr[2] = 0x0a; instr[3] = 0x01; + for ( i = 0; i < 0x20; ++i ) + { + uint32_t r = res[0], f, m = X86_EFLAGS_ARITH_MASK & ~X86_EFLAGS_AF; + + asm ( "shld $1,%2,%0; pushf; pop %1" + : "+rm" (r), "=rm" (f) : "r" (regs.ecx) ); + regs.eflags = f ^ m; + regs.eip = (unsigned long)&instr[0]; + rc = x86_emulate(&ctxt, &emulops); + if ( (rc != X86EMUL_OKAY) || + (regs.eip != (unsigned long)&instr[4]) || + (res[0] != r) || + ((regs.eflags ^ f) & m) ) + goto fail; + regs.ecx <<= 1; + } + printf("okay\n"); + printf("%-40s", "Testing movbe (%ecx),%eax..."); instr[0] = 0x0f; instr[1] = 0x38; instr[2] = 0xf0; instr[3] = 0x01; regs.eflags = 0x200; --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -6424,7 +6424,7 @@ x86_emulate( (src.val >> (width - shift))); _regs.eflags &= ~(X86_EFLAGS_OF | X86_EFLAGS_SF | X86_EFLAGS_ZF | X86_EFLAGS_PF | X86_EFLAGS_CF); - if ( (dst.val >> ((b & 8) ? (shift - 1) : (width - shift))) & 1 ) + if ( (dst.orig_val >> ((b & 8) ? (shift - 1) : (width - shift))) & 1 ) _regs.eflags |= X86_EFLAGS_CF; if ( ((dst.val ^ dst.orig_val) >> (width - 1)) & 1 ) _regs.eflags |= X86_EFLAGS_OF;