diff options
author | Soby Mathew <soby.mathew@arm.com> | 2018-10-12 16:26:20 +0100 |
---|---|---|
committer | Soby Mathew <soby.mathew@arm.com> | 2018-10-29 09:54:31 +0000 |
commit | 6a7b30057806c3573ee0194b7aa583bd60c89371 (patch) | |
tree | 33e09ffc84f804cdb24ecabe112538df09a0868a /include | |
parent | 9aabd11a424770e11dd89251960678d3e3332df6 (diff) | |
download | platform_external_arm-trusted-firmware-6a7b30057806c3573ee0194b7aa583bd60c89371.tar.gz platform_external_arm-trusted-firmware-6a7b30057806c3573ee0194b7aa583bd60c89371.tar.bz2 platform_external_arm-trusted-firmware-6a7b30057806c3573ee0194b7aa583bd60c89371.zip |
Add helper to return reference to a symbol
This patch adds a utility function to return
the address of a symbol. By default, the compiler
generates adr/adrp instruction pair to return
the reference and this utility is used to override
this compiler generated to code and use `ldr`
instruction.
This is needed for Position Independent Executable
when it needs to reference a symbol which is constant
and does not depend on the execute address of the
binary.
For example, on the FVP, the GICv3 register context is
stored in a secure carveout (arm_el3_tzc_dram) within
DDR and does not relocate with the BL image. Now if
BL31 is executing at a different address other than
the compiled address, using adrp/adr instructions to
reference this memory will not work as they generate an
address that is PC relative. The way to get around this
problem is to reference it as non-PC relative (i.e
non-relocatable location) via `ldr` instruction.
Change-Id: I5008a951b007144258121690afb68dc8e12ee6f7
Signed-off-by: Soby Mathew <soby.mathew@arm.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/lib/utils.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/lib/utils.h b/include/lib/utils.h index d46d8461d..f324a9909 100644 --- a/include/lib/utils.h +++ b/include/lib/utils.h @@ -67,6 +67,29 @@ void zero_normalmem(void *mem, u_register_t length); * zeroing. */ void zeromem(void *mem, u_register_t length); + +/* + * Utility function to return the address of a symbol. By default, the + * compiler generates adr/adrp instruction pair to return the reference + * to the symbol and this utility is used to override this compiler + * generated to code to use `ldr` instruction. + * + * This helps when Position Independent Executable needs to reference a symbol + * which is constant and does not depend on the execute address of the binary. + */ +#define DEFINE_LOAD_SYM_ADDR(_name) \ +static inline u_register_t load_addr_## _name(void) \ +{ \ + u_register_t v; \ + /* Create a void reference to silence compiler */ \ + (void) _name; \ + __asm__ volatile ("ldr %0, =" #_name : "=r" (v)); \ + return v; \ +} + +/* Helper to invoke the function defined by DEFINE_LOAD_SYM_ADDR() */ +#define LOAD_ADDR_OF(_name) (typeof(_name) *) load_addr_## _name() + #endif /* !(defined(__LINKER__) || defined(__ASSEMBLY__)) */ #endif /* __UTILS_H__ */ |