<div dir="ltr">Does this impact the porting guide or any CPU supplement?<div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, May 17, 2021 at 4:42 PM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">ok to me<br>
<br>
On Mon, May 17, 2021 at 5:43 AM Sebastian Huber<br>
<<a href="mailto:sebastian.huber@embedded-brains.de" target="_blank">sebastian.huber@embedded-brains.de</a>> wrote:<br>
><br>
> The __builtin_unreachable() cannot be used with current GCC versions to<br>
> tell the compiler that a function does not return to the caller, see:<br>
><br>
> <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99151" rel="noreferrer" target="_blank">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99151</a><br>
><br>
> Add a no return variant of _CPU_Context_switch() to avoid generation of<br>
> dead code in _Thread_Start_multitasking() if RTEMS was built with SMP<br>
> support enabled.<br>
> ---<br>
> bsps/powerpc/shared/cpu_asm.S | 2 ++<br>
> cpukit/score/cpu/arm/cpu_asm.S | 3 ++<br>
> .../score/cpu/arm/include/rtems/score/cpu.h | 5 ++++<br>
> .../cpu/no_cpu/include/rtems/score/cpu.h | 30 +++++++++++++++++--<br>
> .../cpu/powerpc/include/rtems/score/cpu.h | 5 ++++<br>
> .../score/cpu/riscv/include/rtems/score/cpu.h | 5 ++++<br>
> cpukit/score/cpu/riscv/riscv-context-switch.S | 2 ++<br>
> cpukit/score/cpu/sparc/cpu_asm.S | 2 ++<br>
> .../score/cpu/sparc/include/rtems/score/cpu.h | 5 ++++<br>
> cpukit/score/src/threadstartmultitasking.c | 2 +-<br>
> 10 files changed, 57 insertions(+), 4 deletions(-)<br>
><br>
> diff --git a/bsps/powerpc/shared/cpu_asm.S b/bsps/powerpc/shared/cpu_asm.S<br>
> index e4d627016c..63f6a3fdfe 100644<br>
> --- a/bsps/powerpc/shared/cpu_asm.S<br>
> +++ b/bsps/powerpc/shared/cpu_asm.S<br>
> @@ -258,7 +258,9 @@ PROC (_CPU_Context_restore_fp):<br>
><br>
> ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER)<br>
> PUBLIC_PROC (_CPU_Context_switch)<br>
> + PUBLIC_PROC (_CPU_Context_switch_no_return)<br>
> PROC (_CPU_Context_switch):<br>
> +PROC (_CPU_Context_switch_no_return):<br>
><br>
> #ifdef BSP_USE_SYNC_IN_CONTEXT_SWITCH<br>
> sync<br>
> diff --git a/cpukit/score/cpu/arm/cpu_asm.S b/cpukit/score/cpu/arm/cpu_asm.S<br>
> index 66f8ba6032..46eb46b914 100644<br>
> --- a/cpukit/score/cpu/arm/cpu_asm.S<br>
> +++ b/cpukit/score/cpu/arm/cpu_asm.S<br>
> @@ -54,6 +54,9 @@<br>
> */<br>
><br>
> DEFINE_FUNCTION_ARM(_CPU_Context_switch)<br>
> + .globl _CPU_Context_switch_no_return<br>
> + .set _CPU_Context_switch_no_return, _CPU_Context_switch<br>
> +<br>
> /* Start saving context */<br>
> GET_SELF_CPU_CONTROL r2<br>
> ldr r3, [r2, #PER_CPU_ISR_DISPATCH_DISABLE]<br>
> diff --git a/cpukit/score/cpu/arm/include/rtems/score/cpu.h b/cpukit/score/cpu/arm/include/rtems/score/cpu.h<br>
> index e5b23e7100..dcda4d525c 100644<br>
> --- a/cpukit/score/cpu/arm/include/rtems/score/cpu.h<br>
> +++ b/cpukit/score/cpu/arm/include/rtems/score/cpu.h<br>
> @@ -465,6 +465,11 @@ void _CPU_ISR_install_vector(<br>
> */<br>
> void _CPU_Context_switch( Context_Control *run, Context_Control *heir );<br>
><br>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(<br>
> + Context_Control *executing,<br>
> + Context_Control *heir<br>
> +);<br>
> +<br>
> RTEMS_NO_RETURN void _CPU_Context_restore( Context_Control *new_context );<br>
><br>
> #if defined(ARM_MULTILIB_ARCH_V7M)<br>
> diff --git a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h<br>
> index c067501502..c437ded5fb 100644<br>
> --- a/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h<br>
> +++ b/cpukit/score/cpu/no_cpu/include/rtems/score/cpu.h<br>
> @@ -1054,22 +1054,46 @@ void _CPU_ISR_install_vector(<br>
> void *_CPU_Thread_Idle_body( uintptr_t ignored );<br>
><br>
> /**<br>
> + * @brief Peforms a context switch from the executing thread to the heir<br>
> + * thread.<br>
> + *<br>
> * @addtogroup RTEMSScoreCPUExampleContext<br>
> *<br>
> * This routine switches from the run context to the heir context.<br>
> *<br>
> - * @param[in] run points to the context of the currently executing task<br>
> - * @param[in] heir points to the context of the heir task<br>
> + * @param[out] executing points to the context of the currently executing task.<br>
> + *<br>
> + * @param[in, out] heir points to the context of the heir task.<br>
> *<br>
> * Port Specific Information:<br>
> *<br>
> * XXX document implementation including references if appropriate<br>
> */<br>
> void _CPU_Context_switch(<br>
> - Context_Control *run,<br>
> + Context_Control *executing,<br>
> Context_Control *heir<br>
> );<br>
><br>
> +/**<br>
> + * @brief Peforms a context switch from the executing thread to the heir thread<br>
> + * and does not return.<br>
> + *<br>
> + * @addtogroup RTEMSScoreCPUExampleContext<br>
> + *<br>
> + * This routine shall be a strong alias to _CPU_Context_switch(). It shall be<br>
> + * provided for all target architectures which support an SMP build<br>
> + * configuration (RTEMS_SMP). The purpose is help to compiler to avoid<br>
> + * generation of dead code in _Thread_Start_multitasking().<br>
> + *<br>
> + * @param[out] executing points to the context of the currently executing task.<br>
> + *<br>
> + * @param[in, out] heir points to the context of the heir task.<br>
> + */<br>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(<br>
> + Context_Control *executing,<br>
> + Context_Control *heir<br>
> +);<br>
> +<br>
> /**<br>
> * @addtogroup RTEMSScoreCPUExampleContext<br>
> *<br>
> diff --git a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h<br>
> index 996b6f8e60..f22e1cd7ec 100644<br>
> --- a/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h<br>
> +++ b/cpukit/score/cpu/powerpc/include/rtems/score/cpu.h<br>
> @@ -914,6 +914,11 @@ void _CPU_Context_switch(<br>
> Context_Control *heir<br>
> );<br>
><br>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(<br>
> + Context_Control *executing,<br>
> + Context_Control *heir<br>
> +);<br>
> +<br>
> /*<br>
> * _CPU_Context_restore<br>
> *<br>
> diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h<br>
> index 38eb92394d..a44b815b12 100644<br>
> --- a/cpukit/score/cpu/riscv/include/rtems/score/cpu.h<br>
> +++ b/cpukit/score/cpu/riscv/include/rtems/score/cpu.h<br>
> @@ -383,6 +383,11 @@ void _CPU_Context_switch(<br>
> Context_Control *heir<br>
> );<br>
><br>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(<br>
> + Context_Control *executing,<br>
> + Context_Control *heir<br>
> +);<br>
> +<br>
> /*<br>
> * _CPU_Context_restore<br>
> *<br>
> diff --git a/cpukit/score/cpu/riscv/riscv-context-switch.S b/cpukit/score/cpu/riscv/riscv-context-switch.S<br>
> index 96c117b3de..830f8629a4 100644<br>
> --- a/cpukit/score/cpu/riscv/riscv-context-switch.S<br>
> +++ b/cpukit/score/cpu/riscv/riscv-context-switch.S<br>
> @@ -37,9 +37,11 @@<br>
> .align 2<br>
><br>
> PUBLIC(_CPU_Context_switch)<br>
> +PUBLIC(_CPU_Context_switch_no_return)<br>
> PUBLIC(_CPU_Context_restore)<br>
><br>
> SYM(_CPU_Context_switch):<br>
> +SYM(_CPU_Context_switch_no_return):<br>
> GET_SELF_CPU_CONTROL a2<br>
> lw a3, PER_CPU_ISR_DISPATCH_DISABLE(a2)<br>
><br>
> diff --git a/cpukit/score/cpu/sparc/cpu_asm.S b/cpukit/score/cpu/sparc/cpu_asm.S<br>
> index e884fb2f9e..a7b87ad5f8 100644<br>
> --- a/cpukit/score/cpu/sparc/cpu_asm.S<br>
> +++ b/cpukit/score/cpu/sparc/cpu_asm.S<br>
> @@ -57,7 +57,9 @@<br>
><br>
> .align 4<br>
> PUBLIC(_CPU_Context_switch)<br>
> + PUBLIC(_CPU_Context_switch_no_return)<br>
> SYM(_CPU_Context_switch):<br>
> +SYM(_CPU_Context_switch_no_return):<br>
> st %g5, [%o0 + G5_OFFSET] ! save the global registers<br>
><br>
> /*<br>
> diff --git a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h<br>
> index 8c5330b8ce..6c167e3f08 100644<br>
> --- a/cpukit/score/cpu/sparc/include/rtems/score/cpu.h<br>
> +++ b/cpukit/score/cpu/sparc/include/rtems/score/cpu.h<br>
> @@ -971,6 +971,11 @@ void _CPU_Context_switch(<br>
> Context_Control *heir<br>
> );<br>
><br>
> +RTEMS_NO_RETURN void _CPU_Context_switch_no_return(<br>
> + Context_Control *executing,<br>
> + Context_Control *heir<br>
> +);<br>
> +<br>
> /**<br>
> * @brief SPARC specific context restore.<br>
> *<br>
> diff --git a/cpukit/score/src/threadstartmultitasking.c b/cpukit/score/src/threadstartmultitasking.c<br>
> index a0b465a226..094a535394 100644<br>
> --- a/cpukit/score/src/threadstartmultitasking.c<br>
> +++ b/cpukit/score/src/threadstartmultitasking.c<br>
> @@ -59,7 +59,7 @@ void _Thread_Start_multitasking( void )<br>
> * executing to the currently selected heir thread.<br>
> */<br>
> _CPU_Context_Set_is_executing( &trash, true );<br>
> - _CPU_Context_switch( &trash, &heir->Registers );<br>
> + _CPU_Context_switch_no_return( &trash, &heir->Registers );<br>
> RTEMS_UNREACHABLE();<br>
> }<br>
> #else<br>
> --<br>
> 2.26.2<br>
><br>
> _______________________________________________<br>
> devel mailing list<br>
> <a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
> <a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>