From 3a48365babbdacda4547a2076061592912b6e474 Mon Sep 17 00:00:00 2001 From: Carlo Caione Date: Tue, 21 Jun 2022 14:26:03 +0200 Subject: [PATCH] irq: Fix IRQ vector table relocation The generation of the software ISR table and the IRQ vector table (respectively generated by CONFIG_GEN_SW_ISR_TABLE and CONFIG_GEN_IRQ_VECTOR_TABLE) should (in theory) go through three stages: 1. A placeholder table is generated in arch/common/isr_tables.c and placed in an orphaned .gnu.linkonce.{irq_vector_table, sw_isr_table} section 2. The real table is generated by arch/common/gen_isr_tables.py (creating the build/zephyr/isr_tables.c file) 3. The real table is un-orphaned by moving it in a proper section with a proper alignment While all the steps are done automatically for the software ISR table, for the IRQ vector table each architectures must take care of modiying its own linker script to place somewhere the generated IRQ vector table (basically step 3 is missing). This is currently only done for 2 architectures: Cortex-M (ARMv7) and ARC. But when another architecture tries to use the IRQ vector table, the linker complains about that. For example: Linking C executable zephyr/zephyr.elf riscv64-zephyr-elf/bin/ld.bfd: warning: orphan section `.gnu.linkonce.irq_vector_table' from `zephyr/CMakeFiles/zephyr_final.dir/isr_tables.c.obj' being placed in section `.gnu.linkonce.irq_vector_table' In this patch we introduce a new CONFIG_ARCH_IRQ_VECTOR_TABLE_ALIGN to support the architectures requiring a special alignment for the IRQ vector table and we also introduce a way to automatically place the IRQ vector table in place in the same way it is done for the ISR software table. Signed-off-by: Carlo Caione --- arch/Kconfig | 10 ++++++++++ arch/common/CMakeLists.txt | 6 ++++++ include/zephyr/linker/irq-vector-table-section.ld | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 include/zephyr/linker/irq-vector-table-section.ld diff --git a/arch/Kconfig b/arch/Kconfig index 944bb959fb7..62d50f62bd3 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -408,6 +408,16 @@ config GEN_IRQ_VECTOR_TABLE indexed by IRQ line. In the latter case, the vector table must be supplied by the application or architecture code. +config ARCH_IRQ_VECTOR_TABLE_ALIGN + int "Alignment size of the interrupt vector table" + default 0 + depends on GEN_IRQ_VECTOR_TABLE + help + This option controls alignment size of generated + _irq_vector_table. Some architecture needs an IRQ vector table + to be aligned to architecture specific size. The default + size is 0 for no alignment. + config GEN_SW_ISR_TABLE bool "Generate a software ISR table" default y diff --git a/arch/common/CMakeLists.txt b/arch/common/CMakeLists.txt index a83fe44a884..5c7dd0ea53e 100644 --- a/arch/common/CMakeLists.txt +++ b/arch/common/CMakeLists.txt @@ -24,6 +24,12 @@ zephyr_linker_sources_ifdef(CONFIG_GEN_ISR_TABLES ${ZEPHYR_BASE}/include/zephyr/linker/intlist.ld ) +zephyr_linker_sources_ifdef(CONFIG_GEN_IRQ_VECTOR_TABLE + ROM_START + SORT_KEY 0x0vectors + ${ZEPHYR_BASE}/include/zephyr/linker/irq-vector-table-section.ld +) + if(CONFIG_GEN_ISR_TABLES) zephyr_linker_section(NAME .intList VMA IDT_LIST LMA IDT_LIST NOINPUT PASS NOT LINKER_ZEPHYR_FINAL) zephyr_linker_section_configure(SECTION .intList KEEP INPUT ".irq_info" FIRST) diff --git a/include/zephyr/linker/irq-vector-table-section.ld b/include/zephyr/linker/irq-vector-table-section.ld new file mode 100644 index 00000000000..6a07abc34e2 --- /dev/null +++ b/include/zephyr/linker/irq-vector-table-section.ld @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: Apache-2.0 */ + +. = ALIGN(CONFIG_ARCH_IRQ_VECTOR_TABLE_ALIGN); +KEEP(*(_IRQ_VECTOR_TABLE_SECTION_SYMS))