Message-ID: <32F2CAE9.DF5@rangenet.com> Date: Fri, 31 Jan 1997 22:47:37 -0600 From: Dan Hedlund Reply-To: markiv AT rangenet DOT com Organization: Range Net MIME-Version: 1.0 To: Shawn Hargreaves CC: djgpp AT delorie DOT com Subject: Re: Possible bug/misfeature in GCC References: <32F1A438 DOT 5509 AT rangenet DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Shawn Hargreaves wrote: > > Dan Hedlund writes: > >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; > >} > [...] > >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. > > This is correct behaviour on the part of gcc. In most cases that is a > valid optimisation, since you've told it what registers you change in > your asm routine, and it has no way of knowing that you are waiting for > an external hardware event. To make the optimiser leave your function > alone, you need to add the 'volatile' keyword. Look in > djgpp\include\inlines\pc.h for an example. In fact, why don't you just > use the inportb() from that header? I'm writing an OS, like every one else..., and it also happens when accessing cr0 and cr3. Thanks for refrenceing pc.h, I was putting the 'volatile' in the function definition. -- ***** *** ** ** Dan M. Hedlund ** ** ***** *** ** ** ** ** ** **** ** http://www.rangenet.com/markiv ** ** ** ** ** ** ** ** ** ******* ** **** ** ** ** ** ** *** ** ** ** ** ** ** ***** ** ** ** **