From 5a2a72bff4f047bcaba07ea6bd9aff6afe028735 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 20 Oct 2020 17:37:08 -0700 Subject: [PATCH] mips: Implement an SE workload for Linux. Change-Id: I78f6048cfe06be1b08d54dc7d24cb3518e97be0f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34158 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- src/arch/mips/MipsSeWorkload.py | 44 +++++++++ src/arch/mips/SConscript | 4 +- .../mips/linux/{process.cc => se_workload.cc} | 66 +++++++------- .../mips/linux/{process.hh => se_workload.hh} | 42 +++++---- src/arch/mips/process.cc | 4 - src/arch/mips/process.hh | 42 +-------- src/arch/mips/se_workload.cc | 37 ++++++++ src/arch/mips/se_workload.hh | 91 +++++++++++++++++++ 8 files changed, 234 insertions(+), 96 deletions(-) create mode 100644 src/arch/mips/MipsSeWorkload.py rename src/arch/mips/linux/{process.cc => se_workload.cc} (91%) rename src/arch/mips/linux/{process.hh => se_workload.hh} (73%) create mode 100644 src/arch/mips/se_workload.cc create mode 100644 src/arch/mips/se_workload.hh diff --git a/src/arch/mips/MipsSeWorkload.py b/src/arch/mips/MipsSeWorkload.py new file mode 100644 index 000000000..453a2c4d4 --- /dev/null +++ b/src/arch/mips/MipsSeWorkload.py @@ -0,0 +1,44 @@ +# Copyright 2020 Google Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from m5.params import * + +from m5.objects.Workload import SEWorkload + +class MipsSEWorkload(SEWorkload): + type = 'MipsSEWorkload' + cxx_header = "arch/mips/se_workload.hh" + cxx_class = 'MipsISA::SEWorkload' + abstract = True + +class MipsEmuLinux(MipsSEWorkload): + type = 'MipsEmuLinux' + cxx_header = "arch/mips/linux/se_workload.hh" + cxx_class = 'MipsISA::EmuLinux' + + @classmethod + def _is_compatible_with(cls, obj): + return obj.get_arch() == 'mips' and \ + obj.get_op_sys() in ('linux', 'unknown') diff --git a/src/arch/mips/SConscript b/src/arch/mips/SConscript index 9b5f6e40b..62cf15d05 100644 --- a/src/arch/mips/SConscript +++ b/src/arch/mips/SConscript @@ -37,17 +37,19 @@ if env['TARGET_ISA'] == 'mips': Source('interrupts.cc') Source('isa.cc') Source('linux/linux.cc') - Source('linux/process.cc') + Source('linux/se_workload.cc') Source('mmu.cc') Source('pagetable.cc') Source('process.cc') Source('remote_gdb.cc') + Source('se_workload.cc') Source('tlb.cc') Source('utility.cc') SimObject('MipsInterrupts.py') SimObject('MipsISA.py') SimObject('MipsMMU.py') + SimObject('MipsSeWorkload.py') SimObject('MipsTLB.py') DebugFlag('MipsPRA') diff --git a/src/arch/mips/linux/process.cc b/src/arch/mips/linux/se_workload.cc similarity index 91% rename from src/arch/mips/linux/process.cc rename to src/arch/mips/linux/se_workload.cc index ad423173c..5caed39c8 100644 --- a/src/arch/mips/linux/process.cc +++ b/src/arch/mips/linux/se_workload.cc @@ -1,7 +1,7 @@ /* - * Copyright (c) 2005 The Regents of The University of Michigan - * Copyright (c) 2007 MIPS Technologies, Inc. - * All rights reserved. + * Copyright 2005 The Regents of The University of Michigan + * Copyright 2007 MIPS Technologies, Inc. + * Copyright 2020 Google Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -27,37 +27,29 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "arch/mips/linux/process.hh" +#include "arch/mips/linux/se_workload.hh" -#include "arch/mips/isa_traits.hh" -#include "arch/mips/linux/linux.hh" +#include + +#include "arch/mips/process.hh" #include "base/loader/object_file.hh" #include "base/trace.hh" #include "cpu/thread_context.hh" -#include "debug/SyscallVerbose.hh" -#include "kern/linux/linux.hh" -#include "sim/eventq.hh" -#include "sim/process.hh" -#include "sim/syscall_desc.hh" #include "sim/syscall_emul.hh" -#include "sim/system.hh" - -using namespace std; -using namespace MipsISA; namespace { -class MipsLinuxObjectFileLoader : public Process::Loader +class LinuxLoader : public Process::Loader { public: Process * - load(const ProcessParams ¶ms, ::Loader::ObjectFile *obj_file) override + load(const ProcessParams ¶ms, ::Loader::ObjectFile *obj) override { - if (obj_file->getArch() != ::Loader::Mips) + if (obj->getArch() != ::Loader::Mips) return nullptr; - auto opsys = obj_file->getOpSys(); + auto opsys = obj->getOpSys(); if (opsys == ::Loader::UnknownOpSys) { warn("Unknown operating system; assuming Linux."); @@ -67,14 +59,28 @@ class MipsLinuxObjectFileLoader : public Process::Loader if (opsys != ::Loader::Linux) return nullptr; - return new MipsLinuxProcess(params, obj_file); + return new MipsProcess(params, obj); } }; -MipsLinuxObjectFileLoader loader; +LinuxLoader loader; } // anonymous namespace +namespace MipsISA +{ + +void +EmuLinux::syscall(ThreadContext *tc) +{ + Process *process = tc->getProcessPtr(); + // Call the syscall function in the base Process class to update stats. + // This will move into the base SEWorkload function at some point. + process->Process::syscall(tc); + + syscallDescs.get(tc->readIntReg(2))->doSyscall(tc); +} + /// Target uname() handler. static SyscallReturn unameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr name) @@ -107,7 +113,7 @@ sys_getsysinfoFunc(SyscallDesc *desc, ThreadContext *tc, unsigned op, return 0; } default: - cerr << "sys_getsysinfo: unknown op " << op << endl; + std::cerr << "sys_getsysinfo: unknown op " << op << std::endl; abort(); break; } @@ -132,7 +138,7 @@ sys_setsysinfoFunc(SyscallDesc *desc, ThreadContext *tc, unsigned op, return 0; } default: - cerr << "sys_setsysinfo: unknown op " << op << endl; + std::cerr << "sys_setsysinfo: unknown op " << op << std::endl; abort(); break; } @@ -147,7 +153,7 @@ setThreadAreaFunc(SyscallDesc *desc, ThreadContext *tc, Addr addr) return 0; } -SyscallDescTable MipsLinuxProcess::syscallDescs = { +SyscallDescTable EmuLinux::syscallDescs = { { 4000, "syscall" }, { 4001, "exit", exitFunc }, { 4002, "fork" }, @@ -470,14 +476,10 @@ SyscallDescTable MipsLinuxProcess::syscallDescs = { { 4319, "eventfd" } }; -MipsLinuxProcess::MipsLinuxProcess(const ProcessParams ¶ms, - ::Loader::ObjectFile *objFile) : - MipsProcess(params, objFile) -{} +} // namespace MipsISA -void -MipsLinuxProcess::syscall(ThreadContext *tc) +MipsISA::EmuLinux * +MipsEmuLinuxParams::create() const { - MipsProcess::syscall(tc); - syscallDescs.get(tc->readIntReg(2))->doSyscall(tc); + return new MipsISA::EmuLinux(*this); } diff --git a/src/arch/mips/linux/process.hh b/src/arch/mips/linux/se_workload.hh similarity index 73% rename from src/arch/mips/linux/process.hh rename to src/arch/mips/linux/se_workload.hh index 04cbd169e..7e1353e66 100644 --- a/src/arch/mips/linux/process.hh +++ b/src/arch/mips/linux/se_workload.hh @@ -1,6 +1,6 @@ /* - * Copyright (c) 2004 The Regents of The University of Michigan - * All rights reserved. + * Copyright 2004 The Regents of The University of Michigan + * Copyright 2020 Google Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -26,32 +26,36 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __MIPS_LINUX_PROCESS_HH__ -#define __MIPS_LINUX_PROCESS_HH__ +#ifndef __ARCH_MIPS_LINUX_SE_WORKLOAD_HH__ +#define __ARCH_MIPS_LINUX_SE_WORKLOAD_HH__ #include "arch/mips/linux/linux.hh" -#include "arch/mips/process.hh" -#include "sim/eventq.hh" +#include "arch/mips/se_workload.hh" +#include "params/MipsEmuLinux.hh" #include "sim/syscall_desc.hh" -/// A process with emulated Mips/Linux syscalls. -class MipsLinuxProcess : public MipsProcess +namespace MipsISA { - public: - /// Constructor. - MipsLinuxProcess(const ProcessParams ¶ms, - ::Loader::ObjectFile *objFile); - - /// The target system's hostname. - static const char *hostname; - /// ID of the thread group leader for the process - uint64_t __tgid; +class EmuLinux : public SEWorkload +{ + public: + using Params = MipsEmuLinuxParams; - void syscall(ThreadContext *tc) override; + protected: + const Params &_params; /// Syscall descriptors, indexed by call number. static SyscallDescTable syscallDescs; + + public: + const Params ¶ms() const { return _params; } + + EmuLinux(const Params &p) : SEWorkload(p), _params(p) {} + + void syscall(ThreadContext *tc) override; }; -#endif // __MIPS_LINUX_PROCESS_HH__ +} // namespace MipsISA + +#endif // __ARCH_MIPS_LINUX_SE_WORKLOAD_HH__ diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index f0f9a7bc9..44f4f3237 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -202,7 +202,3 @@ MipsProcess::argsInit(int pageSize) tc->pcState(getStartPC()); } - -const std::vector MipsProcess::SyscallABI::ArgumentRegs = { - 4, 5, 6, 7, 8, 9 -}; diff --git a/src/arch/mips/process.hh b/src/arch/mips/process.hh index 578824c19..c356d7e88 100644 --- a/src/arch/mips/process.hh +++ b/src/arch/mips/process.hh @@ -29,12 +29,7 @@ #ifndef __MIPS_PROCESS_HH__ #define __MIPS_PROCESS_HH__ -#include -#include - -#include "mem/page_table.hh" #include "sim/process.hh" -#include "sim/syscall_abi.hh" namespace Loader { @@ -43,47 +38,14 @@ class ObjectFile; class MipsProcess : public Process { - protected: + public: MipsProcess(const ProcessParams ¶ms, ::Loader::ObjectFile *objFile); + protected: void initState(); template void argsInit(int pageSize); - - public: - struct SyscallABI : public GenericSyscallABI64 - { - static const std::vector ArgumentRegs; - }; }; -namespace GuestABI -{ - -template <> -struct Result -{ - static void - store(ThreadContext *tc, const SyscallReturn &ret) - { - if (ret.suppressed() || ret.needsRetry()) - return; - - if (ret.successful()) { - // no error - tc->setIntReg(MipsISA::SyscallSuccessReg, 0); - tc->setIntReg(MipsISA::ReturnValueReg, ret.returnValue()); - } else { - // got an error, return details - tc->setIntReg(MipsISA::SyscallSuccessReg, (uint32_t)(-1)); - tc->setIntReg(MipsISA::ReturnValueReg, ret.errnoValue()); - } - if (ret.count() > 1) - tc->setIntReg(MipsISA::SyscallPseudoReturnReg, ret.value2()); - } -}; - -} // namespace GuestABI - #endif // __MIPS_PROCESS_HH__ diff --git a/src/arch/mips/se_workload.cc b/src/arch/mips/se_workload.cc new file mode 100644 index 000000000..580eb40e7 --- /dev/null +++ b/src/arch/mips/se_workload.cc @@ -0,0 +1,37 @@ +/* + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "arch/mips/se_workload.hh" + +namespace MipsISA +{ + +const std::vector SEWorkload::SyscallABI::ArgumentRegs = { + 4, 5, 6, 7, 8, 9 +}; + +} // namespace MipsISA diff --git a/src/arch/mips/se_workload.hh b/src/arch/mips/se_workload.hh new file mode 100644 index 000000000..53c1cbef1 --- /dev/null +++ b/src/arch/mips/se_workload.hh @@ -0,0 +1,91 @@ +/* + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __ARCH_MIPS_SE_WORKLOAD_HH__ +#define __ARCH_MIPS_SE_WORKLOAD_HH__ + +#include "arch/mips/registers.hh" +#include "params/MipsSEWorkload.hh" +#include "sim/se_workload.hh" +#include "sim/syscall_abi.hh" +#include "sim/syscall_desc.hh" + +namespace MipsISA +{ + +class SEWorkload : public ::SEWorkload +{ + public: + using Params = MipsSEWorkloadParams; + + protected: + const Params &_params; + + public: + const Params ¶ms() const { return _params; } + + SEWorkload(const Params &p) : ::SEWorkload(p), _params(p) {} + + ::Loader::Arch getArch() const override { return ::Loader::Mips; } + + struct SyscallABI : public GenericSyscallABI64 + { + static const std::vector ArgumentRegs; + }; +}; + +} // namespace MipsISA + +namespace GuestABI +{ + +template <> +struct Result +{ + static void + store(ThreadContext *tc, const SyscallReturn &ret) + { + if (ret.suppressed() || ret.needsRetry()) + return; + + if (ret.successful()) { + // no error + tc->setIntReg(MipsISA::SyscallSuccessReg, 0); + tc->setIntReg(MipsISA::ReturnValueReg, ret.returnValue()); + } else { + // got an error, return details + tc->setIntReg(MipsISA::SyscallSuccessReg, (uint32_t)(-1)); + tc->setIntReg(MipsISA::ReturnValueReg, ret.errnoValue()); + } + if (ret.count() > 1) + tc->setIntReg(MipsISA::SyscallPseudoReturnReg, ret.value2()); + } +}; + +} // namespace GuestABI + +#endif // __ARCH_MIPS_SE_WORKLOAD_HH__ -- 2.30.2