[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] Function pointer problem
From: |
Thomas Olsson |
Subject: |
[avr-gcc-list] Function pointer problem |
Date: |
Sat, 2 Oct 2004 16:09:11 +0200 |
Hi,
I hope someone can help with this. I have been through most of the internet
looking for an answer, but I haven't found anything matching the problem.
Basically, I want function pointers to work correctly. It's not the old
"function pointer in progmem" problem, since these are stored in RAM.
The function itself is obviously in progmem, but GCC seems to be confused
about this, and whenever the function pointer is assigned to something, it
uses some other address instead. I haven't been able to find out what the
wrong address points at, but it sure isn't the function in progmem.
Here is a simplified way to produce the problem:
- - - cut - - -
void (*code)(byte arg);
void code_test(char arg)
{
}
void code_init(void)
{
code = code_test;
code(1);
}
- - - cut - - -
This produces the following code:
0000011e <code_test>:
11e: 08 95 ret
00000120 <code_init>:
120: 8f e8 ldi r24, 0x8F ; 143
122: 90 e0 ldi r25, 0x00 ; 0
124: 90 93 19 01 sts 0x0119, r25
128: 80 93 18 01 sts 0x0118, r24
12c: 81 e0 ldi r24, 0x01 ; 1
12e: 0e 94 8f 00 call 0x11e
132: 08 95 ret
As you can see, GCC has discovered that "code" is constant, so it calls the
right address (0x11e). But the value stored in the pointer is 0x8f, which
is the problem (in the real code, it would not be a constant, and 0x8f
would be indirectly called instead).
I have already tried nearly all combinations of:
* Storing the function pointer, the implicit function pointer, and the
address of either.
* With and without various typedefs.
* Casting to void *, int, and more.
* Variations with and without __attribute__((__progmem__)) in all sorts of
weird places.
* -O1, -O2 and no -O
It always produces the wrong address, I have not been able to change that
at all.
For the record, this is GCC-avr 3.4.1.
Thanks in advance for any suggestions,
Thomas.
--
9876543210 Magic tab-o-meter. http://www.armware.dk/
^
- [avr-gcc-list] Function pointer problem,
Thomas Olsson <=