delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/31/03:00:35

Message-ID: <32F1A438.5509@rangenet.com>
Date: Fri, 31 Jan 1997 01:50:16 -0600
From: Dan Hedlund <markiv AT rangenet DOT com>
Reply-To: markiv AT rangenet DOT com
Organization: Range Net
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Possible bug/misfeature in GCC

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.

I've also had a few problems with the -O2 option, but they are more
difficult to reproduce.  The problem goes away if I use the -O0 option
or comment the portion of the code that uses inportb.  GCC also seems to
produce incorrect code when accessing the control registers (cr0 and
cr3).

-- 

*****      ***   **    **       Dan M. Hedlund
 ** **    *****  ***   **       <markiv AT rangenet DOT com>
 **  **  **   ** ****  **       http://www.rangenet.com/markiv
 **   ** **   ** ** ** **
 **   ** ******* **  ****
 **  **  **   ** **   ***
 ** **   **   ** **    **
*****    **   ** **    **

- Raw text -


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