[PATCH] mm: Add infrastructure for basic memory management

Gedare Bloom gedare at rtems.org
Mon Feb 18 17:47:19 UTC 2013


---
 c/src/lib/libcpu/shared/include/mm.h   |   35 ++++++++++++++
 c/src/lib/libcpu/shared/src/no_mm.c    |   18 +++++++
 cpukit/score/Makefile.am               |    2 +
 cpukit/score/include/rtems/score/mm.h  |   53 ++++++++++++++++++++
 cpukit/score/inline/rtems/score/mm.inl |   77 ++++++++++++++++++++++++++++++
 cpukit/score/preinstall.am             |    8 +++
 testsuites/sptests/Makefile.am         |    3 +-
 testsuites/sptests/configure.ac        |    2 +
 testsuites/sptests/spmm01/Makefile.am  |   18 +++++++
 testsuites/sptests/spmm01/init.c       |   62 ++++++++++++++++++++++++
 testsuites/sptests/spmm01/spmm01.scn   |    1 +
 testsuites/sptests/spmm01/system.h     |   27 ++++++++++
 testsuites/sptests/spmm02/Makefile.am  |   18 +++++++
 testsuites/sptests/spmm02/init.c       |   82 ++++++++++++++++++++++++++++++++
 testsuites/sptests/spmm02/system.h     |   27 ++++++++++
 15 files changed, 432 insertions(+), 1 deletions(-)
 create mode 100644 c/src/lib/libcpu/shared/include/mm.h
 create mode 100644 c/src/lib/libcpu/shared/src/no_mm.c
 create mode 100644 cpukit/score/include/rtems/score/mm.h
 create mode 100644 cpukit/score/inline/rtems/score/mm.inl
 create mode 100644 testsuites/sptests/spmm01/Makefile.am
 create mode 100644 testsuites/sptests/spmm01/init.c
 create mode 100644 testsuites/sptests/spmm01/spmm01.scn
 create mode 100644 testsuites/sptests/spmm01/system.h
 create mode 100644 testsuites/sptests/spmm02/Makefile.am
 create mode 100644 testsuites/sptests/spmm02/init.c
 create mode 100644 testsuites/sptests/spmm02/spmm02.scn
 create mode 100644 testsuites/sptests/spmm02/system.h

diff --git a/c/src/lib/libcpu/shared/include/mm.h b/c/src/lib/libcpu/shared/include/mm.h
new file mode 100644
index 0000000..82d1090
--- /dev/null
+++ b/c/src/lib/libcpu/shared/include/mm.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#ifndef __LIBCPU_MM_H
+#define __LIBCPU_MM_H
+
+#include <rtems/score/mm.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void _CPU_Memory_management_Initialize(void);
+
+void _CPU_Memory_management_Install_entry(
+    Memory_management_Entry *mme
+);
+
+void _CPU_Memory_management_Set_read_only(
+    Memory_management_Entry *mme
+);
+
+void _CPU_Memory_management_Set_write(
+    Memory_management_Entry *mme
+);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/c/src/lib/libcpu/shared/src/no_mm.c b/c/src/lib/libcpu/shared/src/no_mm.c
new file mode 100644
index 0000000..7f8444f
--- /dev/null
+++ b/c/src/lib/libcpu/shared/src/no_mm.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#include <rtems.h>
+#include <libcpu/mm.h>
+
+void _CPU_Memory_management_Initialize( void ) { }
+
+void _CPU_Memory_management_Install_MPE( Memory_management_Entry *mpe ) { }
+
+void _CPU_Memory_management_Set_read_only( Memory_management_Entry *mpe ) { }
+
+void _CPU_Memory_management_Set_write( Memory_management_Entry *mpe ) { }
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 8da32a5..47efcea 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -30,6 +30,7 @@ include_rtems_score_HEADERS += include/rtems/score/protectedheap.h
 include_rtems_score_HEADERS += include/rtems/score/interr.h
 include_rtems_score_HEADERS += include/rtems/score/isr.h
 include_rtems_score_HEADERS += include/rtems/score/isrlevel.h
+include_rtems_score_HEADERS += include/rtems/score/mm.h
 include_rtems_score_HEADERS += include/rtems/score/object.h
 include_rtems_score_HEADERS += include/rtems/score/percpu.h
 include_rtems_score_HEADERS += include/rtems/score/priority.h
@@ -92,6 +93,7 @@ include_rtems_score_HEADERS += inline/rtems/score/coremutex.inl
 include_rtems_score_HEADERS += inline/rtems/score/coresem.inl
 include_rtems_score_HEADERS += inline/rtems/score/heap.inl
 include_rtems_score_HEADERS += inline/rtems/score/isr.inl
