Skip to content

Commit

Permalink
fix: Use __COUNTER__ to create unified names
Browse files Browse the repository at this point in the history
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 <radoslaw.koppel@nordicsemi.no>
  • Loading branch information
rakons committed Jan 3, 2024
1 parent 78b3622 commit cd2fefc
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions include/zephyr/sw_isr_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -137,17 +138,24 @@ 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
* used by isr generation script to create linker script chunk.
*/
#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.
Expand All @@ -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.
Expand All @@ -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) */
Expand Down

0 comments on commit cd2fefc

Please sign in to comment.