HC12: How do I compile relocatable functions?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HC12: How do I compile relocatable functions?

Jump to solution
2,862 Views
xgater
Contributor I
I am writing in Codewarrior v4.5 C for HCS12X cpu.
 
I am trying to make a few relocatable functions that I can copy to RAM and execute there. I have no problem with the copy and execute. The problem is that the compiler has used some JMP and JSR opcodes that make it non-relocatable. These are short jumps to the end of the function and for optimization of repetitive code but they are jumping to flash and not the RAM copy. How can I disable this and force the compiler to use relative branches (long or short as needed) instead of absolute jumps when I compile these functions?
 
...oh and NO I can NOT build the code to reside in RAM because the RAM location of the buffer may change in future versions so it MUST use relative branches.
 
I really don't want to have to re-write all of this in asm just to get it to run.

Message Edited by CrasyCat on 2007-04-13 01:21 PM

Message Edited by CrasyCat on 2007-04-13 01:21 PM

Labels (1)
Tags (1)
0 Kudos
1 Solution
682 Views
CompilerGuru
NXP Employee
NXP Employee
There's a PIC (position independend code) section qualifier:
(out of my memory, not tried)
#pragma CODE_SEG PIC REL_CODE
void fun(void) {
.......
}
#pragma CODE_SEG DEFAULT

I guess that's what you are looking for. With the RELOCATE_TO prm file syntax
it is also possible to link the code to a different place than it is executed from.

Daniel

View solution in original post

0 Kudos
5 Replies
682 Views
xgater
Contributor I
Thanks, once again you've bailed me out. This is working well.
0 Kudos
683 Views
CompilerGuru
NXP Employee
NXP Employee
There's a PIC (position independend code) section qualifier:
(out of my memory, not tried)
#pragma CODE_SEG PIC REL_CODE
void fun(void) {
.......
}
#pragma CODE_SEG DEFAULT

I guess that's what you are looking for. With the RELOCATE_TO prm file syntax
it is also possible to link the code to a different place than it is executed from.

Daniel
0 Kudos
682 Views
Scratch
Contributor I
Answers my question as well! (Also, you can find a technical note elsewhere on this site TN235 on the same subject).
(I am writing a "bootstrap" function to update the firmware remotely - did this previously on the HC11 where I ran the interface and flash program modules from RAM, allowing me to completely rewrite the code in FLASH.. I don't know if you are looking at a similar application?)
0 Kudos
682 Views
bigmac
Specialist III
Hello,
 
According to TN235, the PIC qualifier is not available for HC9(S)08.  So what is the solution for these devices?  Writing the relocatable code in assembler would seem to be the only workable arrangement.
 
Regards,
Mac
 
682 Views
CompilerGuru
NXP Employee
NXP Employee
PIC is not supported for the HC08, that's correct.
If you "just" have to execute your code from a specific known location in RAM, then using RELOCATE_TO does the trick, check TN228.

If you need real relocatable code (which can execute from any address) for a HC(S)08, then the only clean solution today is to use assembly, AFAIK. For smaller functions you could also check and hope (and configure up to some extend) that the compiler does not use any JMPs or JSRs. But that's more a (ugly) workaround, I know.

Daniel
0 Kudos