diff --git a/arch/sim/include/arch.h b/arch/sim/include/arch.h index 4798968085..3fca68198c 100644 --- a/arch/sim/include/arch.h +++ b/arch/sim/include/arch.h @@ -40,14 +40,6 @@ #ifndef __ARCH_SIM_INCLUDE_ARCH_H #define __ARCH_SIM_INCLUDE_ARCH_H -/**************************************************************************** - * Included Files - ****************************************************************************/ - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - /**************************************************************************** * Inline functions ****************************************************************************/ @@ -61,29 +53,4 @@ static inline uintptr_t sim_getsp(void) return (uintptr_t)__builtin_frame_address(0); } -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -#undef EXTERN -#ifdef __cplusplus -} -#endif - #endif /* __ARCH_SIM_INCLUDE_ARCH_H */ diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h index 2741c64f6c..ac7d2215e6 100644 --- a/arch/sim/src/sim/up_internal.h +++ b/arch/sim/src/sim/up_internal.h @@ -242,6 +242,7 @@ void sim_cpu0_start(void); void up_cpu_started(void); int up_cpu_paused(int cpu); struct tcb_s *up_this_task(void); +int up_cpu_set_pause_handler(int irq); #endif /* up_oneshot.c *************************************************************/ diff --git a/arch/sim/src/sim/up_simsmp.c b/arch/sim/src/sim/up_simsmp.c index 56f8ac6734..478b4d7a1d 100644 --- a/arch/sim/src/sim/up_simsmp.c +++ b/arch/sim/src/sim/up_simsmp.c @@ -123,7 +123,6 @@ static void *sim_idle_trampoline(void *arg) #ifdef CONFIG_SIM_WALLTIME uint64_t now = 0; #endif - sigset_t set; int ret; /* Set the CPU number for the CPU thread */ @@ -137,14 +136,7 @@ static void *sim_idle_trampoline(void *arg) /* Make sure the SIGUSR1 is not masked */ - sigemptyset(&set); - sigaddset(&set, SIGUSR1); - - ret = pthread_sigmask(SIG_UNBLOCK, &set, NULL); - if (ret < 0) - { - return NULL; - } + up_cpu_set_pause_handler(SIGUSR1); /* Let up_cpu_start() continue */ @@ -180,28 +172,6 @@ static void *sim_idle_trampoline(void *arg) return NULL; } -/**************************************************************************** - * Name: sim_handle_signal - * - * Description: - * This is the SIGUSR signal handler. It implements the core logic of - * up_cpu_pause() on the thread of execution the simulated CPU. - * - * Input Parameters: - * arg - Standard sigaction arguments - * - * Returned Value: - * None - * - ****************************************************************************/ - -static void sim_handle_signal(int signo, siginfo_t *info, void *context) -{ - int cpu = (int)((uintptr_t)pthread_getspecific(g_cpu_key)); - - up_cpu_paused(cpu); -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -223,8 +193,6 @@ static void sim_handle_signal(int signo, siginfo_t *info, void *context) void sim_cpu0_start(void) { - struct sigaction act; - sigset_t set; int ret; g_cpu_thread[0] = pthread_self(); @@ -247,26 +215,7 @@ void sim_cpu0_start(void) /* Register the common signal handler for all threads */ - act.sa_sigaction = sim_handle_signal; - act.sa_flags = SA_SIGINFO; - sigemptyset(&act.sa_mask); - - ret = sigaction(SIGUSR1, &act, NULL); - if (ret < 0) - { - return; - } - - /* Make sure the SIGUSR1 is not masked */ - - sigemptyset(&set); - sigaddset(&set, SIGUSR1); - - ret = pthread_sigmask(SIG_UNBLOCK, &set, NULL); - if (ret < 0) - { - return; - } + up_cpu_set_pause_handler(SIGUSR1); } /**************************************************************************** diff --git a/arch/sim/src/sim/up_smpsignal.c b/arch/sim/src/sim/up_smpsignal.c index 0179bbc00e..7417a8740d 100644 --- a/arch/sim/src/sim/up_smpsignal.c +++ b/arch/sim/src/sim/up_smpsignal.c @@ -46,6 +46,32 @@ #include "sched/sched.h" #include "up_internal.h" +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: sim_cpupause_handler + * + * Description: + * This is the SIGUSR signal handler. It implements the core logic of + * up_cpu_pause() on the thread of execution the simulated CPU. + * + * Input Parameters: + * irq - the interrupt number + * context - not used + * arg - not used + * + * Returned Value: + * In case of success OK (0) is returned otherwise a negative value. + * + ****************************************************************************/ + +static int sim_cpupause_handler(int irq, FAR void *context, FAR void *arg) +{ + return up_cpu_paused(this_cpu()); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -204,3 +230,22 @@ struct tcb_s *up_this_task(void) { return this_task(); } + +/**************************************************************************** + * Name: up_cpu_set_pause_handler + * + * Description: + * Attach the CPU pause request interrupt to the NuttX logic. + * + * Input Parameters: + * irq - the SIGUSR1 interrupt number + * + * Returned Value: + * On success returns OK (0), otherwise a negative value. + ****************************************************************************/ + +int up_cpu_set_pause_handler(int irq) +{ + up_enable_irq(irq); + return irq_attach(irq, sim_cpupause_handler, NULL); +}