Gabe Black has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/18631 )

Change subject: sim: Make the Process create function use the object loader mechanism.
......................................................................

sim: Make the Process create function use the object loader mechanism.

This gets rid of the big mass of #if-s around headers and around the
code which creates an object file.

As a nice side bonus, this also means that in addition to supporting
multiple OS/arch combinations simultaneously, the object file loader
could support multiple ISAs simultaneously as well, since each could
load and set up its object file loaders indepedently and without the
base process classes knowledge/involvement.

Change-Id: I0a19ad06e30e9062a96d27f00b66756eb3a595ba
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18631
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Andreas Sandberg <andreas.sandb...@arm.com>
Maintainer: Andreas Sandberg <andreas.sandb...@arm.com>
---
M src/sim/process.cc
1 file changed, 3 insertions(+), 172 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/sim/process.cc b/src/sim/process.cc
index 9d6f3d1..352c179 100644
--- a/src/sim/process.cc
+++ b/src/sim/process.cc
@@ -72,34 +72,6 @@
 #include "sim/syscall_desc.hh"
 #include "sim/system.hh"

-#if THE_ISA == ALPHA_ISA
-#include "arch/alpha/linux/process.hh"
-
-#elif THE_ISA == SPARC_ISA
-#include "arch/sparc/linux/process.hh"
-#include "arch/sparc/solaris/process.hh"
-
-#elif THE_ISA == MIPS_ISA
-#include "arch/mips/linux/process.hh"
-
-#elif THE_ISA == ARM_ISA
-#include "arch/arm/freebsd/process.hh"
-#include "arch/arm/linux/process.hh"
-
-#elif THE_ISA == X86_ISA
-#include "arch/x86/linux/process.hh"
-
-#elif THE_ISA == POWER_ISA
-#include "arch/power/linux/process.hh"
-
-#elif THE_ISA == RISCV_ISA
-#include "arch/riscv/linux/process.hh"
-
-#else
-#error "THE_ISA not set"
-#endif
-
-
 using namespace std;
 using namespace TheISA;

@@ -563,151 +535,10 @@
     }

     ObjectFile *obj_file = createObjectFile(executable);
-    if (obj_file == nullptr) {
-        fatal("Can't load object file %s", executable);
-    }
+    fatal_if(!obj_file, "Can't load object file %s", executable);

-#if THE_ISA == ALPHA_ISA
-    if (obj_file->getArch() != ObjectFile::Alpha)
- fatal("Object file architecture does not match compiled ISA (Alpha).");
+    process = ObjectFile::tryLoaders(this, obj_file);
+    fatal_if(!process, "Unknown error creating process object.");

