This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: code optimizations


On Thu, Aug 23, 2001 at 09:32:20AM -0600, Trenton D. Adams wrote:

> Here's some output from my stepping through my pc-controller
> driver I'm making.  Notice how the code jumps back and forth?
> This shouldn't happen should it?

It is allowed to happen according to the C standard.

> My hardware is supposed to be initialized in a specific order,
> not jump around.

Declare all your hardware registers as volatile.  That will
prevent the compiler from re-ordering the access:

 #define foo 0x7ff8005

 *(volatile unsigned*)foo = 0x12345678;


<pet peeve>

Personally, I think that addresses should be assigned to
objects by the linker, so I prefer this:

  extern volatile unsigned foo;
  
  foo = 0x12345678;  

Then assign an address to foo at link time.

However, that's not the standard eCos idiom.  Rather, putting
peripheral addresses in the source code seems to be the way
it's usually done in eCos HAL and drivers.

</pet peeve>


> If this occurs during debug, it would occur during a normal run
> too, wouldn't it?

Yes.

> I know we talked about this before, but this just seems really
> weird to me!  I never did show anyone this before so I thought
> I would give it a try.
> 
> How do I make the config tool allow me to specify different
> compiler options for my driver?  Is it a CDL thing?

Nope, it's a bug in your source code.  The compiler is
generating legal object code for the source it has been given.

Two statements with no interdependacies may be re-ordered by
the compiler if it so wishes.  Accessing a volatile object will
cause a "sequence point" to be placed before and after the
expression, which will prevent the compiler from moving that
expression when it optimizes code.  I'm sure somebody has a
pointer to a good C language reference, but I don't have one
handy.

-- 
Grant Edwards
grante@visi.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]