This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
RE: structure size
- From: "Olaf Peters" <olaf dot peters at technolution dot nl>
- To: "Bart Veer" <bartv at ecoscentric dot com>,<grante at visi dot com>
- Cc: <ecos-discuss at sources dot redhat dot com>
- Date: Tue, 6 Jan 2004 18:05:50 +0100
- Subject: RE: [ECOS] 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