[PATCH] sparc: Prefer RTEMS_FATAL_SOURCE_EXCEPTION

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Jul 15 07:13:51 UTC 2021


Prefer RTEMS_FATAL_SOURCE_EXCEPTION over
INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT since the fatal code
(rtems_exception_frame) provides more context.
---
 cpukit/score/cpu/sparc/sparc-bad-trap.S | 14 ----------
 testsuites/sptests/spfatal30/init.c     | 37 +++++++++++++++++++------
 testsuites/sptests/spfatal31/init.c     | 35 +++++++++++++++++------
 3 files changed, 55 insertions(+), 31 deletions(-)

diff --git a/cpukit/score/cpu/sparc/sparc-bad-trap.S b/cpukit/score/cpu/sparc/sparc-bad-trap.S
index 2e73a4a7da..c20a97889f 100644
--- a/cpukit/score/cpu/sparc/sparc-bad-trap.S
+++ b/cpukit/score/cpu/sparc/sparc-bad-trap.S
@@ -208,20 +208,6 @@ SYM(_SPARC_Bad_trap):
         std     %f30, [%l7 + SPARC_EXCEPTION_OFFSET_FP(15)]
 #endif
 
-#if !defined(SPARC_USE_LAZY_FP_SWITCH)
-        /*
-         * Call
-         * _Internal_error( INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT )
-         * if necessary.
-         */
-        cmp     %l3, 4
-        bne     .Lno_fp_disable_trap
-         nop
-        call    SYM(_Internal_error)
-         set    38, %o0
-.Lno_fp_disable_trap:
-#endif
-
         /*
          * Call _Terminate( RTEMS_FATAL_SOURCE_EXCEPTION, %l0 ).
          */
diff --git a/testsuites/sptests/spfatal30/init.c b/testsuites/sptests/spfatal30/init.c
index a02bf062f4..a76fe1f309 100644
--- a/testsuites/sptests/spfatal30/init.c
+++ b/testsuites/sptests/spfatal30/init.c
@@ -22,9 +22,28 @@
 
 const char rtems_test_name[] = "SPFATAL 30";
 
-#if (CPU_HARDWARE_FP == TRUE && CPU_ALL_TASKS_ARE_FP == FALSE) \
-  || SPARC_HAS_FPU == 1
-#define EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+#if ( CPU_HARDWARE_FP == TRUE && CPU_ALL_TASKS_ARE_FP == FALSE ) || \
+  defined(SPARC_USE_LAZY_FP_SWITCH)
+
+#define EXPECTED_FATAL_SOURCE INTERNAL_ERROR_CORE
+
+static bool is_expected_fatal_code( rtems_fatal_code code )
+{
+  return code == INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT;
+}
+
+#elif defined(SPARC_USE_SYNCHRONOUS_FP_SWITCH)
+
+#define EXPECTED_FATAL_SOURCE RTEMS_FATAL_SOURCE_EXCEPTION
+
+static bool is_expected_fatal_code( rtems_fatal_code code )
+{
+  const rtems_exception_frame *frame;
+
+  frame = (const rtems_exception_frame *) code;
+  return frame->trap == 4;
+}
+
 #endif
 
 static volatile double f = 1.0;
@@ -35,7 +54,7 @@ static void Init(rtems_task_argument arg)
 
   f *= 123.456;
 
-#ifdef EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+#ifdef EXPECTED_FATAL_SOURCE
   rtems_test_assert(0);
 #else
   TEST_END();
@@ -43,7 +62,7 @@ static void Init(rtems_task_argument arg)
 #endif
 }
 
-#ifdef EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+#ifdef EXPECTED_FATAL_SOURCE
 static void fatal_extension(
   rtems_fatal_source source,
   bool always_set_to_false,
@@ -51,9 +70,9 @@ static void fatal_extension(
 )
 {
   if (
-    source == INTERNAL_ERROR_CORE
+    source == EXPECTED_FATAL_SOURCE
       && !always_set_to_false
-      && code == INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+      && is_expected_fatal_code( code )
   ) {
     TEST_END();
   }
@@ -63,11 +82,11 @@ static void fatal_extension(
   { .fatal = fatal_extension }, \
   RTEMS_TEST_INITIAL_EXTENSION
 
-#else /* EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT */
+#else /* EXPECTED_FATAL_SOURCE */
 
 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
 
-#endif /* EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT */
+#endif /* EXPECTED_FATAL_SOURCE */
 
 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
 
diff --git a/testsuites/sptests/spfatal31/init.c b/testsuites/sptests/spfatal31/init.c
index 5aab6630dc..782e7632cc 100644
--- a/testsuites/sptests/spfatal31/init.c
+++ b/testsuites/sptests/spfatal31/init.c
@@ -22,8 +22,27 @@
 
 const char rtems_test_name[] = "SPFATAL 31";
 
-#if SPARC_HAS_FPU == 1
-#define EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+#if defined(SPARC_USE_LAZY_FP_SWITCH)
+
+#define EXPECTED_FATAL_SOURCE INTERNAL_ERROR_CORE
+
+static bool is_expected_fatal_code( rtems_fatal_code code )
+{
+  return code == INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT;
+}
+
+#elif defined(SPARC_USE_SYNCHRONOUS_FP_SWITCH)
+
+#define EXPECTED_FATAL_SOURCE RTEMS_FATAL_SOURCE_EXCEPTION
+
+static bool is_expected_fatal_code( rtems_fatal_code code )
+{
+  const rtems_exception_frame *frame;
+
+  frame = (const rtems_exception_frame *) code;
+  return frame->trap == 4;
+}
+
 #endif
 
 static volatile double f = 1.0;
@@ -49,7 +68,7 @@ static void Init(rtems_task_argument arg)
   sc = rtems_task_wake_after(2);
   rtems_test_assert(sc == RTEMS_SUCCESSFUL);
 
-#ifdef EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+#ifdef EXPECTED_FATAL_SOURCE
   rtems_test_assert(0);
 #else
   TEST_END();
@@ -57,7 +76,7 @@ static void Init(rtems_task_argument arg)
 #endif
 }
 
-#ifdef EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+#ifdef EXPECTED_FATAL_SOURCE
 static void fatal_extension(
   rtems_fatal_source source,
   bool always_set_to_false,
@@ -65,9 +84,9 @@ static void fatal_extension(
 )
 {
   if (
-    source == INTERNAL_ERROR_CORE
+    source == EXPECTED_FATAL_SOURCE
       && !always_set_to_false
-      && code == INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
+      && is_expected_fatal_code( code )
   ) {
     TEST_END();
   }
@@ -77,11 +96,11 @@ static void fatal_extension(
   { .fatal = fatal_extension }, \
   RTEMS_TEST_INITIAL_EXTENSION
 
-#else /* EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT */
+#else /* EXPECTED_FATAL_SOURCE */
 
 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
 
-#endif /* EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT */
+#endif /* EXPECTED_FATAL_SOURCE */
 
 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
 
-- 
2.26.2



More information about the devel mailing list