[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bad volatile -mstrict-align code on powerpc on 4.0.2?



Can someone sanity check this and verify that I'm not doing anything stupid? This is gcc 4.0.2 compiled on solaris 10. It is generating wacky code with -mstrict-align unless I'm doing something dumb. In the following script it is generating reasonable code without - mstrict-align, when I turn on -mstrict-align it is amoungst other things reading back from the volatile register before writing to it. Is there another attribute I'm supposed to use?

Peter
Script started on Fri Nov 04 09:41:09 2005
+++CMD+++> cat foo.c
typedef unsigned short uint16_t;

struct foo_reg {
	uint16_t leds;		/**< The 16 LEDs on the side of the board. */
	uint16_t id_eaprom;	/**< The ID EAPROM. */
	uint16_t control;	/**< The control register. */
	uint16_t pad0;
} __attribute__((__packed__));

void foo(void);

void foo(void) {
	volatile struct foo_reg *fp = (volatile struct foo_reg *)0x9fff9800;
	fp->control = 0x00ff;
}
+++CMD+++> powerpc-rtems-gcc -O -c foo.c
+++CMD+++> powerpc-rtems-objdump --disassemble --source foo.o

foo.o:     file format elf32-powerpc

Disassembly of section .text:

00000000 <foo>:
   0:	3d 20 9f ff 	lis     r9,-24577
   4:	61 29 98 00 	ori     r9,r9,38912
   8:	38 00 00 ff 	li      r0,255
   c:	b0 09 00 04 	sth     r0,4(r9)
  10:	4e 80 00 20 	blr
+++CMD+++> powerpc-rtems-gcc -O -mstrict-align -c foo.c
+++CMD+++> powerpc-rtems-objdump --disassemble --source foo.o

foo.o:     file format elf32-powerpc

Disassembly of section .text:

00000000 <foo>:
   0:	3d 20 9f ff 	lis     r9,-24577
   4:	61 29 98 00 	ori     r9,r9,38912
   8:	88 09 00 04 	lbz     r0,4(r9)
   c:	38 00 00 00 	li      r0,0
  10:	98 09 00 04 	stb     r0,4(r9)
  14:	88 09 00 05 	lbz     r0,5(r9)
  18:	38 00 ff ff 	li      r0,-1
  1c:	98 09 00 05 	stb     r0,5(r9)
  20:	4e 80 00 20 	blr
+++CMD+++> 
script done on Fri Nov 04 09:41:58 2005