qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCH] kvm-unittest: fix build with gcc 4.3.X and older
Date: Thu, 17 Oct 2013 11:12:31 +0300	[thread overview]
Message-ID: <20131017081231.GA13975@redhat.com> (raw)
In-Reply-To: <20131017062751.GK15657@redhat.com>

On Thu, Oct 17, 2013 at 09:27:51AM +0300, Gleb Natapov wrote:
> 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.

Well it's not as widely used as kvm itself yet :)
The patch seems simple enough though.

> 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'

OK that's easy to fix.

> > 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.

It does produce warnings with -Wall though:
Assembler messages:
Warning: using `%ax' instead of `%eax' due to `w' suffix
Warning: using `%al' instead of `%eax' due to `b' suffix

So it's not the compiler, the compiler generated wrong
code with outb %eax. But assembler saw outb and %eax which
are inconsistent and decided that outb should take precedence.

I'm not sure it's wize to rely on this behaviour though.
How's this? This should fix 4.2 for you too.

Maybe we should tweak outb/outw as well to keep it
all consistent. I can do this - what do you think?


diff --git a/lib/x86/pci.c b/lib/x86/pci.c
index f95cd88..08f7ebf 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 %%eax, %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, %%eax" : "=a"(data) : "Nd"(port));
     return data;
 }
 static uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg)
diff --git a/x86/s3.c b/x86/s3.c
index 1feb452..bfa4206 100644
--- a/x86/s3.c
+++ b/x86/s3.c
@@ -142,15 +142,15 @@ u32* find_resume_vector_addr(void)
 static inline int rtc_in(u8 reg)
 {
     u8 x = reg;
-    asm volatile("outb %b1, $0x70; inb $0x71, %b0"
-		 : "+a"(x) : "0"(x));
+    asm volatile("outb %%al, $0x70; inb $0x71, %%al"
+		 : "+a"(x));
     return x;
 }
 
 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));
+    asm volatile("outb %%al, $0x70; mov %b1, %%al; outb %%al, $0x71"
+		 : "+a"(reg) : "ri"(val));
 }
 
 extern char resume_start, resume_end;
diff --git a/x86/vmexit.c b/x86/vmexit.c
index 3b945de..29bc582 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 %%eax, %w1" : : "a"(val), "Nd"(port));
 }
 
 static unsigned int inb(unsigned short port)


-- 
MST

  reply	other threads:[~2013-10-17  8:28 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-16 19:46 [Qemu-devel] [PATCH] kvm-unittest: fix build with gcc 4.3.X and older Michael S. Tsirkin
2013-10-17  6:27 ` Gleb Natapov
2013-10-17  8:12   ` Michael S. Tsirkin [this message]
2013-10-17  8:20     ` Gleb Natapov
2013-10-17  8:27       ` Michael S. Tsirkin
2013-10-17  8:34         ` Gleb Natapov
2013-10-17  9:28           ` Michael S. Tsirkin
2013-10-17  9:33             ` Gleb Natapov
2013-10-17  9:44               ` Michael S. Tsirkin
2013-10-17  9:43                 ` Gleb Natapov
2013-10-17 10:55   ` Paolo Bonzini
2013-10-17 10:58     ` Gleb Natapov
2013-10-17 11:02       ` Paolo Bonzini
2013-10-17 11:31         ` Michael S. Tsirkin
2013-10-17 10:53 ` Paolo Bonzini
2013-10-17 11:29   ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131017081231.GA13975@redhat.com \
    --to=mst@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).