diff --git a/core/include/kernel_internal.h b/core/include/kernel_internal.h index 34ff547739fb3f011a078b2c1078028412ba794e..dfa60704e2c8d0ba306a5cd1c81463104e785031 100644 --- a/core/include/kernel_internal.h +++ b/core/include/kernel_internal.h @@ -20,6 +20,8 @@ #ifndef KERNEL_INTERNAL_H_ #define KERNEL_INTERNAL_H_ +#include "attributes.h" + /** * @brief Initializes scheduler and creates main and idle task */ @@ -44,7 +46,7 @@ char *thread_stack_init(void (*task_func)(void), void *stack_start, int stack_s /** * @brief Removes thread from scheduler and set status to #STATUS_STOPPED */ -void sched_task_exit(void); +NORETURN void sched_task_exit(void); /** * @brief Prints human readable, ps-like thread information for debugging purposes diff --git a/core/include/sched.h b/core/include/sched.h index 5fde47dc2f292cafdea2d4e9be5c3acf32b78af0..7d813084b7680ba5c8be115eb3170002e12f8543 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -25,6 +25,7 @@ #include <stddef.h> #include "bitarithm.h" #include "tcb.h" +#include "attributes.h" #define MAXTHREADS 32 /**< the maximum number of threads to be scheduled */ @@ -65,7 +66,7 @@ void sched_switch(uint16_t current_prio, uint16_t other_prio); /** * @brief Call context switching at thread exit */ -void cpu_switch_context_exit(void); +NORETURN void cpu_switch_context_exit(void); /** * Flag indicating whether a context switch is necessary after handling an diff --git a/core/sched.c b/core/sched.c index f1c5917172130b50b5b4ba558dc706aa11f8ac22..883a72e7547ab242bc327fe2d34211392e151e7d 100644 --- a/core/sched.c +++ b/core/sched.c @@ -189,7 +189,7 @@ void sched_switch(uint16_t current_prio, uint16_t other_prio) } } -void sched_task_exit(void) +NORETURN void sched_task_exit(void) { DEBUG("sched_task_exit(): ending task %s...\n", active_thread->name); diff --git a/cpu/lpc1768/atom.c b/cpu/lpc1768/atom.c index e8ecc4fc1a75b972653168ef312f62539213de7f..f4b0e4302150891fede8a699e2a3e546c200850e 100644 --- a/cpu/lpc1768/atom.c +++ b/cpu/lpc1768/atom.c @@ -18,9 +18,9 @@ #include "sched.h" #include "cpu.h" #include "irq.h" +#include "kernel_internal.h" -extern void sched_task_exit(void); -void sched_task_return(void); +NORETURN void sched_task_return(void); unsigned int atomic_set_return(unsigned int* p, unsigned int uiVal) { //unsigned int cspr = disableIRQ(); //crashes @@ -32,7 +32,7 @@ unsigned int atomic_set_return(unsigned int* p, unsigned int uiVal) { return uiOldVal; } -void cpu_switch_context_exit(void){ +NORETURN void cpu_switch_context_exit(void){ sched_run(); sched_task_return(); } @@ -78,7 +78,7 @@ void ctx_switch(void) sched_task_return(); } /* call scheduler so active_thread points to the next task */ -void sched_task_return(void) +NORETURN void sched_task_return(void) { /* load pdc->stackpointer in r0 */ asm("ldr r0, =active_thread"); /* r0 = &active_thread */ @@ -89,6 +89,8 @@ void sched_task_return(void) asm(" pop {r0-r3,r12,lr}"); /* simulate register restor from stack */ // asm("pop {r4}"); /*foo*/ asm("pop {pc}"); + + UNREACHABLE(); } /* * cortex m4 knows stacks and handles register backups @@ -109,7 +111,7 @@ void sched_task_return(void) * * */ -char * thread_stack_init(void * task_func, void * stack_start, int stack_size ) { +char * thread_stack_init(void (*task_func)(void), void * stack_start, int stack_size ) { unsigned int * stk; stk = (unsigned int *) (stack_start + stack_size); diff --git a/cpu/msp430-common/cpu.c b/cpu/msp430-common/cpu.c index 0009b92db2ebbf920588e2d77e5d17b945b4a6f6..36bb88ad85be012ff4f14f374528047997f5d9eb 100644 --- a/cpu/msp430-common/cpu.c +++ b/cpu/msp430-common/cpu.c @@ -32,12 +32,14 @@ void thread_yield(void) __restore_context(); } -void cpu_switch_context_exit(void) +NORETURN void cpu_switch_context_exit(void) { active_thread = sched_threads[0]; sched_run(); __restore_context(); + + UNREACHABLE(); } /**