3
\$\begingroup\$

I am working on a project which includes an ARM microcontroller. At runtime, I want to load code from an SD card into program flash and then execute that code. My question is, since ARM code seems to work with relative jumps, whether it matters where in memory I am putting the code. If I can just compile my code and relocate it anywhere in the address space, this greatly simplifies the task. I am using TI Code Composer Studio with a GCC compiler toolchain.

asked Feb 17, 2016 at 20:04
\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

ARM really has nothing to do with this, many/most instruction sets have ways to use fixed addresses and relative addresses. Then it comes down to asking the tools to do it one way or the other or writing your code one way or the other.

ARM has plenty of different instructions for doing things, most definitely is well supported in toolchains and those toolchains can build position dependent or position independent.

If you had run your gcc program with --help you would see some command line options that would apply to what you are trying to do. Actually when you run with --help you will see that you really want

arm-whatever-gcc -v --help
answered Feb 17, 2016 at 20:40
\$\endgroup\$
1
  • \$\begingroup\$ I will be working on this part of the project soon, so I'll wait to mark an answer but this looks like sound advice \$\endgroup\$ Commented Feb 19, 2016 at 5:37
4
\$\begingroup\$

The ARM instruction set is fully relocatable, though it is possible to create code that isn't by referencing absolute addresses (eg. to relative positioned data). It is one of the major design features of the instruction set since the very first versions in the late 80's.

Another consideration is memory protection, this entirely depends on the hardware platform. On some hardware platforms not all address ranges can be used to execute code, these ranges can only be used for data (or memory mapped I/O). Refer to the datasheet of your chip(set).

answered Feb 17, 2016 at 20:06
\$\endgroup\$
1
  • 1
    \$\begingroup\$ To add to this, relocation usually requires a bootstrap routine to copy the objects to the right memory addresses. Typically You set up the linker table and build against the post-relocation addresses, you place the hex binary wherever you want and the bootstrap routine handles relocation. \$\endgroup\$ Commented Feb 17, 2016 at 20:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.