[rtems commit] score: Add _CPU_Instruction_illegal()
Sebastian Huber
sebh at rtems.org
Tue Jul 24 07:13:49 UTC 2018
Module: rtems
Branch: master
Commit: 3a646426aa421ab3e229ec483d8b29f2f56c29ac
Changeset: http://git.rtems.org/rtems/commit/?id=3a646426aa421ab3e229ec483d8b29f2f56c29ac
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu Jul 19 12:53:34 2018 +0200
score: Add _CPU_Instruction_illegal()
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 +++
.../score/cpu/bfin/include/rtems/score/cpuimpl.h | 5 +++
.../cpu/epiphany/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/i386/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/lm32/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/m32c/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/m68k/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/mips/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/moxie/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/nios2/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/no_cpu/include/rtems/score/cpuimpl.h | 10 ++++++
.../score/cpu/or1k/include/rtems/score/cpuimpl.h | 5 +++
.../cpu/powerpc/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/riscv/include/rtems/score/cpuimpl.h | 5 +++
cpukit/score/cpu/sh/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/sparc/include/rtems/score/cpuimpl.h | 5 +++
.../cpu/sparc64/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/v850/include/rtems/score/cpuimpl.h | 5 +++
.../score/cpu/x86_64/include/rtems/score/cpuimpl.h | 5 +++
testsuites/sptests/spfatal26/init.c | 40 ++++------------------
20 files changed, 106 insertions(+), 34 deletions(-)
diff --git a/cpukit/score/cpu/arm/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/arm/include/rtems/score/cpuimpl.h
index d007a79..b856349 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 5d8bd77..78b87ef 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 5d8bd77..78b87ef 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 5d8bd77..78b87ef 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 5d8bd77..78b87ef 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 5d8bd77..78b87ef 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 5d8bd77..965976b 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 ( "illegal" );
+}
+
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 5d8bd77..a6b5708 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 -1" );
+}
+
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 5d8bd77..78b87ef 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 a291aab..5f81020 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 c13180a..86d0ace 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 148e23c..e9beab8 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 4f5efe5..e46d9bf 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 c6e1015..c12bbbb 100644
--- a/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
+++ b/cpukit/score/cpu/riscv/include/rtems/score/cpuimpl.h
@@ -325,6 +325,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/sh/include/rtems/score/cpuimpl.h b/cpukit/score/cpu/sh/include/rtems/score/cpuimpl.h
index 5d8bd77..78b87ef 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 93e5b45..c125b8a 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 5d8bd77..fab09bb 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 5d8bd77..78b87ef 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 543c091..722edeb 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 1848659..a77c62a 100644
--- a/testsuites/sptests/spfatal26/init.c
+++ b/testsuites/sptests/spfatal26/init.c
@@ -1,8 +1,8 @@
/*
- * 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
+ * Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems at embedded-brains.de>
@@ -16,45 +16,17 @@
#include "config.h"
#endif
-#include "tmacros.h"
-
-#include <limits.h>
-
#include <rtems.h>
+#include <rtems/score/cpuimpl.h>
-const char rtems_test_name[] = "SPFATAL 26";
-
-static void provoke_aligment_or_data_access_exception( void )
-{
- uintptr_t one = 1;
- int i = sizeof(void *) * CHAR_BIT;
- uintptr_t n = 1;
- uintptr_t base = 0;
- uintptr_t inc;
-
- *(volatile uint64_t *) base;
-
- do {
- int j;
+#include <tmacros.h>
- --i;
- base = one << i;
- inc = base << 1;
-
- for (j = 0; j < n; ++j, base += inc) {
- *(volatile uint64_t *) base;
- }
-
- n <<= 1;
- } while (i > 0);
-}
+const char rtems_test_name[] = "SPFATAL 26";
static void Init( rtems_task_argument arg )
{
TEST_BEGIN();
-
- provoke_aligment_or_data_access_exception();
-
+ _CPU_Instruction_illegal();
rtems_test_assert( 0 );
}
More information about the vc
mailing list