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.

how to get base address of a section in program?

Hi,

We are using Keystone family of Multicore DSP. I moved some of my function code (text section) to DDR3 using the format

 

SECTIONS
{
    .mytext : /* Build .text output section */
    {
        f1.obj(.text)      /* Link .text section from f1.obj */
        f2.obj(.text) /* Link .text and sec2 from f4.obj */
    }
}

Now I want to protect the memory where .mytext section is located from being written. I figured that this can be done using the MPAX registers but for that I need to know the base address of .mytext section in my code.

Any ideas how to do this?

 

  • You can defines symbols in the linker command file using the dot operator or the RUN_START() operator (see spru186 para. 7.5.8.5):

    .mytext { start_of_mytext = . ;     ..... };

    Now You can get the address in your code:

    extern far unsigned int start_of_mytext; //note: far and extern. Declaration only, don't define it

    unsigned int* start_of_mytext_address=&start_of_mytext;

    Linker symbols defines only constant link-time address, so You have to extract the address of the linker created symbols.

  •  

    Thanks for the tip Alberto, it worked.

     

    Tarun