I seem to be running afoul of a bug in the avr-gcc that is packaged up
with avr-gcc-3.4.3-1.i386.rpm. The bug is nasty and results in indirect
calls to neverneverland.
A program that trips this bug is attached.
Compiling like this:
avr-gcc -Wall -mmcu=atmega128 -Os shifty.c -o shifty.elf
generates a program that icalls to a bad address.
If you have Avrora installed this command:
java avrora.Main -colors=false -simulation=sensor-network -mcu=atmega128
-seconds=30 shifty.elf
will cause an exception in the simulator.
On the other hand, compiling the same program with -O instead of -Os
results in correct code.
The problem occurs when the Z register is loaded with the address of
foo(). In the buggy (-Os) version, the literal address of foo() is
loaded. This is wrong because the Atmega128 PC addresses 16-bit
locations, in order to reach all 2^17 bytes of flash. In the correct
(-O) version, Z is loaded with 1/2 of the address of foo().
Just wanted to make sure this is known, it was not fun to track down.
If a workaround exists I'd be happy to hear about it.
Thanks,
John Regehr
struct bar
{
void *yyy;
void *aaa;
};
void foo (void)
{
}
void stuff (void)
{
struct bar back[2];
void (*p) (void) = foo;
back[0].aaa = (void *) (&foo + 1);
int i;
for (i=0; i<6; i++) {
back[0].aaa = back[0].yyy;
}
(*p)();
}
int
main (void)
{
stuff ();
return 0;
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help