preventing optimization in gcc 2.95.1

Jens Heilig jens.heilig@gmx.de
Wed Sep 29 07:04:00 GMT 1999


I use gcc as a cross-compiler for an embedded m68k target.

For access to memory-mapped IOs I defined two macros:
#define pBYTE(x) (*((ubyte *) (x)))
#define pWORD(x) (*((ushort *)(x)))

for 8 or 16-bit access (read and write access!).

Now, in case I wait for an I/O port to obtain a certain state, I use
code like
while (!( pWORD(SCSR) & 0x0100 ));

This does not work if I use -O or -O2 when compiling. The resulting
assembler code then becomes
0030759C: MOVE.W  0xFFFC0C.W,D0
003075A2: ANDI.W  #0x100,D0
003075A6: TST.W   D0
003075A8: BEQ.B   0x3075A6

Clearly, this cannot work. I tried adding casts to volatile in various
parts of the #define statements, but to no avail. Only when I declare
SCSR as
volatile long SCSR=0xFFFC0C does it work. Of course, I don't want to
find all the hundreds of lines in the code, that make use of the pWORD
macro and change them all (this project is migrating from another
compiler)

Does anybody know what I can do to make pBYTE and pWORD work as
expected? I guess the main problem is, that pBYTE can also be an
L-value, like in pBYTE(ADDRESS)=0;

Any help is appreciated!
jens


More information about the Gcc-help mailing list