From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: [PATCH v2 1/3] hvmloader/tests: Improvements to shadow_gs_test() Date: Tue, 29 Jul 2014 18:49:02 +0100 Message-ID: <1406656144-24882-2-git-send-email-andrew.cooper3@citrix.com> References: <1406656144-24882-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1406656144-24882-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Keir Fraser , Ian Campbell , Andrew Cooper , Ian Jackson , Tim Deegan , Jan Beulich List-Id: xen-devel@lists.xenproject.org Use .code64 and .code32, and real mnemonics instead of bare opcodes. No functional change to the test. Correct register constraints. PD_START doesn't necessarily need to be in eax, but eax does need to identified as clobbered. As GAS is unable to express a register as an input and also clobbered, opt for an explicit eax clobber and allow some choice for the register used to pass PD_START (and indeed, objdump indicates that esi is chosen). ebx gains an early clobber to remove it from the candidate list for PD_START. Signed-off-by: Andrew Cooper CC: Keir Fraser CC: Jan Beulich CC: Tim Deegan CC: Ian Campbell CC: Ian Jackson --- v2: Include register constraint fixes as suggested by Jan --- tools/firmware/hvmloader/tests.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/firmware/hvmloader/tests.c b/tools/firmware/hvmloader/tests.c index 52772aa..931ed2f 100644 --- a/tools/firmware/hvmloader/tests.c +++ b/tools/firmware/hvmloader/tests.c @@ -135,7 +135,7 @@ static int rep_io_test(void) static int shadow_gs_test(void) { uint64_t *pd = (uint64_t *)PD_START; - uint32_t i, eax, ebx, ecx, edx; + uint32_t i, eax, ebx, ecx, edx, dummy; /* Skip this test if the CPU does not support long mode. */ cpuid(0x80000000, &eax, &ebx, &ecx, &edx); @@ -158,7 +158,7 @@ static int shadow_gs_test(void) "mov $0x20,%%ebx; " "mov %%ebx,%%cr4; " /* CR3 */ - "mov %%eax,%%cr3; " + "mov %0,%%cr3; " /* EFER.LME=1 */ "mov $0xc0000080,%%ecx; rdmsr; btsl $8,%%eax; wrmsr; " /* CR0.PG=1 */ @@ -170,12 +170,14 @@ static int shadow_gs_test(void) /* Push LRETQ stack frame. */ "pushl $0; pushl $"STR(SEL_CODE32)"; pushl $0; pushl $2f; " /* Jump to 64-bit mode. */ - "ljmp $"STR(SEL_CODE64)",$1f; 1: " + "ljmp $"STR(SEL_CODE64)",$1f; " + ".code64; 1: " /* Swap GS_BASE and SHADOW_GS_BASE */ - ".byte 0x0f,0x01,0xf8; " /* SWAPGS */ + "swapgs; " /* Jump to 32-bit mode. */ - ".byte 0x89, 0xe4; " /* MOV ESP,ESP */ - ".byte 0x48, 0xcb; 2: " /* LRETQ */ + "movl %%esp,%%esp; " + "lretq; " + ".code32; 2:" /* Read SHADOW_GS_BASE: should now contain 2 */ "mov $0xc0000102,%%ecx; rdmsr; mov %%eax,%%ebx; " /* CR0.PG=0 */ @@ -185,7 +187,9 @@ static int shadow_gs_test(void) "mov $0xc0000080,%%ecx; rdmsr; btcl $8,%%eax; wrmsr; " /* CR4.PAE=0 */ "xor %%eax,%%eax; mov %%eax,%%cr4; " - : "=b" (ebx) : "a" (PD_START) : "ecx", "edx", "memory" ); + : "=r" (dummy), "=&b" (ebx) + : "0" (PD_START) + : "eax", "ecx", "edx", "memory" ); return (ebx == 2) ? TEST_PASS : TEST_FAIL; } -- 1.7.10.4