[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] tools/x86_64: Fix cpuid() inline asm to not clobber stack's red zone
# HG changeset patch # User Keir Fraser <keir@xxxxxxx> # Date 1322836274 28800 # Node ID 72f4e4cb7440c6ab64d4c08dfdc3158112cc95ac # Parent 109b99239b21275ee2249873dcdb9a413741142d tools/x86_64: Fix cpuid() inline asm to not clobber stack's red zone Pushing stuff onto the stack on x86-64 when we do not specify -mno-red-zone is unsafe. Since the complicated asm is due to register pressure on i386, we simply implement an all-new simpler alternative for x86-64. Signed-off-by: Keir Fraser <keir@xxxxxxx> Acked-by: Jan Beulich <jbeulich@xxxxxxxxxx> --- diff -r 109b99239b21 -r 72f4e4cb7440 tools/libxc/xc_cpuid_x86.c --- a/tools/libxc/xc_cpuid_x86.c Fri Dec 02 06:07:52 2011 -0800 +++ b/tools/libxc/xc_cpuid_x86.c Fri Dec 02 06:31:14 2011 -0800 @@ -43,23 +43,23 @@ static void cpuid(const unsigned int *input, unsigned int *regs) { unsigned int count = (input[1] == XEN_CPUID_INPUT_UNUSED) ? 0 : input[1]; +#ifdef __i386__ + /* Use the stack to avoid reg constraint failures with some gcc flags */ asm ( -#ifdef __i386__ "push %%ebx; push %%edx\n\t" -#else - "push %%rbx; push %%rdx\n\t" -#endif "cpuid\n\t" "mov %%ebx,4(%4)\n\t" "mov %%edx,12(%4)\n\t" -#ifdef __i386__ "pop %%edx; pop %%ebx\n\t" + : "=a" (regs[0]), "=c" (regs[2]) + : "0" (input[0]), "1" (count), "S" (_regs) + : "memory" ); #else - "pop %%rdx; pop %%rbx\n\t" + asm ( + "cpuid" + : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3]) + : "0" (input[0]), "2" (count) ); #endif - : "=a" (regs[0]), "=c" (regs[2]) - : "0" (input[0]), "1" (count), "S" (regs) - : "memory" ); } /* Get the manufacturer brand name of the host processor. */ diff -r 109b99239b21 -r 72f4e4cb7440 tools/misc/xen-detect.c --- a/tools/misc/xen-detect.c Fri Dec 02 06:07:52 2011 -0800 +++ b/tools/misc/xen-detect.c Fri Dec 02 06:31:14 2011 -0800 @@ -35,18 +35,21 @@ static void cpuid(uint32_t idx, uint32_t *regs, int pv_context) { +#ifdef __i386__ + /* Use the stack to avoid reg constraint failures with some gcc flags */ asm volatile ( -#ifdef __i386__ -#define R(x) "%%e"#x"x" -#else -#define R(x) "%%r"#x"x" -#endif - "push "R(a)"; push "R(b)"; push "R(c)"; push "R(d)"\n\t" + "push %%eax; push %%ebx; push %%ecx; push %%edx\n\t" "test %1,%1 ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid\n\t" "mov %%eax,(%2); mov %%ebx,4(%2)\n\t" "mov %%ecx,8(%2); mov %%edx,12(%2)\n\t" - "pop "R(d)"; pop "R(c)"; pop "R(b)"; pop "R(a)"\n\t" + "pop %%edx; pop %%ecx; pop %%ebx; pop %%eax\n\t" : : "a" (idx), "c" (pv_context), "S" (regs) : "memory" ); +#else + asm volatile ( + "test %5,%5 ; jz 1f ; ud2a ; .ascii \"xen\" ; 1: cpuid\n\t" + : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3]) + : "0" (idx), "1" (pv_context), "2" (0) ); +#endif } static int check_for_xen(int pv_context) _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |