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]
Other format: [Raw text]

RE: structure size


> 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;
}

int
fred(void)
{
    assign42(&data.b);
}

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.

Olaf.


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


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