[PATCH 3/3] score: Add _CPU_Instruction_illegal()

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Jul 20 06:53:59 UTC 2018


On some architectures/simulators it is difficult to provoke an
exception with misaligned or illegal data loads.  Use an illegal
instruction instead.

Update #3433.
---
 cpukit/score/cpu/arm/include/rtems/score/cpuimpl.h      |  5 +++++
 cpukit/score/cpu/bfin/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/epiphany/include/rtems/score/cpuimpl.h |  5 +++++
 cpukit/score/cpu/i386/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/lm32/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/m32c/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/m68k/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/mips/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/moxie/include/rtems/score/cpuimpl.h    |  5 +++++
 cpukit/score/cpu/nios2/include/rtems/score/cpuimpl.h    |  5 +++++
 cpukit/score/cpu/no_cpu/include/rtems/score/cpuimpl.h   | 10 ++++++++++
 cpukit/score/cpu/or1k/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/powerpc/include/rtems/score/cpuimpl.h  |  5 +++++
 cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h    |  5 +++++
 cpukit/score/cpu/sh/include/rtems/score/cpuimpl.h       |  5 +++++
 cpukit/score/cpu/sparc/include/rtems/score/cpuimpl.h    |  5 +++++
 cpukit/score/cpu/sparc64/include/rtems/score/cpuimpl.h  |  5 +++++
 cpukit/score/cpu/v850/include/rtems/score/cpuimpl.h     |  5 +++++
 cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h   |  5 +++++
 testsuites/sptests/spfatal26/init.c                     | 13 ++++++++++---
 20 files changed, 110 insertions(+), 3 deletions(-)

diff --git a/cpukit/score/cpu/arm/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/arm/include/rtems/score/cpuimpl.h
index d007a7982b..b856349db3 100644
--- a/cpukit/score/cpu/arm/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/arm/include/rtems/score/cpuimpl.h
@@ -106,6 +106,11 @@ void _CPU_Context_volatile_clobber( uintptr_t pattern );
 
 void _CPU_Context_validate( uintptr_t pattern );
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( "udf" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/bfin/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/bfin/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/bfin/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/bfin/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/epiphany/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/epiphany/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/epiphany/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/epiphany/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/i386/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/i386/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/i386/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/i386/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/lm32/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/lm32/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/lm32/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/lm32/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/m32c/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/m32c/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/m32c/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/m32c/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/m68k/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/m68k/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/m68k/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/m68k/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/mips/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/mips/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/mips/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/mips/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/moxie/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/moxie/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/moxie/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/moxie/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/nios2/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/nios2/include/rtems/score/cpuimpl.h
index a291aabe2f..5f8102009f 100644
--- a/cpukit/score/cpu/nios2/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/nios2/include/rtems/score/cpuimpl.h
@@ -29,6 +29,11 @@ void _CPU_Context_volatile_clobber( uintptr_t pattern );
 
 void _CPU_Context_validate( uintptr_t pattern );
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/no_cpu/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/no_cpu/include/rtems/score/cpuimpl.h
index c13180a06d..86d0ace0f3 100644
--- a/cpukit/score/cpu/no_cpu/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/no_cpu/include/rtems/score/cpuimpl.h
@@ -105,6 +105,16 @@ void _CPU_Context_volatile_clobber( uintptr_t pattern );
 void _CPU_Context_validate( uintptr_t pattern );
 
 /**
+ * @brief Emits an illegal instruction.
+ *
+ * This function is used only in test sptests/spfatal26.
+ */
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
+/**
  * @brief Emits a no operation instruction (nop).
  *
  * This function is used only in test sptests/spcache01.
diff --git a/cpukit/score/cpu/or1k/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/or1k/include/rtems/score/cpuimpl.h
index 148e23c309..e9beab85c8 100644
--- a/cpukit/score/cpu/or1k/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/or1k/include/rtems/score/cpuimpl.h
@@ -29,6 +29,11 @@ void _CPU_Context_volatile_clobber( uintptr_t pattern );
 
 void _CPU_Context_validate( uintptr_t pattern );
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "l.nop" );
diff --git a/cpukit/score/cpu/powerpc/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/powerpc/include/rtems/score/cpuimpl.h
index 4f5efe5ba3..e46d9bfabc 100644
--- a/cpukit/score/cpu/powerpc/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/powerpc/include/rtems/score/cpuimpl.h
@@ -242,6 +242,11 @@ void _CPU_Context_volatile_clobber( uintptr_t pattern );
 
 void _CPU_Context_validate( uintptr_t pattern );
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
index 8c29b86c4d..dcf666d2ad 100644
--- a/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
@@ -317,6 +317,11 @@ void _CPU_Context_volatile_clobber( uintptr_t pattern );
 
 void _CPU_Context_validate( uintptr_t pattern );
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/sh/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/sh/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/sh/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/sh/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/sparc/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/sparc/include/rtems/score/cpuimpl.h
index 93e5b45437..c125b8af72 100644
--- a/cpukit/score/cpu/sparc/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/sparc/include/rtems/score/cpuimpl.h
@@ -150,6 +150,11 @@ void _CPU_Context_volatile_clobber( uintptr_t pattern );
 
 void _CPU_Context_validate( uintptr_t pattern );
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( "unimp" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/sparc64/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/sparc64/include/rtems/score/cpuimpl.h
index 5d8bd77161..fab09bb15b 100644
--- a/cpukit/score/cpu/sparc64/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/sparc64/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( "unimp" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/v850/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/v850/include/rtems/score/cpuimpl.h
index 5d8bd77161..78b87ef981 100644
--- a/cpukit/score/cpu/v850/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/v850/include/rtems/score/cpuimpl.h
@@ -37,6 +37,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
   }
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
 {
   __asm__ volatile ( "nop" );
diff --git a/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
index 543c0918d2..722edeb00e 100644
--- a/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h
@@ -47,6 +47,11 @@ RTEMS_INLINE_ROUTINE void _CPU_Context_volatile_clobber( uintptr_t pattern )
   /* TODO */
 }
 
+RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
+{
+  __asm__ volatile ( ".word 0" );
+}
+
 RTEMS_INLINE_ROUTINE void _CPU_Context_validate( uintptr_t pattern )
 {
   while (1) {
diff --git a/testsuites/sptests/spfatal26/init.c b/testsuites/sptests/spfatal26/init.c
index 1848659d6a..3643e46814 100644
--- a/testsuites/sptests/spfatal26/init.c
+++ b/testsuites/sptests/spfatal26/init.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2012, 2018 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Obere Lagerstr. 30
@@ -16,14 +16,20 @@
   #include "config.h"
 #endif
 
-#include "tmacros.h"
+#include <rtems.h>
+#include <rtems/score/cpuimpl.h>
 
 #include <limits.h>
 
-#include <rtems.h>
+#include <tmacros.h>
 
 const char rtems_test_name[] = "SPFATAL 26";
 
+static void provoke_illegal_instruction_exception( void )
+{
+  _CPU_Instruction_illegal();
+}
+
 static void provoke_aligment_or_data_access_exception( void )
 {
   uintptr_t one = 1;
@@ -53,6 +59,7 @@ static void Init( rtems_task_argument arg )
 {
   TEST_BEGIN();
 
+  provoke_illegal_instruction_exception();
   provoke_aligment_or_data_access_exception();
 
   rtems_test_assert( 0 );
-- 
2.13.7




More information about the devel mailing list