arm: Add an object file loader for linux and freebsd.
authorGabe Black <gabeblack@google.com>
Fri, 3 May 2019 05:52:46 +0000 (22:52 -0700)
committerGabe Black <gabeblack@google.com>
Sat, 18 May 2019 18:28:21 +0000 (18:28 +0000)
Change-Id: Ie5fd187a4897aa608ffc12278b23d3ee8c0f323c
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18585
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

src/arch/arm/freebsd/process.cc
src/arch/arm/linux/process.cc

index e6aa74068b590e2426f83a04ef432d68e709849a..ba79eb18b74e48d4368473fdcd12f5a93ad14e9a 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "arch/arm/freebsd/freebsd.hh"
 #include "arch/arm/isa_traits.hh"
+#include "base/loader/object_file.hh"
 #include "base/trace.hh"
 #include "cpu/thread_context.hh"
 #include "kern/freebsd/freebsd.hh"
 using namespace std;
 using namespace ArmISA;
 
+namespace
+{
+
+class ArmFreebsdObjectFileLoader : 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::Arm && arch != ObjectFile::Thumb &&
+                arch != ObjectFile::Arm64) {
+            return nullptr;
+        }
+
+        if (opsys != ObjectFile::FreeBSD)
+            return nullptr;
+
+        if (arch == ObjectFile::Arm64)
+            return new ArmFreebsdProcess64(params, obj_file, arch);
+        else
+            return new ArmFreebsdProcess32(params, obj_file, arch);
+    }
+};
+
+ArmFreebsdObjectFileLoader loader;
+
+} // anonymous namespace
+
 static SyscallReturn
 issetugidFunc(SyscallDesc *desc, int callnum, Process *process,
               ThreadContext *tc)
index 99f4b2cd33764ee7c8dfeb4b692f074e3c820ec8..cd37c770af47d8a07c8d4f0ece10cc4dc67f574c 100644 (file)
@@ -50,6 +50,7 @@
 
 #include "arch/arm/isa_traits.hh"
 #include "arch/arm/linux/linux.hh"
+#include "base/loader/object_file.hh"
 #include "base/trace.hh"
 #include "cpu/thread_context.hh"
 #include "kern/linux/linux.hh"
 using namespace std;
 using namespace ArmISA;
 
+namespace
+{
+
+class ArmLinuxObjectFileLoader : 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::Arm && arch != ObjectFile::Thumb &&
+                arch != ObjectFile::Arm64) {
+            return nullptr;
+        }
+
+        if (opsys == ObjectFile::UnknownOpSys) {
+            warn("Unknown operating system; assuming Linux.");
+            opsys = ObjectFile::Linux;
+        }
+
+        if (opsys == ObjectFile::LinuxArmOABI) {
+            fatal("gem5 does not support ARM OABI binaries. Please recompile "
+                    "with an EABI compiler.");
+        }
+
+        if (opsys != ObjectFile::Linux)
+            return nullptr;
+
+        if (arch == ObjectFile::Arm64)
+            return new ArmLinuxProcess64(params, obj_file, arch);
+        else
+            return new ArmLinuxProcess32(params, obj_file, arch);
+    }
+};
+
+ArmLinuxObjectFileLoader loader;
+
+} // anonymous namespace
+
 /// Target uname() handler.
 static SyscallReturn
 unameFunc32(SyscallDesc *desc, int callnum, Process *process,