Mail Archives: djgpp/1997/01/31/03:00:35
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 -