Skip to content

Commit 4f9fe61

Browse files
committed
tests/kernel: Avoid C library calls from interrupt handlers
On arm64, GCC feels free to use floating point registers for essentially anything unless we build with -mgeneral-regs-only. After the FPU gets used in an interrupt handler, interrupts are disabled as there's no place to save the registers during a nested exception. As the C library may be built separately without this flag, we cannot use any of its functions or risk having nested exceptions fail. Switch printk usage to k_str_out and stick to (mostly) Zephyr internal functions to ensure nested interrupts work correctly. Signed-off-by: Keith Packard <[email protected]>
1 parent 84244a2 commit 4f9fe61

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

subsys/testsuite/include/zephyr/interrupt_util.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef INTERRUPT_UTIL_H_
88
#define INTERRUPT_UTIL_H_
99

10+
#define k_str_out_count(s) k_str_out(s, sizeof(s) - 1);
11+
1012
#if defined(CONFIG_CPU_CORTEX_M)
1113
#include <cmsis_core.h>
1214

@@ -57,7 +59,7 @@ static inline uint32_t get_available_nvic_line(uint32_t initial_offset)
5759

5860
static inline void trigger_irq(int irq)
5961
{
60-
printk("Triggering irq : %d\n", irq);
62+
k_str_out_count("Triggering irq\n");
6163
#if defined(CONFIG_SOC_TI_LM3S6965_QEMU) || defined(CONFIG_CPU_CORTEX_M0) || \
6264
defined(CONFIG_CPU_CORTEX_M0PLUS) || defined(CONFIG_CPU_CORTEX_M1) || \
6365
defined(CONFIG_ARMV6_M_ARMV8_M_BASELINE)
@@ -74,7 +76,7 @@ static inline void trigger_irq(int irq)
7476

7577
static inline void trigger_irq(int irq)
7678
{
77-
printk("Triggering irq : %d\n", irq);
79+
k_str_out_count("Triggering irq\n");
7880

7981
/* Ensure that the specified IRQ number is a valid SGI interrupt ID */
8082
zassert_true(irq <= 15, "%u is not a valid SGI interrupt ID", irq);
@@ -96,7 +98,7 @@ static inline void trigger_irq(int irq)
9698
#elif defined(CONFIG_ARC)
9799
static inline void trigger_irq(int irq)
98100
{
99-
printk("Triggering irq : %d\n", irq);
101+
k_str_out_count("Triggering irq\n");
100102
z_arc_v2_aux_reg_write(_ARC_V2_AUX_IRQ_HINT, irq);
101103
}
102104

tests/kernel/interrupt/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ target_sources(app PRIVATE
1616
src/nested_irq.c
1717
)
1818

19+
if(CONFIG_ARM64)
20+
add_compile_options(-mgeneral-regs-only)
21+
endif()
22+
1923
target_sources_ifdef(CONFIG_DYNAMIC_INTERRUPTS app PRIVATE src/dynamic_isr.c)
2024
target_sources_ifdef(CONFIG_X86 app PRIVATE src/regular_isr.c)
2125
target_sources_ifdef(CONFIG_SHARED_INTERRUPTS app PRIVATE src/static_shared_irq.c)

tests/kernel/interrupt/src/nested_irq.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ void isr1(const void *param)
102102
{
103103
ARG_UNUSED(param);
104104

105-
printk("isr1: Enter\n");
105+
k_str_out_count("isr1: Enter\n");
106106

107107
/* Set verification token */
108108
isr1_result = ISR1_TOKEN;
109109

110-
printk("isr1: Leave\n");
110+
k_str_out_count("isr1: Leave\n");
111111
}
112112

113113
void isr0(const void *param)
114114
{
115115
ARG_UNUSED(param);
116116

117-
printk("isr0: Enter\n");
117+
k_str_out_count("isr0: Enter\n");
118118

119119
/* Set verification token */
120120
isr0_result = ISR0_TOKEN;
@@ -128,7 +128,7 @@ void isr0(const void *param)
128128
/* Validate nested ISR result token */
129129
zassert_equal(isr1_result, ISR1_TOKEN, "isr1 did not execute");
130130

131-
printk("isr0: Leave\n");
131+
k_str_out_count("isr0: Leave\n");
132132
}
133133

134134
/**

0 commit comments

Comments
 (0)