From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guillaume Rousse Subject: Re: porting xen-detect ASM code into a shared library Date: Thu, 10 Jul 2008 12:54:33 +0200 Message-ID: <4875EA69.5040109@inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir Fraser Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org Keir Fraser a =E9crit : >=20 >=20 > On 10/7/08 10:21, "Guillaume Rousse" wrote: >=20 >> I'm trying to port xen-detect.c ASM code into cfengine, which is >> currently build as a shared library. However, I'm facing a compilation >> error: >> misc.c: In function 'Xen_cpuid': >> misc.c:1376: error: can't find a register in class 'BREG' while >> reloading 'asm' >> misc.c:1376: error: 'asm' operand has impossible constraints >> >> From=20 >=20 > See tools/libxc/xc_cpuid_x86.c for an example of how to work around thi= s. > Essentially you turn the "=3Db" constraint into "=3Dr". You then push/p= op ebx > (to save/restore it) and you 'mov %%ebx,%1' to save away ebx's value be= fore > restoring its original value. Thanks, I see the idea, but I feel like a typing monkey here because of=20 the unknown syntax. Is this supposed to be OK ? void Xen_cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { asm volatile ( "test %1,%1 ; jz 1f ; ud2a ; .ascii \"xen\" ;" #ifdef __i386__ "push %%ebx; cpuid; mov %%ebx,%1; pop %%ebx" #else "push %%rbx; cpuid; mov %%ebx,%1; pop %%rbx" #endif : "=3Da" (*eax), "=3Dr" (*ebx), "=3Dc" (*ecx), "=3Dd" (*edx) : "0" (idx), "1" (0) ); } Also, the final line was originally: : "0" (idx), "1" (pv_context) ); I turned it into the current way because I don't need the check in pv=20 context, but I guess it might be simplified. --=20 Guillaume Rousse Moyens Informatiques - INRIA Futurs Tel: 01 69 35 69 62