3

I want to place a function void loadableSW (void) at a specific location:0x3FF802. In another function residentMain() I will jump to this location using pointer to function. How to declare function loadableSW to accomplish this. I have attached the skeleton of residentMain for clarity.

Update: Target hardware is TMS320C620xDSP. Since this is an aerospace project, deterministic behaviour is a desirable design objective. Ideally, they would like to know what portion of memory contains what at a particular time. The solution as I just got to know is to define a section in memory in the linker file. The section shall start at 0x3FF802 (Location where to place the function). Since the size of the loadableSW function is known, the size of the memory section can also be determined. And then the directive #pragma CODESECTION ("function_name", "section_name") can place that function in the specified section.

Since pragma directives are not permissible in test scripts, I am wondering if there is any other way to do this without using any linker directives.

Besides I am curious. Is there any placement syntax for functions in C++? I know there is one for objects, but functions?

    void residentMain (void)
    {
        void (*loadable_p) (void) = (void (*) (void)) 0x3FF802;
        int hardwareOK = 0;
    
        /*Code to check hardware integrity. hardwareOK = 1 if success*/
    
        if (hardwareOK)
        {
            loadable_p (); /*Jump to Loadable Software*/
        }
        else
        {
            dspHalt ();
        }
    }
9
  • 3
    What is the reason that you need the function to be at a predetermined address? Commented Oct 31, 2013 at 8:21
  • You will have to use a map file. What embedded system are you doing this for? Commented Oct 31, 2013 at 8:23
  • 1
    Which platform you are on? Commented Oct 31, 2013 at 8:24
  • 1
    You may be to do it by tweaking the link script and declaring a "fake" memory bank at 3FF802. Commented Oct 31, 2013 at 8:28
  • 2
    You need to deal with this at the level of allegedly being "barred from using any pragmas in test scripts" - either the person making that requirement is clueless, or they intend to prevent you from accomplish the task you have set out to accomplish, because anything you could do to accomplish it would be functionally equivalent to that. Commented Oct 31, 2013 at 14:40

2 Answers 2

1

How to place a function at a particular address in C?

Since pragma directives are not permissible in test scripts, I am wondering if there is any other way to do this without using any linker directives.

If your target supports PC-relative addressing and you can ensure it is pure, then you can use a memcpy() to relocate the routine.

How to run code from RAM... has some hints on this. If you can not generate PC-relative/relocatable code, then you absolutely can not do this with out the help of the linker. That is the definition of a linker/loader, to fix up addresses.

Which can take you to a different concept. Do not fully link your code. Instead defer the address fixup until loading. Then you must write a loader to place the code at run-time; but from your aerospace project comment, I think that complexity and analysis are also important so I don't believe you would accept that. You also need double the storage, etc.

Sign up to request clarification or add additional context in comments.

1 Comment

See David Salomon's Assemblers and Loaders for references/explanation of what an assembler, loader and linker do.
0

I'm not sure about your OS/toolchain/IDE, but the following answer should work:

How to specify a memory location at which function will get stored?

There is just one way I know of and it is shown in the first answer.

UPDATE

How to define sections in gcc:

variables: http://mcuoneclipse.com/2012/11/01/defining-variables-at-absolute-addresses-with-gcc/

methods (section ("section-name")): http://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Function-Attributes.html#Function%20Attributes

3 Comments

Isn't this specific to IAR?
@Agentlien Yes it is, but it was the only thing I was aware of, and since you haven't specify anything about the env... Please check the update
@Susanta: Yes I am looking for something like this. Only hitch is the compiler is not gcc. It is cl55. But thanks.I am going to go through the manual once again for similar features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.