-    switch (obj_file->getOpSys()) {
-      case ObjectFile::UnknownOpSys:
-        warn("Unknown operating system; assuming Linux.");
-        // fall through
-      case ObjectFile::Linux:
-        process = new AlphaLinuxProcess(this, obj_file);
-        break;
-
-      default:
-        fatal("Unknown/unsupported operating system.");
-    }
-#elif THE_ISA == SPARC_ISA
-    if (obj_file->getArch() != ObjectFile::SPARC64 &&
-        obj_file->getArch() != ObjectFile::SPARC32)
- fatal("Object file architecture does not match compiled ISA (SPARC).");
-    switch (obj_file->getOpSys()) {
-      case ObjectFile::UnknownOpSys:
-        warn("Unknown operating system; assuming Linux.");
-        // fall through
-      case ObjectFile::Linux:
-        if (obj_file->getArch() == ObjectFile::SPARC64) {
-            process = new Sparc64LinuxProcess(this, obj_file);
-        } else {
-            process = new Sparc32LinuxProcess(this, obj_file);
-        }
-        break;
-
-      case ObjectFile::Solaris:
-        process = new SparcSolarisProcess(this, obj_file);
-        break;
-
-      default:
-        fatal("Unknown/unsupported operating system.");
-    }
-#elif THE_ISA == X86_ISA
-    if (obj_file->getArch() != ObjectFile::X86_64 &&
-        obj_file->getArch() != ObjectFile::I386)
- fatal("Object file architecture does not match compiled ISA (x86).");
-    switch (obj_file->getOpSys()) {
-      case ObjectFile::UnknownOpSys:
-        warn("Unknown operating system; assuming Linux.");
-        // fall through
-      case ObjectFile::Linux:
-        if (obj_file->getArch() == ObjectFile::X86_64) {
-            process = new X86_64LinuxProcess(this, obj_file);
-        } else {
-            process = new I386LinuxProcess(this, obj_file);
-        }
-        break;
-
-      default:
-        fatal("Unknown/unsupported operating system.");
-    }
-#elif THE_ISA == MIPS_ISA
-    if (obj_file->getArch() != ObjectFile::Mips)
- fatal("Object file architecture does not match compiled ISA (MIPS).");
-    switch (obj_file->getOpSys()) {
-      case ObjectFile::UnknownOpSys:
-        warn("Unknown operating system; assuming Linux.");
-        // fall through
-      case ObjectFile::Linux:
-        process = new MipsLinuxProcess(this, obj_file);
-        break;
-
-      default:
-        fatal("Unknown/unsupported operating system.");
-    }
-#elif THE_ISA == ARM_ISA
-    ObjectFile::Arch arch = obj_file->getArch();
-    if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
-        arch != ObjectFile::Arm64)
- fatal("Object file architecture does not match compiled ISA (ARM).");
-    switch (obj_file->getOpSys()) {
-      case ObjectFile::UnknownOpSys:
-        warn("Unknown operating system; assuming Linux.");
-        // fall through
-      case ObjectFile::Linux:
-        if (arch == ObjectFile::Arm64) {
-            process = new ArmLinuxProcess64(this, obj_file,
-                                            obj_file->getArch());
-        } else {
-            process = new ArmLinuxProcess32(this, obj_file,
-                                            obj_file->getArch());
-        }
-        break;
-      case ObjectFile::FreeBSD:
-        if (arch == ObjectFile::Arm64) {
-            process = new ArmFreebsdProcess64(this, obj_file,
-                                              obj_file->getArch());
-        } else {
-            process = new ArmFreebsdProcess32(this, obj_file,
-                                              obj_file->getArch());
-        }
-        break;
-      case ObjectFile::LinuxArmOABI:
- fatal("M5 does not support ARM OABI binaries. Please recompile with an"
-              " EABI compiler.");
-      default:
-        fatal("Unknown/unsupported operating system.");
-    }
-#elif THE_ISA == POWER_ISA
-    if (obj_file->getArch() != ObjectFile::Power)
- fatal("Object file architecture does not match compiled ISA (Power).");
-    switch (obj_file->getOpSys()) {
-      case ObjectFile::UnknownOpSys:
-        warn("Unknown operating system; assuming Linux.");
-        // fall through
-      case ObjectFile::Linux:
-        process = new PowerLinuxProcess(this, obj_file);
-        break;
-
-      default:
-        fatal("Unknown/unsupported operating system.");
-    }
-#elif THE_ISA == RISCV_ISA
-    ObjectFile::Arch arch = obj_file->getArch();
-    if (arch != ObjectFile::Riscv64 && arch != ObjectFile::Riscv32)
- fatal("Object file architecture does not match compiled ISA (RISCV).");
-    switch (obj_file->getOpSys()) {
-      case ObjectFile::UnknownOpSys:
-        warn("Unknown operating system; assuming Linux.");
-        // fall through
-      case ObjectFile::Linux:
-        if (arch == ObjectFile::Riscv64) {
-            process = new RiscvLinuxProcess64(this, obj_file);
-        } else {
-            process = new RiscvLinuxProcess32(this, obj_file);
-        }
-        break;
-      default:
-        fatal("Unknown/unsupported operating system.");
-    }
-#else
-#error "THE_ISA not set"
-#endif
-
-    if (process == nullptr)
-        fatal("Unknown error creating process object.");
     return process;
 }

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/18631
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I0a19ad06e30e9062a96d27f00b66756eb3a595ba
Gerrit-Change-Number: 18631
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Anthony Gutierrez <anthony.gutier...@amd.com>
Gerrit-Reviewer: Brandon Potter <brandon.pot...@amd.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to