aboutsummaryrefslogtreecommitdiff
path: root/plat/nvidia/tegra/soc/t186
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2017-08-01 15:16:36 -0700
committerJulius Werner <jwerner@chromium.org>2017-08-15 16:37:08 -0700
commit64726e6d61e94203a1dc6aa3f49affd8f2165aec (patch)
tree4717e3109b74ee0f0aa8c25e053e622c456691e7 /plat/nvidia/tegra/soc/t186
parent1a52aca5f627a0c0623d6a7052064f090b26d134 (diff)
downloadtrusted-firmware-a-64726e6d61e94203a1dc6aa3f49affd8f2165aec.tar.gz
Add new alignment parameter to func assembler macro
Assembler programmers are used to being able to define functions with a specific aligment with a pattern like this: .align X myfunction: However, this pattern is subtly broken when instead of a direct label like 'myfunction:', you use the 'func myfunction' macro that's standard in Trusted Firmware. Since the func macro declares a new section for the function, the .align directive written above it actually applies to the *previous* section in the assembly file, and the function it was supposed to apply to is linked with default alignment. An extreme case can be seen in Rockchip's plat_helpers.S which contains this code: [...] endfunc plat_crash_console_putc .align 16 func platform_cpu_warmboot [...] This assembles into the following plat_helpers.o: Sections: Idx Name Size [...] Algn 9 .text.plat_crash_console_putc 00010000 [...] 2**16 10 .text.platform_cpu_warmboot 00000080 [...] 2**3 As can be seen, the *previous* function actually got the alignment constraint, and it is also 64KB big even though it contains only two instructions, because the .align directive at the end of its section forces the assembler to insert a giant sled of NOPs. The function we actually wanted to align has the default constraint. This code only works at all because the linker just happens to put the two functions right behind each other when linking the final image, and since the end of plat_crash_console_putc is aligned the start of platform_cpu_warmboot will also be. But it still wastes almost 64KB of image space unnecessarily, and it will break under certain circumstances (e.g. if the plat_crash_console_putc function becomes unused and its section gets garbage-collected out). There's no real way to fix this with the existing func macro. Code like func myfunc .align X happens to do the right thing, but is still not really correct code (because the function label is inserted before the .align directive, so the assembler is technically allowed to insert padding at the beginning of the function which would then get executed as instructions if the function was called). Therefore, this patch adds a new parameter with a default value to the func macro that allows overriding its alignment. Also fix up all existing instances of this dangerous antipattern. Change-Id: I5696a07e2fde896f21e0e83644c95b7b6ac79a10 Signed-off-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'plat/nvidia/tegra/soc/t186')
-rw-r--r--plat/nvidia/tegra/soc/t186/plat_trampoline.S3
1 files changed, 1 insertions, 2 deletions
diff --git a/plat/nvidia/tegra/soc/t186/plat_trampoline.S b/plat/nvidia/tegra/soc/t186/plat_trampoline.S
index 4841aa2096..6a17c3328b 100644
--- a/plat/nvidia/tegra/soc/t186/plat_trampoline.S
+++ b/plat/nvidia/tegra/soc/t186/plat_trampoline.S
@@ -12,11 +12,10 @@
#define TEGRA186_SMMU_CTX_SIZE 0x420
- .align 4
.globl tegra186_cpu_reset_handler
/* CPU reset handler routine */
-func tegra186_cpu_reset_handler
+func tegra186_cpu_reset_handler _align=4
/*
* The TZRAM loses state during System Suspend. We use this
* information to decide if the reset handler is running after a