Finding the last variable in the __attribute __ (section)

I am currently working on an embedded system, and in order to meet time constraints, I needed to lock some code in the cache. I put all the functions that I would need to lock the cache in the MEMORY_CACHEABLE section using the section variable attribute.

Since the board I am using sets the memory attributes to 1 megabyte, I made a 1MB MEMORY_CACHEABLE.

When it comes to actually locking the code in the cache, I need to define a high address for the code inside MEMORY_CACHEABLE, since it doesn't take up all the memory space, and I don't want to lock the unused memory in the cache.

The way I do this is to use a placeholder in MEMORY_CACHEABLE which is defined in my C code after all other function put in MEMORY_CACHEABLE. Every time I debug I have confirmed that the placeholder has a higher address than the other function. I used this value as a high address, but it seems a little hacky.

I don't know of a standard way to determine the size of a C function at runtime, but is there an easier way to detect a high code address in this particular section of memory?

Also, I am cross-compiling with arm-xilinx-eabi-gcc.

Thank!

+3


source to share


1 answer


You can use a linker script for this. You may already be using it to specify the attributes of a memory section.

So, just add:

MEMORY_CACHEABLE :
{
    BEGIN_MEMORY_CACHEABLE = .;
    *(MEMORY_CACHEABLE)
    END_MEMORY_CACHEABLE = .;
}

      



Then in C code:

extern char BEGIN_MEMORY_CACHEABLE, END_MEMORY_CACHEABLE;

      

And use &BEGIN_MEMORY_CACHEABLE

both a pointer to the beginning and a &END_MEMORY_CACHEABLE

pointer to one end of your cached storage.

+1


source







All Articles