riscv: Add an object file loader for linux.
authorGabe Black <gabeblack@google.com>
Fri, 3 May 2019 05:53:41 +0000 (22:53 -0700)
committerGabe Black <gabeblack@google.com>
Mon, 20 May 2019 06:08:24 +0000 (06:08 +0000)
Change-Id: I3accca91cc4e02fa8e3a1169590cbe6696cf05e2
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18628
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alec Roelke <alec.roelke@gmail.com>
Maintainer: Alec Roelke <alec.roelke@gmail.com>

src/arch/riscv/linux/process.cc

index 72399201e6ba270ad2f5a5e85ab827cfd5fc063d..b2d0305230c87fc21bd2b433d2aa5ebe779f0edf 100644 (file)
@@ -38,6 +38,7 @@
 
 #include "arch/riscv/isa_traits.hh"
 #include "arch/riscv/linux/linux.hh"
+#include "base/loader/object_file.hh"
 #include "base/trace.hh"
 #include "cpu/thread_context.hh"
 #include "debug/SyscallVerbose.hh"
 using namespace std;
 using namespace RiscvISA;
 
+namespace
+{
+
+class RiscvLinuxObjectFileLoader : public ObjectFile::Loader
+{
+  public:
+    Process *
+    load(ProcessParams *params, ObjectFile *obj_file) override
+    {
+        auto arch = obj_file->getArch();
+        auto opsys = obj_file->getOpSys();
+
+        if (arch != ObjectFile::Riscv64 && arch != ObjectFile::Riscv32)
+            return nullptr;
+
+        if (opsys == ObjectFile::UnknownOpSys) {
+            warn("Unknown operating system; assuming Linux.");
+            opsys = ObjectFile::Linux;
+        }
+
+        if (opsys != ObjectFile::Linux)
+            return nullptr;
+
+        if (arch == ObjectFile::Riscv64)
+            return new RiscvLinuxProcess64(params, obj_file);
+        else
+            return new RiscvLinuxProcess32(params, obj_file);
+    }
+};
+
+RiscvLinuxObjectFileLoader loader;
+
+} // anonymous namespace
+
 /// Target uname() handler.
 static SyscallReturn
 unameFunc64(SyscallDesc *desc, int callnum, Process *process,