Relocatable Code...help please

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

Relocatable Code...help please

3,406 Views
Andy049
Contributor I
I am using Codewarrior IDE HC(s)08 and a HC908AP64. I am having problems with some syntax and would really appreciate any help, hints, guess, or just discussion.

I need to write a routine which will be located in section oxF400, but is made to run in section 0x500(which is RAM). During execution, code from 0xF400 will be copied to 0x500 and then ran. Does anyone know how to set up the linker to accomplish this?

Again any help would be great.

-Andy
Labels (1)
Tags (1)
0 Kudos
5 Replies

581 Views
CrasyCat
Specialist III
Hello
 
The attached technical note explains how to run portion of code from RAM.
I am wondering whether it does not help fixing your problem?
 
Depending on the version of CodeWarrior you are using the Technical notes may be installed on top of your installation or are available on the installation CD.
 
I hope this helps.
 
CrasyCat
0 Kudos

581 Views
Andy049
Contributor I
Thanks for the reply,

I understand what you are saying, but not sure if it applies to what I am doing...

I am writing a Mass erase routine that, when called, will Move a entire section of code (oxF400) into Ram (ox500) and execute. The code consist of Mass erasing the chip, and then re writing new data into the chip, by receiving incoming bytes from the SCI channel. All this needs to be in RAM.

I can simply load that code into RAM and jmp to the start of it, but the section of code is large, and my the BSR and BRA(inside the code being moved)are not big enough.

essentially I would like to have two completely different programs in one chip. When asked to, the second program will load itself into it's proper location and run. The problem I don't understand is, how to keep the assembly from remapping all the jmps and JSR to it's location in Flash(the storage location not the executing location).

If you can just confirm that your post works for mine, then you are life saver and I owe you. If not, do you (or anyone) have any ideas where I could look.

Is their a name for what I am just to do? Other IDEs have called it Locator controls, or even code stacking, I have no idea what Freescale calls it.


Andy
0 Kudos

581 Views
rocco
Senior Contributor II
Hello again, Andy:

Yes, the technique I outlined would work for you, but it is not the best way to do it when the amount of code is large.

I have handled the "branch out of range" issue by leap-frogging branches. But it's inefficient, hard to maintain, and ugly.

Another way to do it if to build the code for the address where it is destined to run. In your case, you would simply ORG it at $500 for the sake of the assembler, but then put it in flash at $F400 when you program the chip. Easier said than done.

Unfortunately, The only way I know to do that is by editing the .s19 file, changing the addresses where the routine will be loaded. A search and replace of "S12305" to "S123F4" would do the trick, if you then added 0x11 (the one byte difference between 0x05 and 0xF4) to the last byte in each line (the checksum). You may have to manually change the last line of the routine, since it may be shorter than the others, and the byte count (the third and fourth characters) would be something other than "23".

CodeWarrior may have a way to do this for you, but I can't help you there, since I don't use it. But the Freescale linker for the DSP563xx does have the capability to remap load addresses, so CodeWarrior should as well.
0 Kudos

581 Views
bigmac
Specialist III

Hello,

I wonder if the following approach might work to implement the modification of the S19 file generated for the code to operate from RAM - that is to use readily available utilities to convert from S19 to binary image, and then back again to S19 using a different address offset value.

Another possibility might be to convert the binary image to a sequence of DC.B directives that can be appropriately ORGed, and assembled, buy not sure if a utility is available to do this.

Regards,
Mac

 

0 Kudos

581 Views
rocco
Senior Contributor II
Hi, Andy:

Assuming you are using assembler, then it is not that hard. The main thing to keep in mind is that only the branch instructions are relative, all other instructions are not. So the following rules apply:

The addresses of your data will not relocate. The data that your routine accesses will access at the addresses defined when you compile. (More on this later).

JMP instructions use absolute addressing, so they cannot occur in a relocatable routine. Use BRA instead.

The call to the routine has to use a re-mapped address. You can re-map it using an EQU directive. To allow the routine "Groan", somewhere in the 0xF400 block of flash to be executed at the address "moved_Groan" in the 0x500 block of ram, you can define it this way:
moved_Groan:    equ     Groan-$F400+$500
You would then call the subroutine by using the new address:
        jsr        moved_Groan
I personally would use equates instead of hard-coded addresses:
RamBase:        equ     $500
FlashBase:      equ     $F400
moved_Groan:    equ     Groan-FlashBase+RamBase
Likewise, you can use that approach if you need to access data that has also been relocated. Simply use the offsets to calculate the real address of the moved data.

Another way to make the data relocatable would be to access it through the index register, H:X.

If you are trying to do this in C, . . . never mind.
0 Kudos