This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

relocatable code

Other Parts Discussed in Thread: CC430F5137

Hi there,

I'm very new to relocatable code methodology. With that motive I have below questions:

1. Any good document that I can refer for understanding & writing relocatable code?

2. 'Blindly', I just tried compiling code in relocatable mode in CCSv6x, the CCS says, ".out exceeds code size limit". So, how to much extra memory we need have if we want make our code to be relocatable. Just general number(say10% extra or so). In other words how much memory does relocatable code costs?.

Thanks in advance!

-Rahul

  • All TI compiler tools, including the MSP430 compiler, use relocatable code and data on a routine basis.  For general background on the topic, please see the chapter titled Introduction to Object Modules in the MSP430 assembly tools manual.  Pay particular attention to the section titled Symbolic Relocations.

    Rahul Udagatti said:
    I just tried compiling code in relocatable mode in CCSv6x, the CCS says, ".out exceeds code size limit"

    You are probably using the free code size limited tools.  These tools are free, but don't allow the total amount of code to exceed some limit.  Change your code to a much smaller program, and you will be able to continue to experiment.

    Thanks and regards,

    -George

  • Do you mean run-time relocatable code? Do you mean "position independent" (PIC) code?
  • Thanks !

    Archaeologist,

    Actually, We've dual image based firmware for our devices, So, want code to run on both of the firmware 1 or 2 areas. (Meaning, firmware linked to area1 should also run in area2).

    -Rahul

  • I'm confused by your configuration. Are you saying that you want to have one copy of the code in memory, and that two different parts of the system see this area of memory as two different addresses?
  • Let me rephrase,

    We're using CC430F5137 and which has 32k flash memory. We have divided it into two areas 1&2. So, if we compile code for area1(starts @0x8000)., it should also work well if we place same code at firmware area2(starts@0x8000+ 16k).

    Thank you!

    -Rahul

  • I'm sorry, it's still unclear to me exactly what you're trying to do.  I'm going to assume you are using small memory model.

    If you are talking about binding the code to a particular address at link time, this decision is not finalized until link time.   When you create an object file and put it into a library, the addresses are not yet bound.  You can subsequently use the linker command file to place any code or data section anywhere in the lower 64k of address space, and it will work just fine.  

    If you are talking about moving the code at run time, you'll need to be more specific.

    1. Are you moving code from a load-time (perhaps ROM) address to its final run-time location?  If so, this is all decided in the linker, and I can help you with that.
    2. Are you executing the code first in one place, and then moving it, and then running from the new location?  If so, you need Position Independent Code (PIC) and the MSP430 compiler does not support this.  It can be done, but it will be a lot of work.
    3. Are there two identical copies of the code active at the same time in memory?  This is not possible unless you compile the source twice and give every function and variable a new name in the second copy.
    4. Is the high part of memory mapped to the lower address, such that there is only one area of memory, but it appears to the program to be two areas?  This will again require PIC.

  • Thank you Archaeologist!.

    yah.. The PIC that I require!.

    Then PIC is not the solution perhaps a this point of time. But Can you elaborate your first point.

    1. Are you moving code from a load-time (perhaps ROM) address to its final run-time location?  If so, this is all decided in the linker, and I can help you with that.

    Is this called relocatable code method?. I'm new to these kind of stuffs, please bear me. :-)

    -Rahul

  • Rahul Udagatti said:
    Is this called relocatable code method?

    No.  I don't think there is a widely agreed term for this technique.  The key is to allocate a section to one address for loading, and another address for running.  For general background, see the sub-chapter titled Load and Run Addresses in the MSP430 assembly tools manual.  The usual method to copy the code or data from ROM to RAM is called copy tables.  An example of using copy tables in in this application note.  The example is for a different processor family (C6000), and it presumes the run address is overlayed (you can also say "shared") between multiple output sections.  But you can adapt the copy table technique to your situation.

    Thanks and regards,

    -George