Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/27267 )

Change subject: mem: Support initializing a memory with an image file.
......................................................................

mem: Support initializing a memory with an image file.

This is particularly useful for ROMs. It avoids forcing other components
of the simulation (the System object, the Workload object) from having
to know what ROMs exist, where they are, and what goes on them, and
leaves that to the config script.

Change-Id: Ibbcffffcb82e0d289f0b3942728c30b8f69d28ba
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27267
Reviewed-by: Gabe Black <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
Tested-by: Gem5 Cloud Project GCB service account <345032938...@cloudbuild.gserviceaccount.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/mem/AbstractMemory.py
M src/mem/abstract_mem.cc
M src/mem/abstract_mem.hh
3 files changed, 41 insertions(+), 0 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass
  Gem5 Cloud Project GCB service account: Regressions pass



diff --git a/src/mem/AbstractMemory.py b/src/mem/AbstractMemory.py
index 897e9e3..4c21d52 100644
--- a/src/mem/AbstractMemory.py
+++ b/src/mem/AbstractMemory.py
@@ -64,3 +64,8 @@
     # configuration information about the physical memory layout to
     # the kernel, e.g. using ATAG or ACPI
     conf_table_reported = Param.Bool(True, "Report to configuration table")
+
+    # Image file to load into this memory as its initial contents. This is
+    # particularly useful for ROMs.
+    image_file = Param.String('',
+            "Image to load into memory as its initial contents")
diff --git a/src/mem/abstract_mem.cc b/src/mem/abstract_mem.cc
index b5412ba..aa80011 100644
--- a/src/mem/abstract_mem.cc
+++ b/src/mem/abstract_mem.cc
@@ -43,6 +43,8 @@
 #include <vector>

 #include "arch/locked_mem.hh"
+#include "base/loader/memory_image.hh"
+#include "base/loader/object_file.hh"
 #include "cpu/base.hh"
 #include "cpu/thread_context.hh"
 #include "debug/LLSC.hh"
@@ -67,6 +69,38 @@
 }

 void
+AbstractMemory::initState()
+{
+    ClockedObject::initState();
+
+    const auto &file = params()->image_file;
+    if (file == "")
+        return;
+
+    auto *object = createObjectFile(file, true);
+    fatal_if(!object, "%s: Could not load %s.", name(), file);
+
+    panic_if(!object->loadGlobalSymbols(debugSymbolTable),
+             "%s: Could not load symbols from %s.", name(), file);
+
+    MemoryImage image = object->buildImage();
+
+    AddrRange image_range(image.minAddr(), image.maxAddr());
+    if (!range.contains(image_range.start())) {
+        warn("%s: Moving image from %s to memory address range %s.",
+                name(), image_range.to_string(), range.to_string());
+        image = image.offset(range.start());
+        image_range = AddrRange(image.minAddr(), image.maxAddr());
+    }
+ panic_if(!image_range.isSubset(range), "%s: memory image %s doesn't fit.",
+             name(), file);
+
+ PortProxy proxy([this](PacketPtr pkt) { functionalAccess(pkt); }, size());
+
+    panic_if(!image.write(proxy), "%s: Unable to write image.");
+}
+
+void
 AbstractMemory::setBackingStore(uint8_t* pmem_addr)
 {
// If there was an existing backdoor, let everybody know it's going away.
diff --git a/src/mem/abstract_mem.hh b/src/mem/abstract_mem.hh
index b1d54fd..616fd0e 100644
--- a/src/mem/abstract_mem.hh
+++ b/src/mem/abstract_mem.hh
@@ -209,6 +209,8 @@
     AbstractMemory(const Params* p);
     virtual ~AbstractMemory() {}

+    void initState() override;
+
     /**
      * See if this is a null memory that should never store data and
      * always return zero.

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27267
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ibbcffffcb82e0d289f0b3942728c30b8f69d28ba
Gerrit-Change-Number: 27267
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Alexandru Duțu <alexandru.d...@amd.com>
Gerrit-Reviewer: Bradford Beckmann <brad.beckm...@amd.com>
Gerrit-Reviewer: GAURAV JAIN <gja...@wisc.edu>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Gem5 Cloud Project GCB service account <345032938...@cloudbuild.gserviceaccount.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: Matt Sinclair <mattdsincl...@gmail.com>
Gerrit-Reviewer: Matthew Poremba <matthew.pore...@amd.com>
Gerrit-Reviewer: Nikos Nikoleris <nikos.nikole...@arm.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Earl Ou <shunhsin...@google.com>
Gerrit-CC: Yu-hsin Wang <yuhsi...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to