WLAN from SDIO to SPI: battle plan

Andy Green andy at openmoko.com
Thu Aug 28 19:03:51 CEST 2008

Hash: SHA1

Somebody in the thread at some point said:
| Am Mi  27. August 2008 schrieb Andy Green:
|> Somebody in the thread at some point said:
|> | HI:
|> |   Yes. it works after remove "__attribute__((__packed__))"
|> |
|> | #arm-angstrom-linux-gnueabi-objdump -d ./cpu/arm920t/s3c24x0/spi.o
|> |   ....
|> |   d0:	e59d2004 	ldr	r2, [sp, #4]
|> |   d4:	e3a0304f 	mov	r3, #79	; 0x4f
|> |   d8:	e582300c 	str	r3, [r2, #12]
|> |   dc:	e59d2004 	ldr	r2, [sp, #4]
|> |   e0:	e3a03001 	mov	r3, #1	; 0x1
|> |   e4:	e5823008 	str	r3, [r2, #8]
|> |   e8:	e59d2004 	ldr	r2, [sp, #4]
|> |   ec:	e283301e 	add	r3, r3, #30	; 0x1e
|> |   f0:	e5823000 	str	r3, [r2]
|> |   f4:	e3a01000 	mov	r1, #0	; 0x0
|> |   f8:	e2811001 	add	r1, r1, #1	; 0x1
|> |   fc:	e59d2004 	ldr	r2, [sp, #4]
|> |  100:	e3a030ff 	mov	r3, #255	; 0xff
|> |
|> |   I see the same problem, if use "__packed__" attribute,  GCC
|> | will compile with byte-access code which may takes more
|> |  instruction. Say, update a counter, and it can't keep it ATOMIC
|> | may produce race, or data corrupt.
|> You need __packed__ if the start of your struct pointer may not be
|> aligned to 32-bit boundary, but you want to access 32-bit items in
|> there.  This happens in network processing code for example, the struct
|> representing the packet payload can easily be at funny alignment due to
|> snipped headers from earlier protocols.
|> You don't need it for dealing with a bunch of 32-bit registers always
|> found on 32-bit boundaries.
| I remember when writing TTY-driver code in assembler for BS2000 back
in 1985,
| there were all sorts of PACK and ALIGN16 and ALIGN32 directives to
cope with
| that. There was good reason they were there.
| Think in COBOL-M there were similar options for data and linkage section.
| Just a nearly OT annotation ;-) Sorry couldn't resist as these low-level
| machine interfaces were my favorite battlefield

Those align things are still alive and well in linker scripts FWIW.  But
this is actually different story.

The problem comes when the guys you need aligned are inside a struct
that does correctly position them at alignment boundary -- relative to
struct start.  If the address of the start of the struct is not itself
aligned to the machine word size though, that doesn't help at all.

So a u32 at +8 from the struct start looks like it follows the rules
great, but if the struct pointer is pointing to 0x1, you are screwed
when you try to dereference that u32 in one 32-bit access at 0x9.
__packed__ is magic get out of jail card for that case.

- -Andy
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org


More information about the openmoko-kernel mailing list