4

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 ();
        }
    }
Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
  • 1
    What is the reason that you need the function to be at a predetermined address? – Agentlien Oct 31 '13 at 08:21
  • You will have to use a map file. What embedded system are you doing this for? – RedX Oct 31 '13 at 08:23
  • 1
    Which platform you are on? – SwiftMango Oct 31 '13 at 08:24
  • 1
    You may be to do it by tweaking the link script and declaring a "fake" memory bank at 3FF802. – lucasg Oct 31 '13 at 08:28
  • possible duplicate of [How to specify a memory location at which function will get stored?](http://stackoverflow.com/questions/18778323/how-to-specify-a-memory-location-at-which-function-will-get-stored) – RedX Oct 31 '13 at 09:09
  • Yes. I agree that the thread does have the correct answer. But since I am barred from using any pragmas in test scripts I am looking for alternatives here. I need only to declare this function loadableSW without tweaking the linker file. – Susanta Kumar Sahoo Oct 31 '13 at 09:29
  • Then its impossible unless the compiler you are using has special syntix support for it in source files. – RedX Oct 31 '13 at 10:39
  • Yes I also think so. Thanks. – Susanta Kumar Sahoo Oct 31 '13 at 10:45
  • 1
    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. – Chris Stratton Oct 31 '13 at 14:40

2 Answers2

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

Community
  • 1
  • 1
asalic
  • 949
  • 4
  • 10
  • Isn't this specific to IAR? – Agentlien Oct 31 '13 at 08:33
  • @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 – asalic Oct 31 '13 at 08:42
  • @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. – Susanta Kumar Sahoo Oct 31 '13 at 09:50
0

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.

Community
  • 1
  • 1
artless noise
  • 21,212
  • 6
  • 68
  • 105
  • See [David Salomon's Assemblers and Loaders](http://www.davidsalomon.name/assem.advertis/asl.pdf) for references/explanation of what an assembler, loader and linker do. – artless noise Oct 31 '13 at 13:15