[U-Boot] __attribute__((__packed__)) switching to byte-access on ARM

Guennadi Liakhovetski lg at denx.de
Mon Aug 11 20:14:30 CEST 2008


On Mon, 11 Aug 2008, Kenneth Johansson wrote:

> On Mon, 2008-08-11 at 19:00 +0200, Guennadi Liakhovetski wrote:
> > On Mon, 11 Aug 2008, Kenneth Johansson wrote:
> > 
> > > On Mon, 2008-08-11 at 18:23 +0200, Guennadi Liakhovetski wrote:
> > > 
> > > > I cannot think of any such examples... I know access-types can be changed 
> > > > on the hardware, say, on a 16-bit bus a 32-bit access can be split into 
> > > > two 16-bit accesses, but I currently cannot think of any examples of the 
> > > > compiler doing such things. But, I think, I can imagine _why_ the compiler 
> > > > might decide to do that - it cannot guarantee, that the structure is 
> > > > 32-bit aligned, so, it is opting for the "safe" variant... So, the 
> > > > question is: is the compiler right and the c-code was wrong, or the other 
> > > > way round?
> > > 
> > > Both are "right" :). C has a lot of implementation specific stuff that
> > > can make life interesting. Simple thing like if char is signed or
> > > unsigned sometimes is really important. 
> > > 
> > > If you have to make sure that the read/write is done in 16 bit the only
> > > option is to use assembler code. 
> > 
> > I think, properly written mmapped-register access functions like readl() 
> > work perfectly too.
> 
> what does the compiler do if you change the code  to 
> 
>         return *(ulong*)&timers->TCNTO4;

Strangely, this doesn't help either... Nor does using 
readl(&timers->TCNTO4).

Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.

DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de



More information about the U-Boot mailing list