On 12/05/2011 17:24, fanqifei wrote:
I am using gcc4.3.2.
In our microcontroller, move instruction(mov reg, imm) can accept
16bits and 32bits immediate operand.
The data memory size is less than 64KB, however, code memory size is
larger than 64KB.
The immediate operand may be addresses of variables in data sections
and function pointers. The address of variables can be represented by
16bits. However, function pointers may be larger than 16bits.
I'd like to use "mov reg, imm16" for addresses of variables and "mov
reg, imm32" for function pointers. So that the code size can be a
little bit smaller.
Another way to understand the requirement is the size of pointers to
data and text have to be different.
How can I select appropriate mov for them? I tried to use LABEL_REF
and SYMBOL_REL to distinguish between them, but it didn't help. It
seems that function pointers are treated as symbols too.
Are there any other cases that references to functions in text
sections are used in data sections?
Thanks.
-Qifei Fan
Another option that is sometimes used in such circumstances is
trampolines. For each function "foo" whose address is taken, you create
a trampoline "foo_jump" with a single long-jump instruction to the real
"foo". When code takes the address of "foo", it actually gets the
address of "foo_jump". You then use linker magic to ensure that all
_jump functions are placed in the low 64K of code memory. With this
arrangement, function pointers are then all 16-bit - it's easier on the
rest of the code, and results in less ram usage and typically also less
code space.
I /believe/ this is how it is done on the AVR target, though I can't
remember for sure.