[PATCH] cpu part of the i386 virtualization layer
Philipp Eppelt
philipp.eppelt at mailbox.tu-dresden.de
Thu Dec 5 15:59:12 UTC 2013
---
cpukit/score/cpu/i386/Makefile.am | 1 +
cpukit/score/cpu/i386/cpu.c | 18 +++++
cpukit/score/cpu/i386/preinstall.am | 4 +
cpukit/score/cpu/i386/rtems/score/cpu.h | 48 +++++++++---
cpukit/score/cpu/i386/rtems/score/interrupts.h | 32 ++++++++
.../cpu/i386/rtems/score/virtualizationlayercpu.h | 91 ++++++++++++++++++++++
6 files changed, 182 insertions(+), 12 deletions(-)
create mode 100644 cpukit/score/cpu/i386/rtems/score/virtualizationlayercpu.h
diff --git a/cpukit/score/cpu/i386/Makefile.am b/cpukit/score/cpu/i386/Makefile.am
index e35a81c..8f196c5 100644
--- a/cpukit/score/cpu/i386/Makefile.am
+++ b/cpukit/score/cpu/i386/Makefile.am
@@ -12,6 +12,7 @@ include_rtems_score_HEADERS += rtems/score/registers.h
include_rtems_score_HEADERS += rtems/score/idtr.h
include_rtems_score_HEADERS += rtems/score/cpuatomic.h
include_rtems_score_HEADERS += rtems/score/cpusmplock.h
+include_rtems_score_HEADERS += rtems/score/virtualizationlayercpu.h
noinst_LIBRARIES = libscorecpu.a
libscorecpu_a_SOURCES = cpu.c cpu_asm.S
diff --git a/cpukit/score/cpu/i386/cpu.c b/cpukit/score/cpu/i386/cpu.c
index c87a76d..39b87b0 100644
--- a/cpukit/score/cpu/i386/cpu.c
+++ b/cpukit/score/cpu/i386/cpu.c
@@ -26,6 +26,8 @@
#include <rtems/bspIo.h>
#include <rtems/score/thread.h>
+#include <rtems/score/virtualizationlayercpu.h>
+
void _CPU_Initialize(void)
{
#if CPU_HARDWARE_FP
@@ -97,6 +99,20 @@ uint32_t _CPU_ISR_Get_level( void )
return level;
}
+
+#if defined(RTEMS_PARAVIRT)
+
+void *_CPU_Thread_Idle_body( uintptr_t ignored )
+{
+ while(1)
+ {
+ _CPU_Virtual_Idle_thread();
+ }
+ return NULL;
+}
+
+#else
+
void *_CPU_Thread_Idle_body( uintptr_t ignored )
{
while(1){
@@ -105,6 +121,8 @@ void *_CPU_Thread_Idle_body( uintptr_t ignored )
return NULL;
}
+#endif /*RTEMS_PARAVIRT*/
+
struct Frame_ {
struct Frame_ *up;
uintptr_t pc;
diff --git a/cpukit/score/cpu/i386/preinstall.am b/cpukit/score/cpu/i386/preinstall.am
index f9faf87..363e1fb 100644
--- a/cpukit/score/cpu/i386/preinstall.am
+++ b/cpukit/score/cpu/i386/preinstall.am
@@ -59,3 +59,7 @@ $(PROJECT_INCLUDE)/rtems/score/cpusmplock.h: rtems/score/cpusmplock.h $(PROJECT_
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/cpusmplock.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/cpusmplock.h
+$(PROJECT_INCLUDE)/rtems/score/virtualizationlayercpu.h: rtems/score/virtualizationlayercpu.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/virtualizationlayercpu.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/virtualizationlayercpu.h
+
diff --git a/cpukit/score/cpu/i386/rtems/score/cpu.h b/cpukit/score/cpu/i386/rtems/score/cpu.h
index 43422ed..0a03253 100644
--- a/cpukit/score/cpu/i386/rtems/score/cpu.h
+++ b/cpukit/score/cpu/i386/rtems/score/cpu.h
@@ -35,6 +35,8 @@ extern "C" {
#include <rtems/score/registers.h> /* formerly part of libcpu */
#endif
+#include <rtems/score/virtualizationlayercpu.h>
+
/* conditional compilation parameters */
#define CPU_INLINE_ENABLE_DISPATCH TRUE
@@ -376,11 +378,22 @@ SCORE_EXTERN Context_Control_fp _CPU_Null_fp_context;
#define _CPU_ISR_Flash( _level ) i386_flash_interrupts( _level )
-#define _CPU_ISR_Set_level( _new_level ) \
- { \
- if ( _new_level ) __asm__ volatile ( "cli" ); \
- else __asm__ volatile ( "sti" ); \
- }
+#if defined(RTEMS_PARAVIRT)
+ #define _CPU_ISR_Set_level( _new_level ) \
+ { \
+ if( _new_level ) _CPU_Virtual_Interrupts_close(); \
+ else _CPU_Virtual_Interrupts_open(); \
+ }
+
+#else
+
+ #define _CPU_ISR_Set_level( _new_level ) \
+ { \
+ if ( _new_level ) __asm__ volatile ( "cli" ); \
+ else __asm__ volatile ( "sti" ); \
+ }
+
+#endif /*RTEMS_PARAVIRT*/
uint32_t _CPU_ISR_Get_level( void );
@@ -497,16 +510,27 @@ uint32_t _CPU_ISR_Get_level( void );
* + disable interrupts and halt the CPU
*/
-#define _CPU_Fatal_halt( _error ) \
+#if defined(RTEMS_PARAVIRT)
+ #define _CPU_Fatal_halt( _error ) \
{ \
- uint32_t _error_lvalue = ( _error ); \
- __asm__ volatile ( "cli ; \
- movl %0,%%eax ; \
- hlt" \
- : "=r" ((_error_lvalue)) : "0" ((_error_lvalue)) \
- ); \
+ _CPU_Virtual_Interrupts_close(); \
+ _CPU_Virtual_Stop_with_error( _error ); \
}
+#else
+
+ #define _CPU_Fatal_halt( _error ) \
+ { \
+ uint32_t _error_lvalue = ( _error ); \
+ __asm__ volatile ( "cli ; \
+ movl %0,%%eax ; \
+ hlt" \
+ : "=r" ((_error_lvalue)) : "0" ((_error_lvalue)) \
+ ); \
+ }
+
+#endif /*RTEMS_PARAVIRT*/
+
#endif /* ASM */
/* end of Fatal Error manager macros */
diff --git a/cpukit/score/cpu/i386/rtems/score/interrupts.h b/cpukit/score/cpu/i386/rtems/score/interrupts.h
index bed6330..e19b356 100644
--- a/cpukit/score/cpu/i386/rtems/score/interrupts.h
+++ b/cpukit/score/cpu/i386/rtems/score/interrupts.h
@@ -19,6 +19,8 @@
#ifndef _RTEMS_SCORE_INTERRUPTS_H
#define _RTEMS_SCORE_INTERRUPTS_H
+#include <rtems/score/virtualizationlayercpu.h>
+
#ifndef ASM
struct __rtems_raw_irq_connect_data__;
@@ -33,6 +35,35 @@ typedef int (*rtems_raw_irq_is_enabled) (const struct __rtems_raw_irq_connect_d
*
*/
/**@{**/
+#if defined(RTEMS_PARAVIRT)
+
+#define i386_disable_interrupts( _level ) \
+ { \
+ _CPU_Virtual_Interrupts_disable( _level ); \
+ }
+
+#define i386_enable_interrupts( _level ) \
+ { \
+ _CPU_Virtual_Interrupts_enable( _level ); \
+ }
+
+#define i386_flash_interrupts( _level ) \
+ { \
+ _CPU_Virtual_Interrupts_enable(_level); \
+ _CPU_Virtual_Interrupts_disable(_level); \
+ }
+
+#define i386_get_interrupt_level( _level ) \
+ { \
+ _CPU_Virtual_Interrupts_get_level( _level ); \
+ }
+
+#define _CPU_ISR_Disable( _level ) i386_disable_interrupts( _level )
+#define _CPU_ISR_Enable( _level ) i386_enable_interrupts( _level )
+
+
+#else /*RTEMS_PARAVIRT*/
+
#define i386_disable_interrupts( _level ) \
{ \
@@ -75,6 +106,7 @@ typedef int (*rtems_raw_irq_is_enabled) (const struct __rtems_raw_irq_connect_d
#define _CPU_ISR_Disable( _level ) i386_disable_interrupts( _level )
#define _CPU_ISR_Enable( _level ) i386_enable_interrupts( _level )
+#endif /*RTEMS_PARAVIRT*/
/** @} */
#endif
diff --git a/cpukit/score/cpu/i386/rtems/score/virtualizationlayercpu.h b/cpukit/score/cpu/i386/rtems/score/virtualizationlayercpu.h
new file mode 100644
index 0000000..9f3d5a5
--- /dev/null
+++ b/cpukit/score/cpu/i386/rtems/score/virtualizationlayercpu.h
@@ -0,0 +1,91 @@
+/*
+ *
+ * COPYRIGHT (c) 2013 Philipp Eppelt.
+ * philipp.eppelt at mailbox.tu-dresden.de
+ *
+ * Purpose: CPU part of the virtualization layer.
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#if defined(RTEMS_PARAVIRT)
+
+#ifndef RTEMS_VIRT_LAYER_CPU_H
+#define RTEMS_VIRT_LAYER_CPU_H
+
+#ifndef ASM
+
+/* Interrupts */
+
+/**
+ * \brief Requests an interrupt vector.
+ */
+int
+_CPU_Virtual_Irq_request( int vector );
+
+/**
+ * \brief Releases an interrupt vector.
+ */
+void
+_CPU_Virtual_Irq_detach( int vector );
+
+/**
+ * \brief Enables interrupt delivery or sets it to the specified level.
+ *
+ * Use this function in collaboration with _CPU_Virtual_Interrupts_disable and
+ * use its returned _level as argument to this function to assure proper
+ * behaviour.
+ */
+void
+_CPU_Virtual_Interrupts_enable( int _level );
+
+/**
+ * \brief Disables interrupt delivery and returns the previous level.
+ *
+ */
+void
+_CPU_Virtual_Interrupts_disable( int _level );
+
+/**
+ * \brief Enables and directly disables interrupt delivery.
+ */
+void
+_CPU_Virtual_Interrupts_flash( int _level );
+
+/**
+ * \brief Requests the current interrupt level.
+ */
+int
+_CPU_Virtual_Interrupts_get_level( int _level );
+
+
+void
+_CPU_Virtual_Interrupts_open(void);
+void
+_CPU_Virtual_Interrupts_close( void );
+
+/* Idle Thread */
+
+/**
+ * \brief Lowest priority thread, doing nothing, never returns;
+ */
+
+void
+_CPU_Virtual_Idle_thread( void );
+
+
+/* Error handling */
+
+/**
+ * \brief Handlers execution errors.
+ */
+void
+_CPU_Virtual_Stop_with_error( int _error );
+
+#endif /* ASM */
+
+#endif /* RTEMS_VIRT_LAYER_CPU_H */
+
+#endif /*RTEMS_PARAVIRT*/
--
1.8.1.4
More information about the devel
mailing list