HC12: How do I compile relocatable functions?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

HC12: How do I compile relocatable functions?

跳至解决方案
3,985 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,805 次查看
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 项奖励
回复
5 回复数
1,805 次查看
xgater
Contributor I
Thanks, once again you've bailed me out. This is working well.
0 项奖励
回复
1,806 次查看
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 项奖励
回复
1,805 次查看
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 项奖励
回复
1,805 次查看
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
 
1,805 次查看
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 项奖励
回复