From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWlEk-00058e-PJ for qemu-devel@nongnu.org; Thu, 17 Oct 2013 06:55:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VWlEe-0000Vf-OU for qemu-devel@nongnu.org; Thu, 17 Oct 2013 06:55:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9272) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWlEe-0000Vb-G7 for qemu-devel@nongnu.org; Thu, 17 Oct 2013 06:55:20 -0400 Message-ID: <525FC214.4020501@redhat.com> Date: Thu, 17 Oct 2013 12:55:16 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <20131016194653.GA10517@redhat.com> <20131017062751.GK15657@redhat.com> In-Reply-To: <20131017062751.GK15657@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] kvm-unittest: fix build with gcc 4.3.X and older List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gleb Natapov Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, "Michael S. Tsirkin" Il 17/10/2013 08:27, Gleb Natapov ha scritto: > On Wed, Oct 16, 2013 at 10:46:53PM +0300, Michael S. Tsirkin wrote: >> Old GCC didn't let you reference variable by >> number if it is listed with a specific register >> constraint, on the assumption you can just >> use the register name explicitly. >> >> Build fails with errors like this: >> a.c:6: error: invalid 'asm': invalid operand code 'd' >> > Is it worth to support such ancient compiler? Nobody complained till > now. BTW with your patch I still cannot compile with 4.2: > > x86/s3.c: In function 'main': > x86/s3.c:145: error: inconsistent operand constraints in an 'asm' > >> To fix, let's just use %eax %al etc. >> > Only %d0 does not work and dropping "d" fixes it since compiler can > figure out correct register from variable size. The patch bellow fixes > compilation for 4.2. > > diff --git a/lib/x86/pci.c b/lib/x86/pci.c > index f95cd88..231668a 100644 > --- a/lib/x86/pci.c > +++ b/lib/x86/pci.c > @@ -3,13 +3,13 @@ > > static void outl(unsigned short port, unsigned val) > { > - asm volatile("outl %d0, %w1" : : "a"(val), "Nd"(port)); > + asm volatile("outl %0, %w1" : : "a"(val), "Nd"(port)); > } > > static unsigned inl(unsigned short port) > { > unsigned data; > - asm volatile("inl %w1, %d0" : "=a"(data) : "Nd"(port)); > + asm volatile("inl %w1, %0" : "=a"(data) : "Nd"(port)); > return data; > } This is okay. > static uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg) > diff --git a/x86/s3.c b/x86/s3.c > index 71d3ff9..d568aa7 100644 > --- a/x86/s3.c > +++ b/x86/s3.c > @@ -143,14 +143,14 @@ static inline int rtc_in(u8 reg) > { > u8 x = reg; > asm volatile("outb %b1, $0x70; inb $0x71, %b0" > - : "+a"(x) : "0"(x)); > + : "=a"(x) : "0"(x)); > return x; > } This should be wrong. GCC should complain that the same operand is used for both input and output but has an "=" constraint. > static inline void rtc_out(u8 reg, u8 val) > { > asm volatile("outb %b1, $0x70; mov %b2, %b1; outb %b1, $0x71" > - : "+a"(reg) : "0"(reg), "ri"(val)); > + : "=a"(reg) : "0"(reg), "ri"(val)); > } Same here. But I'm not sure what is the error message for older GCC for s3.c, as I wrote in reply to Michael. > extern char resume_start, resume_end; > diff --git a/x86/vmexit.c b/x86/vmexit.c > index 3b945de..7e9af15 100644 > --- a/x86/vmexit.c > +++ b/x86/vmexit.c > @@ -26,7 +26,7 @@ static void outw(unsigned short port, unsigned val) > > static void outl(unsigned short port, unsigned val) > { > - asm volatile("outl %d0, %w1" : : "a"(val), "Nd"(port)); > + asm volatile("outl %0, %w1" : : "a"(val), "Nd"(port)); > } Okay. Paolo > static unsigned int inb(unsigned short port) > -- > Gleb. >