+include_rtems_score_HEADERS += inline/rtems/score/mm.inl
 include_rtems_score_HEADERS += inline/rtems/score/object.inl
 include_rtems_score_HEADERS += inline/rtems/score/priority.inl
 include_rtems_score_HEADERS += inline/rtems/score/prioritybitmap.inl
diff --git a/cpukit/score/include/rtems/score/mm.h b/cpukit/score/include/rtems/score/mm.h
new file mode 100644
index 0000000..f3dcfd1
--- /dev/null
+++ b/cpukit/score/include/rtems/score/mm.h
@@ -0,0 +1,53 @@
+/**
+ * @file
+ *
+ * @brief Manages use of MPU/MMU units to provide memory management.
+ */
+
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ * Copyright (c) 2012 Hesham Al-Matary.
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_SCORE_MM_H
+#define _RTEMS_SCORE_MM_H
+
+/* @defgroup SuperCoreMM Memory Management Support
+ *
+ * @ingroup Score
+ */
+/**@{*/
+
+#include <inttypes.h>
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/**
+ * @brief A managed _Memory_management_Region.
+ */
+typedef struct {
+  char *name;
+  uintptr_t base;
+  size_t size;
+  bool installed;
+  /* points to structure defining the BSP specific MM entry */
+  void *bsp_mme;
+} Memory_management_Entry;
+
+#ifndef __RTEMS_APPLICATION__
+#include <rtems/score/mm.inl>
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/**@}*/
+
+#endif
diff --git a/cpukit/score/inline/rtems/score/mm.inl b/cpukit/score/inline/rtems/score/mm.inl
new file mode 100644
index 0000000..abe065d
--- /dev/null
+++ b/cpukit/score/inline/rtems/score/mm.inl
@@ -0,0 +1,77 @@
+/**
+ * @file
+ *
+ * @brief Inlined Routines from the Memory Management Manager
+ */
+
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#ifndef _RTEMS_SCORE_MM_H
+# error "Never use <rtems/score/mm.inl> directly; include <rtems/score/mm.h> instead."
+#endif
+
+#ifndef _RTEMS_SCORE_MM_INL
+#define _RTEMS_SCORE_MM_INL
+
+/**
+ * @addtogroup SuperCoreMM
+ */
+/**@{**/
+
+/**
+ * @brief Calls _CPU_Memory_management_Initialize.
+ */
+RTEMS_INLINE_ROUTINE void _Memory_management_Initialize( void )
+{
+  _CPU_Memory_management_Initialize();
+}
+
+/**
+ * @brief Calls _CPU_Memory_management_Install_entry.
+ */
+RTEMS_INLINE_ROUTINE void _Memory_management_Install_entry(
+  Memory_management_Entry *mme
+)
+{
+  _CPU_Memory_management_Install_entry(mme);
+}
+
+/**
+ * @brief Calls _CPU_Memory_management_Uninstall_entry.
+ */
+RTEMS_INLINE_ROUTINE void _Memory_management_Uninstall_entry(
+  Memory_management_Entry *mme
+)
+{
+  _CPU_Memory_management_Uninstall_entry(mme);
+}
+
+/**
+ * @brief Calls _CPU_Memory_management_Set_write.
+ */
+RTEMS_INLINE_ROUTINE void _Memory_management_Set_write(
+  Memory_management_Entry *mme
+)
+{
+  _CPU_Memory_management_Set_write(mme);
+}
+
+/**
+ * @brief Calls _CPU_Memory_management_Set_read_only
+ */
+RTEMS_INLINE_ROUTINE void _Memory_management_Set_read_only(
+  Memory_management_Entry *mme
+)
+{
+  _CPU_Memory_management_Set_read_only(mme);
+}
+
+/** @}*/
+
+#endif
diff --git a/cpukit/score/preinstall.am b/cpukit/score/preinstall.am
index a346c79..d3d0ea5 100644
--- a/cpukit/score/preinstall.am
+++ b/cpukit/score/preinstall.am
@@ -103,6 +103,10 @@ $(PROJECT_INCLUDE)/rtems/score/isrlevel.h: include/rtems/score/isrlevel.h $(PROJ
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/isrlevel.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/isrlevel.h
 
+$(PROJECT_INCLUDE)/rtems/score/mm.h: include/rtems/score/mm.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/mm.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/mm.h
+
 $(PROJECT_INCLUDE)/rtems/score/object.h: include/rtems/score/object.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/object.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/object.h
@@ -292,6 +296,10 @@ $(PROJECT_INCLUDE)/rtems/score/isr.inl: inline/rtems/score/isr.inl $(PROJECT_INC
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/isr.inl
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/isr.inl
 
+$(PROJECT_INCLUDE)/rtems/score/mm.inl: inline/rtems/score/mm.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
+	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/mm.inl
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/mm.inl
+
 $(PROJECT_INCLUDE)/rtems/score/object.inl: inline/rtems/score/object.inl $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/object.inl
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/object.inl
diff --git a/testsuites/sptests/Makefile.am b/testsuites/sptests/Makefile.am
index c9d20dd..81d9089 100644
--- a/testsuites/sptests/Makefile.am
+++ b/testsuites/sptests/Makefile.am
@@ -24,7 +24,8 @@ SUBDIRS = \
     spintrcritical05 spintrcritical06 spintrcritical07 spintrcritical08 \
     spintrcritical09 spintrcritical10 spintrcritical11 spintrcritical12 \
     spintrcritical13 spintrcritical14 spintrcritical15 spintrcritical16 \
-    spintrcritical17 spintrcritical18 spmkdir spmountmgr01 spheapprot \
+    spintrcritical17 spintrcritical18 \
+    spmkdir spmm01 spmm02 spmountmgr01 spheapprot \
     spsimplesched01 spsimplesched02 spsimplesched03 spnsext01 \
     spedfsched01 spedfsched02 spedfsched03 \
     spcbssched01 spcbssched02 spcbssched03 spqreslib sptimespec01 \
diff --git a/testsuites/sptests/configure.ac b/testsuites/sptests/configure.ac
index 2e48949..6cb1d46 100644
--- a/testsuites/sptests/configure.ac
+++ b/testsuites/sptests/configure.ac
@@ -183,6 +183,8 @@ spintrcritical16/Makefile
 spintrcritical17/Makefile
 spheapprot/Makefile
 spmkdir/Makefile
+spmm01/Makefile
+spmm02/Makefile
 spmountmgr01/Makefile
 spnotepad01/Makefile
 spnsext01/Makefile
diff --git a/testsuites/sptests/spmm01/Makefile.am b/testsuites/sptests/spmm01/Makefile.am
new file mode 100644
index 0000000..7f8b851
--- /dev/null
+++ b/testsuites/sptests/spmm01/Makefile.am
@@ -0,0 +1,18 @@
+
+rtems_tests_PROGRAMS = spmm01
+spmm01_SOURCES = init.c system.h
+
+dist_rtems_tests_DATA = mmtests.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+LINK_OBJS = $(spmm01_OBJECTS) $(spmm01_LDADD)
+LINK_LIBS = $(spmm01_LDLIBS)
+
+spmm01$(EXEEXT): $(spmm01_OBJECTS) $(spmm01_DEPENDENCIES)
+	  @rm -f spmm01$(EXEEXT)
+	  $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spmm01/init.c b/testsuites/sptests/spmm01/init.c
new file mode 100644
index 0000000..4f48ebb
--- /dev/null
+++ b/testsuites/sptests/spmm01/init.c
@@ -0,0 +1,62 @@
+/* Init
+ *
+ * This routine is the initialization task for this test program.
+ *
+ */
+
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ * Copyright (c) 2012 Hesham Al-Matary.
+ *
+ * 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.
+ */
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/score/mm.h>
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  Memory_management_Entry mme1 = {
+    .name = "Valid Entry-1",
+    .base = 0x00100000,
+    .size = 0x200000,
+    .installed = false,
+    .bsp_mme = NULL
+  };
+  Memory_management_Entry mme2 = {
+    .name = "Valid Entry-2",
+    .base = 0x00400000,
+    .size = 0x100000,
+    .installed = false,
+    .bsp_mme = NULL
+  };
+
+  puts( "\n\n*** Start of spmm01 ***\n" );
+
+  puts( "initialize the memory management manager\n");
+  _Memory_management_Initialize ( );
+
+  printf("Test 1: Installing Entry-1\n");
+  _Memory_management_Install_entry( &mme1 );
+
+  printf("Test 2: Set Read only for installed Entry-1 permissions\n");
+  _Memory_management_Set_read_only( &mme1 );
+
+  printf("Test 3 : Installing Entry-2\n");
+  _Memory_management_Install_entry( &mme2 );
+
+  printf("Test 4: Set Write permission for installed Entry-2\n");
+  _Memory_management_Set_write( &mme2 );
+
+  printf( "\n\n*** End of spmm01 ***\n" );
+
+  exit( 0 );
+}
diff --git a/testsuites/sptests/spmm01/spmm01.scn b/testsuites/sptests/spmm01/spmm01.scn
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/testsuites/sptests/spmm01/spmm01.scn
@@ -0,0 +1 @@
+
diff --git a/testsuites/sptests/spmm01/system.h b/testsuites/sptests/spmm01/system.h
new file mode 100644
index 0000000..206ef29
--- /dev/null
+++ b/testsuites/sptests/spmm01/system.h
@@ -0,0 +1,27 @@
+/* system.h
+ *
+ * Copyright (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#include <rtems.h>
+
+/* functions */
+rtems_task Init(
+  rtems_task_argument argument
+);
+
+/* configuration information */
+#include <bsp.h> /* for device driver prototypes */
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS            2
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#include <rtems/confdefs.h>
+/* end of include file */
diff --git a/testsuites/sptests/spmm02/Makefile.am b/testsuites/sptests/spmm02/Makefile.am
new file mode 100644
index 0000000..405e336
--- /dev/null
+++ b/testsuites/sptests/spmm02/Makefile.am
@@ -0,0 +1,18 @@
+
+rtems_tests_PROGRAMS = spmm02
+spmm02_SOURCES = init.c system.h
+
+dist_rtems_tests_DATA = mmtests.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+LINK_OBJS = $(spmm02_OBJECTS) $(spmm02_LDADD)
+LINK_LIBS = $(spmm02_LDLIBS)
+
+spmm02$(EXEEXT): $(spmm02_OBJECTS) $(spmm02_DEPENDENCIES)
+	  @rm -f spmm02$(EXEEXT)
+	  $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/sptests/spmm02/init.c b/testsuites/sptests/spmm02/init.c
new file mode 100644
index 0000000..fb52436
--- /dev/null
+++ b/testsuites/sptests/spmm02/init.c
@@ -0,0 +1,82 @@
+/* Init
+ *
+ * This routine is the initialization task for this test program.
+ */
+
+/*
+ * Copyright (c) 2013 Gedare Bloom.
+ * Copyright (c) 2012 Hesham Al-Matary.
+ *
+ * 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.
+ */
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#define CONFIGURE_INIT
+#include "system.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <rtems/score/mm.h>
+
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  unsigned char* a1;
+  unsigned char* a2;
+  char a;
+
+  /* FIXME: Make these addresses target-independent */
+  Memory_management_Entry mme1 = {
+    .name = "Valid Entry-1",
+    .base = 0x00100000,
+    .size = 0x200000,
+    .installed = false,
+    .bsp_mme = NULL
+  };
+  Memory_management_Entry mme2 = {
+    .name = "Valid Entry-2",
+    .base = 0x00400000,
+    .size = 0x100000,
+    .installed = false,
+    .bsp_mme = NULL
+  };
+
+  puts( "\n\n*** Start of spmm02 ***\n" );
+
+  _Memory_management_Initialize ( );
+
+  printf("Test 1: Installing Entry-1\n");
+  _Memory_management_Install_entry( &mme1 );
+
+  printf("Test 2: Set Read only for installed Entry-1 permissions\n");
+  _Memory_management_Set_read_only( &mme1 );
+
+  printf("Test 3: Installing Entry-2\n");
+  _Memory_management_Install_entry( &mme2 );
+
+  printf("Test 4: Set Write permission for installed Entry-2\n");
+  _Memory_management_Set_write( &mme2 );
+
+  /* FIXME: Make fatal tests? */
+  /* FIXME: make addresses target-independent */
+  a1 = (char*)0xffffffffU;
+  printf("Checking MMU exception 1: Read from Unmapped block\n");
+  a = *a1++;
+
+  a1 = (char*)0xffffffffU + 0x2000U;
+  printf("Checking MMU exception 2: Write to Unmapped block\n");
+  //*a1++ = 0xCC;
+
+  // this one isn't an exception.
+  a2 = mme1.base;
+  printf("Checking MMU exception 3: Read from readonly block\n");
+  a = *a2++;
+
+  printf("Checking MMU exception 4: Write to readonly block  \n");
+   *a2++ = 0xCC;
+
+  printf(  "\n\n*** End of spmm02 ***\n" );
+  exit( 0 );
+}
diff --git a/testsuites/sptests/spmm02/spmm02.scn b/testsuites/sptests/spmm02/spmm02.scn
new file mode 100644
index 0000000..e69de29
diff --git a/testsuites/sptests/spmm02/system.h b/testsuites/sptests/spmm02/system.h
new file mode 100644
index 0000000..15dd018
--- /dev/null
+++ b/testsuites/sptests/spmm02/system.h
@@ -0,0 +1,27 @@
+/* system.h
+ *
+ * COPYRIGHT (c) 2013 Gedare Bloom.
+ *
+ * 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.
+ */
+
+#include <rtems.h>
+
+/* functions */
+rtems_task Init(
+  rtems_task_argument argument
+);
+
+/* configuration information */
+#include <bsp.h> /* for device driver prototypes */
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS            2
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#include <rtems/confdefs.h>
+/* end of include file */
-- 
1.7.1




More information about the devel mailing list