summaryrefslogtreecommitdiff
path: root/memory.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2010-11-18 14:03:58 +0100
committerTobias Klauser <tklauser@distanz.ch>2010-11-18 14:03:58 +0100
commit8db4c483d5e3941c9352ab5caa0808b391adfbfb (patch)
tree39081a294c95584899b1b31fe56e3730c06ab7f5 /memory.c
parent9a6abbb794bace7c472a4bcab806f227cedf0ff9 (diff)
Add memory handling module
Diffstat (limited to 'memory.c')
-rw-r--r--memory.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/memory.c b/memory.c
new file mode 100644
index 0000000..75b041f
--- /dev/null
+++ b/memory.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
+ *
+ * This file is part of nios2sim-ng.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "nios2sim-ng.h"
+#include "nios2.h"
+#include "memory.h"
+
+uint8_t memory_get_byte(struct memory *mem, int32_t offset)
+{
+ uint8_t *base = (uint8_t *) mem->base;
+ return base[offset];
+}
+
+void memory_dump(struct memory *mem, uint32_t offset, size_t count)
+{
+ size_t i;
+
+ for (i = 0; i < count; i++) {
+ if ((i + 1) % 4 == 1)
+ info("%08x: ", (unsigned int) (offset + i));
+ info(" %08x", mem->base[offset / 4 + i]);
+ if ((i + 1) % 4 == 0)
+ info("\n");
+ }
+}