<p dir="ltr"><br>
On Jul 4, 2014 3:47 AM, Daniel Hellstrom <daniel@gaisler.com> wrote:<br>
><br>
> On 07/03/2014 04:55 PM, Joel Sherrill wrote:<br>
> > I am wondering if I don't have a vision for what this<br>
> > series of patches is trying to accomplish in whole.<br>
> * make exit-code propagate to debugger/hypervisor. I though this would be nice for other architectures as well.<br>
> * make SMP fatal exit work<br>
> * instead of using BSP specific reset on LEON3, rely on RTEMS and SPARC to stop execution<br>
> * fix bad behaviour of SPARC fatal halt, always spinning.<br>
><br>
> ><br>
> > And I am hung up on not wanting BSP references in<br>
> > score. So I would like an elegant solution.<br>
> I understand that, however some part of me still thinks that halting is very BSP specific. What makes me a bit confused is that there is just one halt approach, there is no difference between reset, <br>
> reboot, halt and power-down. I remember Win95 or Linux, when you type halt it does not reboot or power-down the machine, since you can see the last terminal shutdown message and push the power-down <br>
> button yourself ;)<br>
><br>
> > How does tweaking the bsp_reset() method not<br>
> > address all of this? It is invoked along the _Terminate()<br>
> > path already.<br>
> ><br>
> > As an aside, should the _Internal_errors_What_happened<br>
> > structure be filled in earlier in _Terminate? How about<br>
> > just after disabling interrupts?<br>
> That is one of the problems I faced.<br>
> * bsp_reset() does not have any arguments of what gone wrong<br>
> * _Internal_errors_What_happened is not modified until after bsp_reset()<br>
> * _Internal_errors_What_happened can not be updated before bsp_reset() on SMP since it will be written by all CPUs<br>
> * The exit codes of CPUs are different. If one CPU finds a problem, signals to the others to shut down, their IPI handler will call fatal handler with another exit code. Now the BSP in the fatal <br>
> extions can look at the exit codes to determine which CPU requested the fatal exit and handle them differently. The BSP makes sure that only one CPU ends up in the<br>
></p>
<p dir="ltr">Would it help if bsp_reset() took arguments? </p>
<p dir="ltr">I see the problem now.</p>
<p dir="ltr">> ><br>
> > On 7/3/2014 2:29 AM, Daniel Hellstrom wrote:<br>
> >> PATCHv2: BSP_fatal_halt renamed to _BSP_Fatal_halt<br>
> >><br>
> >> The Fatal_halt handler now have two options, either halt<br>
> >> as before or enter system error state to return to<br>
> >> debugger or simulator. The exit-code is now also<br>
> >> propagated to the debugger which is very useful for<br>
> >> testing.<br>
> >><br>
> >> The CPU_Fatal_halt handler was split up into two, since<br>
> >> the only the LEON3 support the CPU power down.<br>
> >><br>
> >> The LEON3 halt now uses the power-down instruction to save<br>
> >> CPU power. This doesn't stop a potential watch-dog timer<br>
> >> from expiring.<br>
> >> ---<br>
> >> c/src/lib/libbsp/sparc/erc32/Makefile.am | 1 +<br>
> >> c/src/lib/libbsp/sparc/erc32/configure.ac | 5 +++<br>
> >> c/src/lib/libbsp/sparc/leon2/Makefile.am | 1 +<br>
> >> c/src/lib/libbsp/sparc/leon2/configure.ac | 5 +++<br>
> >> c/src/lib/libbsp/sparc/leon3/Makefile.am | 1 +<br>
> >> c/src/lib/libbsp/sparc/leon3/configure.ac | 5 +++<br>
> >> .../libbsp/sparc/leon3/startup/bsp_fatal_halt.c | 36 ++++++++++++++++++<br>
> >> .../libbsp/sparc/shared/startup/bsp_fatal_halt.c | 38 ++++++++++++++++++++<br>
> >> cpukit/score/cpu/sparc/rtems/score/cpu.h | 12 ++----<br>
> >> 9 files changed, 96 insertions(+), 8 deletions(-)<br>
> >> create mode 100644 c/src/lib/libbsp/sparc/leon3/startup/bsp_fatal_halt.c<br>
> >> create mode 100644 c/src/lib/libbsp/sparc/shared/startup/bsp_fatal_halt.c<br>
> >><br>
> >> diff --git a/c/src/lib/libbsp/sparc/erc32/Makefile.am b/c/src/lib/libbsp/sparc/erc32/Makefile.am<br>
> >> index b9f1c53..00e398b 100644<br>
> >> --- a/c/src/lib/libbsp/sparc/erc32/Makefile.am<br>
> >> +++ b/c/src/lib/libbsp/sparc/erc32/Makefile.am<br>
> >> @@ -46,6 +46,7 @@ libbsp_a_SOURCES += startup/bspidle.c<br>
> >> libbsp_a_SOURCES += startup/bspdelay.c<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/startup/early_malloc.c<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_exit.c<br>
> >> +libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_halt.c<br>
> >> # ISR Handler<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/cpu.c<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/irq_asm.S<br>
> >> diff --git a/c/src/lib/libbsp/sparc/erc32/configure.ac b/c/src/lib/libbsp/sparc/erc32/configure.ac<br>
> >> index 4cbfb7e..bb5174a 100644<br>
> >> --- a/c/src/lib/libbsp/sparc/erc32/configure.ac<br>
> >> +++ b/c/src/lib/libbsp/sparc/erc32/configure.ac<br>
> >> @@ -43,6 +43,11 @@ RTEMS_BSPOPTS_HELP([ENABLE_SIS_QUIRKS],<br>
> >> BSP will be enabled. In particular, SIS requires special<br>
> >> initialization not used on real ERC32 hardware.])<br>
> >> <br>
> >> +RTEMS_BSPOPTS_SET([BSP_HALT_AT_FATAL_EXIT],[*],[])<br>
> >> +RTEMS_BSPOPTS_HELP([BSP_HALT_AT_FATAL_EXIT],<br>
> >> +[If defined, CPU is spinning on fatal exit. Otherwise generate system<br>
> >> + error which will hand over to debugger, simulator, etc.])<br>
> >> +<br>
> > Why would anyone want the CPU to go into a spin?<br>
> This was the previous behaviour of SPARC CPU_fatal_halt(), the only reason for that as I could come up with would be that the watchdog timer expires and causes a hard reset. I wanted to preserve the <br>
> current behaviour, I change quite much in the patch series anyway.<br>
><br>
> >> RTEMS_BSP_CLEANUP_OPTIONS(0,1,1)<br>
> >> <br>
> >> # Explicitly list all Makefiles here<br>
> >> diff --git a/c/src/lib/libbsp/sparc/leon2/Makefile.am b/c/src/lib/libbsp/sparc/leon2/Makefile.am<br>
> >> index 3f8edf4..ac6f327 100644<br>
> >> --- a/c/src/lib/libbsp/sparc/leon2/Makefile.am<br>
> >> +++ b/c/src/lib/libbsp/sparc/leon2/Makefile.am<br>
> >> @@ -61,6 +61,7 @@ libbsp_a_SOURCES += ../../shared/bspinit.c<br>
> >> libbsp_a_SOURCES += startup/bspdelay.c<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/startup/early_malloc.c<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_exit.c<br>
> >> +libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_halt.c<br>
> >> <br>
> >> # ISR Handler<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/cpu.c<br>
> >> diff --git a/c/src/lib/libbsp/sparc/leon2/configure.ac b/c/src/lib/libbsp/sparc/leon2/configure.ac<br>
> >> index 610a049..1975a10 100644<br>
> >> --- a/c/src/lib/libbsp/sparc/leon2/configure.ac<br>
> >> +++ b/c/src/lib/libbsp/sparc/leon2/configure.ac<br>
> >> @@ -36,6 +36,11 @@ RTEMS_BSPOPTS_HELP([SIMSPARC_FAST_IDLE],<br>
> >> time spent in the idle task is minimized. This significantly reduces<br>
> >> the wall time required to execute the RTEMS test suites.])<br>
> >> <br>
> >> +RTEMS_BSPOPTS_SET([BSP_HALT_AT_FATAL_EXIT],[*],[])<br>
> >> +RTEMS_BSPOPTS_HELP([BSP_HALT_AT_FATAL_EXIT],<br>
> >> +[If defined, CPU is spinning on fatal exit. Otherwise generate system<br>
> >> + error which will hand over to debugger, simulator, etc.])<br>
> >> +<br>
> >> RTEMS_BSP_CLEANUP_OPTIONS(0, 1, 1)<br>
> >> <br>
> >> # Explicitly list all Makefiles here<br>
> >> diff --git a/c/src/lib/libbsp/sparc/leon3/Makefile.am b/c/src/lib/libbsp/sparc/leon3/Makefile.am<br>
> >> index 54c9f22..d1f07a7 100644<br>
> >> --- a/c/src/lib/libbsp/sparc/leon3/Makefile.am<br>
> >> +++ b/c/src/lib/libbsp/sparc/leon3/Makefile.am<br>
> >> @@ -42,6 +42,7 @@ libbsp_a_SOURCES += ../../shared/bspclean.c ../../shared/bsplibc.c \<br>
> >> libbsp_a_SOURCES += startup/bspreset.c<br>
> >> libbsp_a_SOURCES += startup/cpucounter.c<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/startup/bsp_fatal_exit.c<br>
> >> +libbsp_a_SOURCES += startup/bsp_fatal_halt.c<br>
> >> <br>
> >> # ISR Handler<br>
> >> libbsp_a_SOURCES += ../../sparc/shared/cpu.c<br>
> >> diff --git a/c/src/lib/libbsp/sparc/leon3/configure.ac b/c/src/lib/libbsp/sparc/leon3/configure.ac<br>
> >> index 3fe1e48..206a662 100644<br>
> >> --- a/c/src/lib/libbsp/sparc/leon3/configure.ac<br>
> >> +++ b/c/src/lib/libbsp/sparc/leon3/configure.ac<br>
> >> @@ -38,6 +38,11 @@ RTEMS_BSPOPTS_HELP([BSP_LEON3_SMP],<br>
> >> [Always defined when on a LEON3 to enable the LEON3 support for<br>
> >> determining the CPU core number in an SMP configuration.])<br>
> >> <br>
> >> +RTEMS_BSPOPTS_SET([BSP_HALT_AT_FATAL_EXIT],[*],[])<br>
> >> +RTEMS_BSPOPTS_HELP([BSP_HALT_AT_FATAL_EXIT],<br>
> >> +[If defined, CPU is powered down on fatal exit. Otherwise generate system<br>
> >> + error which will hand over to debugger, simulator, etc.])<br>
> >> +<br>
> >> RTEMS_BSP_CLEANUP_OPTIONS(0, 1, 1)<br>
> >> RTEMS_BSP_LINKCMDS<br>
> >> <br>
> >> diff --git a/c/src/lib/libbsp/sparc/leon3/startup/bsp_fatal_halt.c b/c/src/lib/libbsp/sparc/leon3/startup/bsp_fatal_halt.c<br>
> >> new file mode 100644<br>
> >> index 0000000..4350faf<br>
> >> --- /dev/null<br>
> >> +++ b/c/src/lib/libbsp/sparc/leon3/startup/bsp_fatal_halt.c<br>
> >> @@ -0,0 +1,36 @@<br>
> >> +/**<br>
> >> + * @file<br>
> >> + * @ingroup sparc_leon3<br>
> >> + * @brief LEON3 BSP Fatal_halt handler.<br>
> >> + *<br>
> >> + * COPYRIGHT (c) 2014.<br>
> >> + * Aeroflex Gaisler AB.<br>
> >> + *<br>
> >> + * The license and distribution terms for this file may be<br>
> >> + * found in the file LICENSE in this distribution or at<br>
> >> + * http://www.rtems.org/license/LICENSE.<br>
> >> + */<br>
> >> +<br>
> >> +#include <leon.h><br>
> >> +#include <rtems/score/sparc.h><br>
> >> +<br>
> >> +#ifdef BSP_HALT_AT_FATAL_EXIT<br>
> >> +<br>
> >> +/* Power down LEON CPU on fatal error exit */<br>
> >> +void _BSP_Fatal_halt(uint32_t source, uint32_t error)<br>
> >> +{<br>
> >> + sparc_disable_interrupts();<br>
> >> + leon3_power_down_loop();<br>
> >> +}<br>
> >> +<br>
> >> +#else<br>
> >> +<br>
> >> +/* return to debugger, simulator, hypervisor or similar by exiting<br>
> >> + * with an error code. g1=1, g2=FATAL_SOURCE, G3=error-code.<br>
> >> + */<br>
> >> +void _BSP_Fatal_halt(uint32_t source, uint32_t error)<br>
> >> +{<br>
> >> + sparc_syscall_exit(source, error);<br>
> >> +}<br>
> >> +<br>
> >> +#endif<br>
> >> diff --git a/c/src/lib/libbsp/sparc/shared/startup/bsp_fatal_halt.c b/c/src/lib/libbsp/sparc/shared/startup/bsp_fatal_halt.c<br>
> >> new file mode 100644<br>
> >> index 0000000..349db20<br>
> >> --- /dev/null<br>
> >> +++ b/c/src/lib/libbsp/sparc/shared/startup/bsp_fatal_halt.c<br>
> >> @@ -0,0 +1,38 @@<br>
> >> +/**<br>
> >> + * @file<br>
> >> + * @ingroup sparc_bsp<br>
> >> + * @brief ERC32/LEON2 BSP Fatal_halt handler.<br>
> >> + *<br>
> >> + * COPYRIGHT (c) 2014.<br>
> >> + * Aeroflex Gaisler AB.<br>
> >> + *<br>
> >> + * The license and distribution terms for this file may be<br>
> >> + * found in the file LICENSE in this distribution or at<br>
> >> + * http://www.rtems.org/license/LICENSE.<br>
> >> + */<br>
> >> +<br>
> >> +#include <rtems/score/sparc.h><br>
> >> +<br>
> >> +#ifdef BSP_HALT_AT_FATAL_EXIT<br>
> >> +<br>
> >> +/* Spin CPU on fatal error exit */<br>
> >> +void _BSP_Fatal_halt(uint32_t source, uint32_t error)<br>
> >> +{<br>
> >> + uint32_t level = sparc_disable_interrupts();<br>
> >> +<br>
> >> + __asm__ volatile ( "mov %0, %%g1 " : "=r" (level) : "0" (level) );<br>
> >> +<br>
> >> + while (1) ; /* loop forever */<br>
> >> +}<br>
> >> +<br>
> >> +#else<br>
> >> +<br>
> >> +/* return to debugger, simulator, hypervisor or similar by exiting<br>
> >> + * with an error code. g1=1, g2=FATAL_SOURCE, G3=error-code.<br>
> >> + */<br>
> >> +void _BSP_Fatal_halt(uint32_t source, uint32_t error)<br>
> >> +{<br>
> >> + sparc_syscall_exit(source, error);<br>
> >> +}<br>
> >> +<br>
> >> +#endif<br>
> >> diff --git a/cpukit/score/cpu/sparc/rtems/score/cpu.h b/cpukit/score/cpu/sparc/rtems/score/cpu.h<br>
> >> index 58c843a..0bb1bf5 100644<br>
> >> --- a/cpukit/score/cpu/sparc/rtems/score/cpu.h<br>
> >> +++ b/cpukit/score/cpu/sparc/rtems/score/cpu.h<br>
> >> @@ -1075,19 +1075,15 @@ void _CPU_Context_Initialize(<br>
> >> <br>
> >> /* Fatal Error manager macros */<br>
> >> <br>
> >> +extern void _BSP_Fatal_halt(uint32_t source, uint32_t error)<br>
> >> + RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;<br>
> >> +<br>
> > I am really having trouble invoking a BSP specific routine<br>
> > out of score/cpu. Can't you do this in the bsp_reset()<br>
> > method?<br>
> No, the debugger/hypervisor typically reads registers as exit-codes not memory so it has to be done last. I'm not sure how it works on other architectures, can we always rely on memory for getting <br>
> exit-codes? If we would read the exit codes from memory from loader/debugger/hypervisor it would require ELF capability or that the BSP defines which address _Internal_errors_What_happened is to be <br>
> located at I guess<br>
><br>
> > If not, the leon3 is now a multilib so you can just have a<br>
> > leon3 specific version of this macro.<br>
> I'm not sure I follow here.<br>
><br>
><br>
> Please see the code below where the SPARC implements an endless spin after disabling interrupt. I substituted that with a power-down instead, as the commit message suggests it does not stop a watchdog <br>
> to expire and reset.<br>
> >> /**<br>
> >> * This routine copies _error into a known place -- typically a stack<br>
> >> * location or a register, optionally disables interrupts, and<br>
> >> * halts/stops the CPU.<br>
> >> */<br>
> >> -#define _CPU_Fatal_halt( _source, _error ) \<br>
> >> - do { \<br>
> >> - uint32_t level; \<br>
> >> - \<br>
> >> - level = sparc_disable_interrupts(); \<br>
> >> - __asm__ volatile ( "mov %0, %%g1 " : "=r" (level) : "0" (level) ); \<br>
> >> - while (1); /* loop forever */ \<br>
> >> - } while (0)<br>
> >> +#define _CPU_Fatal_halt( _source, _error ) _BSP_Fatal_halt( _source, _error )<br>
> >> <br>
> >> /* end of Fatal Error manager macros */<br>
> >> <br>
><br>
</p>