We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello. I want to relocate some function’s from Flash to a different position in PSRAM for a bootloader.
The problem is: Keil generates absolute jumps in the original function. With relative jumps whould it work.
I have copied the original functions to the RAM like this: ------------ Flash function a at 0xC01000 ------------ Flash function b at 0xC02000 ------------ Flash function c at 0xC02800 ->(to copy in RAM at 0xE00000) ------------
Now I copy the c-function from 0xC02800 to RAM at 0xE00000.
The Problem: In the function c is a IF cause, that jumps to the end of the function at 0xC02872:
JMPA cc_UC, 0xC02872 ( +72 Bytes)
If i execute this copied function at the new position (E00000), the jump is located to E02872
JMPA cc_UC, 0xE02872 ( + 2872 Bytes)
and not to 0xE00072 ( + 72 Bytes).
Is there a compiler switch to generate relative jumps (JMPR, CALLR) instead to absolute Jumps (JMPA+,JMPA-,CALLA)?
Or is there a other solution for this problem?
(I need to use the HCompact model, to access all functions and the whole address-space for variables.)
Thanks
This article may help
http://www.keil.com/support/docs/335.htm
Hello.
>>this article may help I've read the article, but is doesn't solve the problem. Even in a small memory modell, Keil generates absolute CALL's and Jump's.
That means: i have to inspect the Code in RAM and search for 0xCA ( CALLA xxxx ) to patch the following adress.
Than i have to hope an pray, that it is really a call and not normal code like: Mov R4, #0CAH
That's realy not the solution.
I also found this, it's old but I would assume it still applies. It seems to confirm that the compiler will not generate code that is guaranteed to be relocatable.
http://www.keil.com/forum/docs/thread122.asp
Maybe the APNT_138 will solve your problem (http://www.keil.com/appnotes/files/apnt_138.pdf). A few years ago i programmed a flashbootloader for the ST10F27x series. While programming the flash this controller is not able to fetch code from it. That's why the flash routines must run in RAM.
I used the L166 SECTION dircetive. With this directive you can configure seperate execution and storage adress for your code. Before execution of the code you must manually copy this code into RAM.
No. It means you have to stop what you're doing and reconsider how you got there. If the compiler won't generate position-independent code, then you can't assume you can use position-independent code unless you're prepared to write it yourself --- in assembler.
Instead, you can compile (and link) your code for its actual run-time location, but tell the linker to store it elsewhere in the image. Then you copy it to its target location before you run it. I'll assume Keil's C16x linkers have support for that.