Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run code from RAM on ARM architecture

Tags:

arm

I am programming an ARM Cortex-R4 and I have a few binary files that I'd like to execute them from TCRAM, just to see if the increase in performance is good enough.

I know I'd have to write a function to copy the binaries to the RAM (which can be accomplished with the linker script, and knowing the size of the binaries). But how would they run?

Imagine this: The first binary has func1(), func2(), func3() and func4(). I'd copy the entire module to TCRAM and how would I call a function there? I'd have to use a function pointer to that specific function? And what if func4(), calls func2() and func3()? If I'm not mistaken they'd point to the piece of code located in the flash. Does that mean I'd have to re write those funcs? Use entirely function pointers? I've been told that just the linker script is enough to do all of this and I needn't worry about anything, but I still don't understand how it works.

like image 974
morcillo Avatar asked Feb 28 '13 13:02

morcillo


1 Answers

On GCC: Just put the function in the .data section:

__attribute__( ( section(".data") ) )

It will be copied over with the rest of your initialzed variables by the startup code (no need to mess with the linker scipt). You may also need a "long_call" option as well if the function ends up "far away" from the rest of the code after being placed into RAM.

__attribute__( ( long_call, section(".data") ) )

Example:

__attribute__( ( long_call, section(".data") ) ) void ram_foobar (void) { ... }

You may get an compiler warning that can be safely ignored:

Warning: ignoring changed section attributes for .data
like image 72
kneeco Avatar answered Sep 29 '22 22:09

kneeco