Disabling local optimizations with GCC

The Chazman chaz@devastator.extern.ucsd.edu
Wed Jun 28 22:20:00 GMT 2000


> Here's my problem:
> I'm using a cross-compiler under Windows 98/NT for an m68k-coff target
> (MC68306). I have certain symbols mapped to specific hardware addresses
> so that I can interact with the hardware (as I assume most would do it).
> In some cases I assign different values to the same address in
> succession, or intermixed with the assignment of values to other
> addresses. It is important for all assignments to occur because each one
> causes the hardware to perform a particular action, and all actions need
> to occur in the order I've placed them in the C-language functions. The
> problem is that with any GCC optimization level  (-O, -O1, -O2, or -O3),
> it "optimizes" out all but the last assignment to a given location. This
> causes my program not to work. Everything seems to be fine if I disable
> all optimizations, but some parts of my program are time-critical and I
> may need some of the optimizations for the program to work right.
>
> Here is some example code:
> _____________________________________________________________
> /* duart's base i/o address */
> #define IoPortAddr   ((BYTE*)0xa0001)

Stop right there.  Change this to:

#define IoPortAddr  ((volatile BYTE*)0xa0001)

It's imperative that you define all hardware registers volatile.
This tells the compiler that these variables/addresses either:
  1) produce side-effects when written, thus back-to-back writes
     must be preserved, or
  2) may change values due to external causes, thus reads must
     not be cached in CPU registers for future use, or
  3) both.

Try that and see how it goes.


-------------------------------------------
Carl Miller               Firmware Engineer
chaz@gordian.com              Gordian, Inc.
(714) 850-0205       http://www.gordian.com
personal: chaz@devastator.extern.ucsd.edu

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com



More information about the crossgcc mailing list