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+kokoro@google.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
Gabe Black
2019-05-02 22:58:08 -07:00
parent 50f85394b3
commit 526a2fb619

View File

@@ -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 @@ ProcessParams::create()
}
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;
}