delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/02/19:43:35

From: brennan AT news DOT rt66 DOT com (Brennan "The Rev. Bas" Underwood)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Possible bug/misfeature in GCC
Date: 2 Feb 1997 16:16:20 -0700
Organization: Acid Brain
Lines: 43
Distribution: world
Message-ID: <5d3784$h37$1@mack.rt66.com>
References: <32F1A438 DOT 5509 AT rangenet DOT com>
NNTP-Posting-Host: mack.rt66.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <32F1A438 DOT 5509 AT rangenet DOT com>,
Dan Hedlund  <markiv AT rangenet DOT com> wrote:
>The following lines compile wrong with the -O3 option.
>
>unsigned char inportb (int port)
>{
>  unsigned char c;
>  asm ("inb     %%dx, %%al"
>      : "=a" (c)
>      : "d" (port));
>  return c;
>}
>
>void main (void)
>{
>  while (inportb (0));
>}
>
>GCC reads a byte from port 0 only once, and then compars that byte to 0
>in an endless loop.  Apparently GCC thinks the byte retrieved from the
>port doesn't change.

You need a 'volatile' on that asm there. i.e.


extern __inline__ unsigned char
inportb (unsigned short _port)
{
  unsigned char rv;
  __asm__ __volatile__ ("inb %1, %0"
          : "=a" (rv)
          : "d" (_port));
  return rv;
}

That's from pc.h. Just #include <pc.h> and it'll be correctly handled.


Brennan
-- 
 brennan AT rt66 DOT com |  Ding-a-ding-dang my dang-a-long-ling-long.
Riomhchlaraitheoir|  
   Rasterfarian   |  <http://brennan.home.ml.org>                          -O

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019