[ECOS] structure size

Olaf Peters olaf.peters@technolution.nl
Tue Jan 6 17:05:00 GMT 2004

> Try the following:
> ------------------------------------------------------------------
> struct xyzzy {
>     short   a;
>     int     b;
> } __attribute__((packed));
> struct xyzzy data;
> int
> fred(void)
> {
>     data.b  = 42;
> }
> ------------------------------------------------------------------
> Compile with arm-elf-gcc -S. The assignment to data.b is implemented
> using four separate strb instructions, as I would expect. If you try
> reading data.b instead there will be four ldrb instructions plus
> appropriate manipulation.

I noticed this behaviour too. But if you add a call to a function with a
pointer to the unaligend member, things still go wrong because of an
unaligned accesses.

int assign42 (int *p)
    *p = 42;


I noticed this on an ARM7 core in the NetSilicon NET+50 chip. However,
that processor can generate a data-abort trap if an unaligned data access
takes place. I used that trap to simulate the actual instruction
and to assign the correct data. It works fine, but is probably not a
generic solution.


Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

More information about the Ecos-discuss mailing list