From 50f85394b36fb7fd186d0137f11bf416f65d080f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 2 May 2019 22:54:08 -0700 Subject: [PATCH] x86: Add an object file loader for linux. Change-Id: I283dd1f52fd020ad3c226eb00fc9216ee034c67f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18630 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- src/arch/x86/linux/process.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/arch/x86/linux/process.cc b/src/arch/x86/linux/process.cc index f19dce358..95f4ee91d 100644 --- a/src/arch/x86/linux/process.cc +++ b/src/arch/x86/linux/process.cc @@ -44,6 +44,7 @@ #include "arch/x86/isa_traits.hh" #include "arch/x86/linux/linux.hh" #include "arch/x86/registers.hh" +#include "base/loader/object_file.hh" #include "base/trace.hh" #include "cpu/thread_context.hh" #include "kern/linux/linux.hh" @@ -54,6 +55,40 @@ using namespace std; using namespace X86ISA; +namespace +{ + +class X86LinuxObjectFileLoader : 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::X86_64 && arch != ObjectFile::I386) + return nullptr; + + if (opsys == ObjectFile::UnknownOpSys) { + warn("Unknown operating system; assuming Linux."); + opsys = ObjectFile::Linux; + } + + if (opsys != ObjectFile::Linux) + return nullptr; + + if (arch == ObjectFile::X86_64) + return new X86_64LinuxProcess(params, obj_file); + else + return new I386LinuxProcess(params, obj_file); + } +}; + +X86LinuxObjectFileLoader loader; + +} // anonymous namespace + /// Target uname() handler. static SyscallReturn unameFunc(SyscallDesc *desc, int callnum, Process *process, -- 2.30.2