From 1067d234359b0e14bf08d7c2087f74bc6ad30842 Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Sat, 10 Aug 2019 18:19:38 +0200 Subject: [PATCH] fix(l0dables): Fix vector table alignment The vector table's alignment requirements depend on the number of interrupts [1]. In our case, we have 0x6E(=110) interrupts and thus an alignment requirement of 0x80(=128). To satisfy this requirement, this commit moves the IVT to the beginning of .text and enforces a 128 byte alignment. Please note that the headers which come before .text will push the IVT to 0x100 instead of having it directly in the beginning at 0x00. [1]: https://developer.arm.com/docs/dui0553/a/cortex-m4-peripherals/system-control-block/vector-table-offset-register Signed-off-by: Rahix <rahix@rahix.de> --- l0dables/lib/crt.s | 6 +++--- l0dables/lib/l0dable.ld | 3 +++ l0dables/lib/meson.build | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/l0dables/lib/crt.s b/l0dables/lib/crt.s index b811c4e6c..57726cb56 100644 --- a/l0dables/lib/crt.s +++ b/l0dables/lib/crt.s @@ -18,10 +18,10 @@ * * All of the following (apart from Reset_Handler, which calls main()) * are backed by weak referenced symbols, which you can override just - * by defining them in C code. + * by defining them in C code. */ - .section .data - .align 2 + .section .text.isr_vector + .align 7 .globl __isr_vector __isr_vector: .long 0 /* Top of Stack, overriden by l0der at load time */ diff --git a/l0dables/lib/l0dable.ld b/l0dables/lib/l0dable.ld index 31fbb773d..aa7225cfe 100644 --- a/l0dables/lib/l0dable.ld +++ b/l0dables/lib/l0dable.ld @@ -33,6 +33,9 @@ SECTIONS { .text : { + /* The vector table needs 128 byte alignment */ + . = ALIGN(128); + KEEP(*(.text.isr_vector)) *(.text*) *(.rodata*) diff --git a/l0dables/lib/meson.build b/l0dables/lib/meson.build index f2f16295a..d24075145 100644 --- a/l0dables/lib/meson.build +++ b/l0dables/lib/meson.build @@ -3,7 +3,7 @@ l0dable_startup_lib = static_library( 'crt.s', 'hardware.c', dependencies: [api_caller], - pic: true, + c_args: ['-fpie'], ) l0dable_startup = declare_dependency( -- GitLab