My program is broken because mspgcc 3.2.3 is generating
unaligned word accesses. I'm calling memset() and memcpy()
fill in the fields in a packed struct. Since I've requested a
2-byte copy/set mspgcc is optimizing some of those memset() and
memcpy() calls into mov.w instructions, but the destination
address isn't word aligned, so the generated code is not
correct.
Here's a sample program that demonstrates the memset() bug.
$ msp430-gcc --version
msp430-gcc (GCC) 3.2.3
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
------------------------------bug.c------------------------------
struct foo
{
unsigned char b1;
unsigned u;
unsigned char b2;
} __attribute__((__packed__));
struct foo foo;
void bar(void)
{
memset(&foo.u, 0x55, 2);
}
------------------------------bug.c------------------------------
$ msp430-gcc -mmcu=msp430x148 -c -O3 -S bug.c
------------------------------bug.s------------------------------
.file "bug.c"
.arch msp430x148
[...]
bar:
/* prologue: frame size = 0 */
.L__FrameSize_bar=0x0
.L__FrameOffset_bar=0x0
/* prologue end (size=0) */
mov #llo(21845), &foo+1
ret
/* epilogue: not required */
/* function bar size 4 (3) */
.Lfe1:
.size bar,.Lfe1-bar
/********* End of function ******/
.comm foo,4,2
[...]
------------------------------bug.s------------------------------
Has this been fixed in newer versions?
--
Grant Edwards grante Yow! A dwarf is passing
at out somewhere in Detroit!
visi.com