S
Samuel Stearley
Stephen said:Declare the variables to be volatile and the compiler won't be allowed
to play games with the ordering.
I wouldn't rely on that. I might be wrong but I think the only
consequence of volatile is to keep the compiler from optimizing away
reads
For the powerPC here's what we do at work to make sure memory mapped
IO registers are accessed in proper order.
1) proper setup of dbat registers. The dbats define attributes for
very larger areas of physical address space. We make sure that they
define it as cache inhibited and as guarded.
2) we don't use expressions like *ptr =value. we call functions like
DWordWrite(UINT32 * ptr, value). The ptr is cast as pointing to a
volatile UINT32 * (I think this is pedantic), the data is written, then
we use some inline asm and force the eieio instruction. To quote the
PPC docs:
"Loads and stores to memory that is both caching-inhibited and guarded,
and stores to memory that is write-through required. The eieio
instruction controls the order in which the accesses are performed in
main memory. It ensures that all applicable memory accesses caused by
instructions preceding the eieio instruction have completed with
respect to main memory before any applicable memory accesses caused by
instructions following the eieio instruction access main memory. It
acts like a barrier that flows through the memory queues and to main
memory, preventing the reordering of memory accesses across the
barrier. No ordering is performed for dcbz if the instruction causes
the system alignment error handler to be invoked."
I hope this helps. If your platform is x86 try to find the equivalent.