summaryrefslogtreecommitdiff
path: root/src/sim
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-10-04 01:21:24 -0700
committerGabe Black <gabeblack@google.com>2019-10-16 01:36:33 +0000
commite35b491c464f8961f5f3fff56478f12716f5a424 (patch)
treef3748c86e0d5b844fd6e8babc41c8d8175f853c7 /src/sim
parent245422102c049cc744d695103ead1caa9d9870ca (diff)
downloadgem5-e35b491c464f8961f5f3fff56478f12716f5a424.tar.xz
arch,base,sim: Move Process loader hooks into the Process class.
This code was originally in the ObjectFile class, but not all object files will become Processes. All Processes will ultimately come from ObjectFiles though, so it makes more sense to put that class there. Change-Id: Ie73e4cdecbb51ce53d24cf68911a6cfc0685d771 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/21468 Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Gabe Black <gabeblack@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/process.cc33
-rw-r--r--src/sim/process.hh32
2 files changed, 64 insertions, 1 deletions
diff --git a/src/sim/process.cc b/src/sim/process.cc
index a01cfea91..db013aee0 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -75,6 +75,37 @@
using namespace std;
using namespace TheISA;
+namespace
+{
+
+typedef std::vector<Process::Loader *> LoaderList;
+
+LoaderList &
+process_loaders()
+{
+ static LoaderList loaders;
+ return loaders;
+}
+
+} // anonymous namespace
+
+Process::Loader::Loader()
+{
+ process_loaders().emplace_back(this);
+}
+
+Process *
+Process::tryLoaders(ProcessParams *params, ObjectFile *obj_file)
+{
+ for (auto &loader: process_loaders()) {
+ Process *p = loader->load(params, obj_file);
+ if (p)
+ return p;
+ }
+
+ return nullptr;
+}
+
static std::string
normalize(std::string& directory)
{
@@ -554,7 +585,7 @@ ProcessParams::create()
ObjectFile *obj_file = createObjectFile(executable);
fatal_if(!obj_file, "Cannot load object file %s.", executable);
- Process *process = ObjectFile::tryLoaders(this, obj_file);
+ Process *process = Process::tryLoaders(this, obj_file);
fatal_if(!process, "Unknown error creating process object.");
return process;
diff --git a/src/sim/process.hh b/src/sim/process.hh
index 8e353071c..a28d58e9a 100644
--- a/src/sim/process.hh
+++ b/src/sim/process.hh
@@ -183,6 +183,38 @@ class Process : public SimObject
SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
+ /**
+ * Each instance of a Loader subclass will have a chance to try to load
+ * an object file when tryLoaders is called. If they can't because they
+ * aren't compatible with it (wrong arch, wrong OS, etc), then they
+ * silently fail by returning nullptr so other loaders can try.
+ */
+ class Loader
+ {
+ public:
+ Loader();
+
+ /* Loader instances are singletons. */
+ Loader(const Loader &) = delete;
+ void operator=(const Loader &) = delete;
+
+ virtual ~Loader() {}
+
+ /**
+ * Each subclass needs to implement this method. If the loader is
+ * compatible with the passed in object file, it should return the
+ * created Process object corresponding to it. If not, it should fail
+ * silently and return nullptr. If there's a non-compatibliity related
+ * error like file IO errors, etc., those should fail non-silently
+ * with a panic or fail as normal.
+ */
+ virtual Process *load(ProcessParams *params, ObjectFile *obj_file) = 0;
+ };
+
+ // Try all the Loader instance's "load" methods one by one until one is
+ // successful. If none are, complain and fail.
+ static Process *tryLoaders(ProcessParams *params, ObjectFile *obj_file);
+
ObjectFile *objFile;
MemoryImage image;
MemoryImage interpImage;