aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoern Rennecke <joern.rennecke@embecosm.com>2005-09-19 11:29:30 +0000
committerJoern Rennecke <joern.rennecke@embecosm.com>2005-09-19 11:29:30 +0000
commit6a8492b56206bf8da71d94d96a76b15f995b8621 (patch)
tree0e180e443d72cea1d59b77848b770b53ea80fcea
parent5c3dead3ce91fef110822a6d5cd6842d039ec858 (diff)
downloadfsf-binutils-gdb-6a8492b56206bf8da71d94d96a76b15f995b8621.zip
fsf-binutils-gdb-6a8492b56206bf8da71d94d96a76b15f995b8621.tar.gz
fsf-binutils-gdb-6a8492b56206bf8da71d94d96a76b15f995b8621.tar.bz2
* interp.c (<sys/mman.h>): Include.
(mcalloc): New function / macro. (mfree): New macro. (sim_size): Use mcalloc and mfree.
-rw-r--r--sim/sh/ChangeLog7
-rw-r--r--sim/sh/interp.c40
2 files changed, 42 insertions, 5 deletions
diff --git a/sim/sh/ChangeLog b/sim/sh/ChangeLog
index 4f2aea3..ee6bfe1 100644
--- a/sim/sh/ChangeLog
+++ b/sim/sh/ChangeLog
@@ -1,3 +1,10 @@
+2005-09-19 J"orn Rennecke <joern.rennecke@st.com>
+
+ * interp.c (<sys/mman.h>): Include.
+ (mcalloc): New function / macro.
+ (mfree): New macro.
+ (sim_size): Use mcalloc and mfree.
+
2005-08-02 J"orn Rennecke <joern.rennecke@st.com>
* interp.c (strswaplen): Add one for '\0' delimiter.
diff --git a/sim/sh/interp.c b/sim/sh/interp.c
index 107842b..235d6bb 100644
--- a/sim/sh/interp.c
+++ b/sim/sh/interp.c
@@ -24,6 +24,15 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_MMAP
+#include <sys/mman.h>
+# ifndef MAP_FAILED
+# define MAP_FAILED -1
+# endif
+# if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
+# define MAP_ANONYMOUS MAP_ANON
+# endif
+#endif
#include "sysdep.h"
#include "bfd.h"
@@ -1715,6 +1724,27 @@ static void ppi_insn ();
#include "ppi.c"
+/* Provide calloc / free versions that use an anonymous mmap. This can
+ significantly cut the start-up time when a large simulator memory is
+ required, because pages are only zeroed on demand. */
+#ifdef MAP_ANONYMOUS
+void *
+mcalloc (size_t nmemb, size_t size)
+{
+ void *page;
+
+ if (nmemb != 1)
+ size *= nmemb;
+ return mmap (0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
+ -1, 0);
+}
+
+#define mfree(start,length) munmap ((start), (length))
+#else
+#define mcalloc calloc
+#define mfree(start,length) free(start)
+#endif
+
/* Set the memory size to the power of two provided. */
void
@@ -1722,17 +1752,17 @@ sim_size (power)
int power;
{
- saved_state.asregs.msize = 1 << power;
-
sim_memory_size = power;
if (saved_state.asregs.memory)
{
- free (saved_state.asregs.memory);
+ mfree (saved_state.asregs.memory, saved_state.asregs.msize);
}
+ saved_state.asregs.msize = 1 << power;
+
saved_state.asregs.memory =
- (unsigned char *) calloc (64, saved_state.asregs.msize / 64);
+ (unsigned char *) mcalloc (1, saved_state.asregs.msize);
if (!saved_state.asregs.memory)
{
@@ -1741,7 +1771,7 @@ sim_size (power)
saved_state.asregs.msize);
saved_state.asregs.msize = 1;
- saved_state.asregs.memory = (unsigned char *) calloc (1, 1);
+ saved_state.asregs.memory = (unsigned char *) mcalloc (1, 1);
}
}