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 <gabe.black@gmail.com> Maintainer: Gabe Black <gabe.black@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
44
src/arch/mips/MipsSeWorkload.py
Normal file
44
src/arch/mips/MipsSeWorkload.py
Normal file
@@ -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')
|
||||
@@ -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')
|
||||
|
||||
@@ -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 <sys/syscall.h>
|
||||
|
||||
#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<Linux::utsname> 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<MipsProcess::SyscallABI> MipsLinuxProcess::syscallDescs = {
|
||||
SyscallDescTable<MipsISA::SEWorkload::SyscallABI> EmuLinux::syscallDescs = {
|
||||
{ 4000, "syscall" },
|
||||
{ 4001, "exit", exitFunc },
|
||||
{ 4002, "fork" },
|
||||
@@ -470,14 +476,10 @@ SyscallDescTable<MipsProcess::SyscallABI> 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);
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
class EmuLinux : public SEWorkload
|
||||
{
|
||||
public:
|
||||
/// Constructor.
|
||||
MipsLinuxProcess(const ProcessParams ¶ms,
|
||||
::Loader::ObjectFile *objFile);
|
||||
using Params = MipsEmuLinuxParams;
|
||||
|
||||
/// The target system's hostname.
|
||||
static const char *hostname;
|
||||
|
||||
/// ID of the thread group leader for the process
|
||||
uint64_t __tgid;
|
||||
|
||||
void syscall(ThreadContext *tc) override;
|
||||
protected:
|
||||
const Params &_params;
|
||||
|
||||
/// Syscall descriptors, indexed by call number.
|
||||
static SyscallDescTable<SyscallABI> 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__
|
||||
@@ -202,7 +202,3 @@ MipsProcess::argsInit(int pageSize)
|
||||
|
||||
tc->pcState(getStartPC());
|
||||
}
|
||||
|
||||
const std::vector<int> MipsProcess::SyscallABI::ArgumentRegs = {
|
||||
4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
@@ -29,12 +29,7 @@
|
||||
#ifndef __MIPS_PROCESS_HH__
|
||||
#define __MIPS_PROCESS_HH__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<class IntType>
|
||||
void argsInit(int pageSize);
|
||||
|
||||
public:
|
||||
struct SyscallABI : public GenericSyscallABI64
|
||||
{
|
||||
static const std::vector<int> ArgumentRegs;
|
||||
};
|
||||
};
|
||||
|
||||
namespace GuestABI
|
||||
{
|
||||
|
||||
template <>
|
||||
struct Result<MipsProcess::SyscallABI, SyscallReturn>
|
||||
{
|
||||
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__
|
||||
|
||||
37
src/arch/mips/se_workload.cc
Normal file
37
src/arch/mips/se_workload.cc
Normal file
@@ -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<int> SEWorkload::SyscallABI::ArgumentRegs = {
|
||||
4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
} // namespace MipsISA
|
||||
91
src/arch/mips/se_workload.hh
Normal file
91
src/arch/mips/se_workload.hh
Normal file
@@ -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<int> ArgumentRegs;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace MipsISA
|
||||
|
||||
namespace GuestABI
|
||||
{
|
||||
|
||||
template <>
|
||||
struct Result<MipsISA::SEWorkload::SyscallABI, SyscallReturn>
|
||||
{
|
||||
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__
|
||||
Reference in New Issue
Block a user