From cd2fefc46908f88ded7854f2408310627c1da092 Mon Sep 17 00:00:00 2001 From: Radoslaw Koppel Date: Wed, 3 Jan 2024 16:04:50 +0100 Subject: [PATCH] fix: Use __COUNTER__ to create unified names This fix uses __COUNTER__ preprocessor variable to create unified names of the sections and entries into ISR structures. The double expansion is required that the used counter does not change between creation of the section and creation of the intList entry with the string representation of the section name. Signed-off-by: Radoslaw Koppel --- include/zephyr/sw_isr_table.h | 44 +++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/include/zephyr/sw_isr_table.h b/include/zephyr/sw_isr_table.h index d617746438c00bc..43d47e12e5e6991 100644 --- a/include/zephyr/sw_isr_table.h +++ b/include/zephyr/sw_isr_table.h @@ -121,10 +121,11 @@ extern struct z_shared_isr_table_entry z_shared_sw_isr_table[]; #define _MK_IRQ_ELEMENT_NAME(func, id) __MK_ISR_ELEMENT_NAME(func, id) #define __MK_IRQ_ELEMENT_NAME(func, id) __irq_table_entry_ ## func ## _irq_ ## id -#define _MK_ISR_SECTION_NAME(prefix, file, line) "." Z_STRINGIFY(prefix)"."file"." Z_STRINGIFY(line) +#define _MK_ISR_SECTION_NAME(prefix, file, counter) \ + "." Z_STRINGIFY(prefix)"."file"." Z_STRINGIFY(counter) -#define _MK_ISR_ELEMENT_SECTION() _MK_ISR_SECTION_NAME(irq, __FILE__, __LINE__) -#define _MK_IRQ_ELEMENT_SECTION() _MK_ISR_SECTION_NAME(isr, __FILE__, __LINE__) +#define _MK_ISR_ELEMENT_SECTION(counter) _MK_ISR_SECTION_NAME(irq, __FILE__, counter) +#define _MK_IRQ_ELEMENT_SECTION(counter) _MK_ISR_SECTION_NAME(isr, __FILE__, counter) /* Separated macro to create ISR table entry only. * Used by Z_ISR_DECLARE and ISR tables generation script. @@ -137,6 +138,15 @@ extern struct z_shared_isr_table_entry z_shared_sw_isr_table[]; .isr = (void (*)(const void *))(void *)(func) \ } +#define Z_ISR_DECLARE_C(irq, flags, func, param, counter) \ + _Z_ISR_DECLARE_C(irq, flags, func, param, counter) + +#define _Z_ISR_DECLARE_C(irq, flags, func, param, counter) \ + _Z_ISR_TABLE_ENTRY(irq, func, param, _MK_ISR_ELEMENT_SECTION(counter)); \ + static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \ + __used _MK_ISR_NAME(func, counter) = \ + {irq, flags, _MK_ISR_ELEMENT_SECTION(counter)} + /* Create an entry for _isr_table to be then placed by the linker. * An instance of struct _isr_list which gets put in the .intList * section is created with the name of the section where _isr_table entry is placed to be then @@ -144,10 +154,8 @@ extern struct z_shared_isr_table_entry z_shared_sw_isr_table[]; */ #define Z_ISR_DECLARE(irq, flags, func, param) \ BUILD_ASSERT(((flags) & ISR_FLAG_DIRECT) == 0, "Use Z_ISR_DECLARE_DIRECT macro"); \ - _Z_ISR_TABLE_ENTRY(irq, func, param, _MK_ISR_ELEMENT_SECTION()); \ - static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \ - __used _MK_ISR_NAME(func, __COUNTER__) = \ - {irq, flags, _MK_ISR_ELEMENT_SECTION()} + Z_ISR_DECLARE_C(irq, flags, func, param, __COUNTER__) + /* Separated macro to create ISR Direct table entry only. * Used by Z_ISR_DECLARE_DIRECT and ISR tables generation script. @@ -156,14 +164,25 @@ extern struct z_shared_isr_table_entry z_shared_sw_isr_table[]; COND_CODE_1(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS, ( \ static Z_DECL_ALIGN(uintptr_t) \ __attribute__((section(sect))) \ - __used _MK_IRQ_ELEMENT_NAME(func, __LINE__) = ((uintptr_t)(func)); \ + __used _MK_IRQ_ELEMENT_NAME(func, __COUNTER__) = ((uintptr_t)(func)); \ ), ( \ static void __attribute__((section(sect))) \ - __used __attribute__((naked)) _MK_IRQ_ELEMENT_NAME(func, __LINE__) { \ + __used __attribute__((naked)) _MK_IRQ_ELEMENT_NAME(func, __COUNTER__) { \ __asm(ARCH_IRQ_VECTOR_JUMP_CODE(func)); \ } \ )) +#define Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) \ + _Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) + +#define _Z_ISR_DECLARE_DIRECT_C(irq, flags, func, counter) \ + _Z_ISR_DIRECT_TABLE_ENTRY(irq, func, _MK_IRQ_ELEMENT_SECTION(counter)); \ + static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \ + __used _MK_ISR_NAME(func, counter) = { \ + irq, \ + ISR_FLAG_DIRECT | (flags), \ + _MK_IRQ_ELEMENT_SECTION(counter)} + /* Create an entry to irq table and place it in specific section which name is then placed * in an instance of struct _isr_list to be then used by the isr generation script to create * the linker script chunks. @@ -172,12 +191,7 @@ extern struct z_shared_isr_table_entry z_shared_sw_isr_table[]; BUILD_ASSERT(IS_ENABLED(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_ADDRESS) || \ IS_ENABLED(CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_CODE), \ "CONFIG_IRQ_VECTOR_TABLE_JUMP_BY_{ADDRESS,CODE} not set"); \ - _Z_ISR_DIRECT_TABLE_ENTRY(irq, func, _MK_IRQ_ELEMENT_SECTION()); \ - static struct _isr_list_sname Z_GENERIC_SECTION(.intList) \ - __used _MK_ISR_NAME(func, __COUNTER__) = { \ - irq, \ - ISR_FLAG_DIRECT | (flags), \ - _MK_IRQ_ELEMENT_SECTION()} + Z_ISR_DECLARE_DIRECT_C(irq, flags, func, __COUNTER__) #else /* IS_ENABLED(CONFIG_ISR_TABLES_LOCAL_DECLARATION) */