diff options
author | Gabe Black <gabeblack@google.com> | 2019-05-02 22:51:09 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2019-05-18 10:20:39 +0000 |
commit | c1b748d691fe407c7cd43330658fba83e3435247 (patch) | |
tree | 1b14ed823f371e31aae73c92099752e4b7f4d159 /src/base/loader/object_file.hh | |
parent | 972c38b1cc5f6f6c649a0e9923695447bc5d6255 (diff) | |
download | gem5-c1b748d691fe407c7cd43330658fba83e3435247.tar.xz |
base: Add a type for keeping track of object file loaders.
This avoids having a big pile of #if-s in sim/process.cc and allows
dynamically adding new types of object file loaders which might
recognize new arch/OS combinations.
Change-Id: Ie3b9c1aa2974d30a61afc4fcc529ffd6a74d43e0
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18583
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/base/loader/object_file.hh')
-rw-r--r-- | src/base/loader/object_file.hh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/base/loader/object_file.hh b/src/base/loader/object_file.hh index 09c453b8d..5da7e3cc4 100644 --- a/src/base/loader/object_file.hh +++ b/src/base/loader/object_file.hh @@ -39,6 +39,8 @@ #include "base/types.hh" class PortProxy; +class Process; +class ProcessParams; class SymbolTable; class ObjectFile @@ -150,6 +152,38 @@ class ObjectFile * @param a address to load the binary/text section at */ void setTextBase(Addr a) { text.baseAddr = a; } + + /** + * 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 *createObjectFile(const std::string &fname, bool raw = false); |