Sometimes it's necessary to move code into RAM for execution, for instance 
when reprogramming the main flash. It isn't too hard to do this in C, by 
compiling all the code to be moved into a special section within .text, then 
copying the whole section to RAM. Of course the code moved has to be 
position-independent. 

The global compiler option -fpic simply accesses all constant addresses via a 
table in RAM. This table can be quite large, and may be overwritten when the 
code is moved. Using it is pretty clumsy.

If one avoids static variables, most of the code is position-independent 
anyway. The difficulty lies in function calls. MSP430-gcc compiles these 
with an absolute address, allowing calls to any place in memory. That's 
normally exactly what one wants, but when the code is moved the calls still 
address flash.

It would be good to write a macro to use the PC-relative 'symbolic" 
addressing mode, something along the lines of:

#define PI_CALL(f) asm("call %0"::"?"(f))

but there seems to be no constraint which generates the right addressing 
mode. Am I missing something really obvious here?
-- 
Rick Jenkins <r...@hartmantech.com>
Hartman Technica           http://www.hartmantech.com 
Phone +1 (403) 230-1987 voice & fax
221 35 Avenue. N.E., Calgary, Alberta, Canada T2E 2K5

Reply via email to