power: Implement an SE workload for Linux.

Change-Id: Ie242698b7f9e6ffffd4abdcbb483ee81d64802d9
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34157
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Sandipan Das <sandipan@linux.ibm.com>
This commit is contained in:
Gabe Black
2020-10-20 17:37:05 -07:00
parent bfad4b77d0
commit 26ed502d4c
8 changed files with 228 additions and 93 deletions

View 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 PowerSEWorkload(SEWorkload):
type = 'PowerSEWorkload'
cxx_header = "arch/power/se_workload.hh"
cxx_class = 'PowerISA::SEWorkload'
abstract = True
class PowerEmuLinux(PowerSEWorkload):
type = 'PowerEmuLinux'
cxx_header = "arch/power/linux/se_workload.hh"
cxx_class = 'PowerISA::EmuLinux'
@classmethod
def _is_compatible_with(cls, obj):
return obj.get_arch() == 'power' and \
obj.get_op_sys() in ('linux', 'unknown')

View File

@@ -42,18 +42,20 @@ if env['TARGET_ISA'] == 'power':
Source('insts/static_inst.cc')
Source('interrupts.cc')
Source('linux/linux.cc')
Source('linux/process.cc')
Source('linux/se_workload.cc')
Source('mmu.cc')
Source('isa.cc')
Source('pagetable.cc')
Source('process.cc')
Source('remote_gdb.cc')
Source('se_workload.cc')
Source('tlb.cc')
Source('utility.cc')
SimObject('PowerInterrupts.py')
SimObject('PowerISA.py')
SimObject('PowerMMU.py')
SimObject('PowerSeWorkload.py')
SimObject('PowerTLB.py')
DebugFlag('Power')

View File

@@ -1,8 +1,5 @@
/*
* Copyright (c) 2003-2005 The Regents of The University of Michigan
* Copyright (c) 2007-2008 The Florida State University
* Copyright (c) 2009 The University of Edinburgh
* All rights reserved.
* Copyright 2020 Google Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -28,35 +25,29 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "arch/power/linux/process.hh"
#include "arch/power/linux/se_workload.hh"
#include "arch/power/isa_traits.hh"
#include "arch/power/linux/linux.hh"
#include <sys/syscall.h>
#include "arch/power/process.hh"
#include "base/loader/object_file.hh"
#include "base/trace.hh"
#include "cpu/thread_context.hh"
#include "kern/linux/linux.hh"
#include "sim/process.hh"
#include "sim/syscall_desc.hh"
#include "sim/syscall_emul.hh"
#include "sim/system.hh"
using namespace std;
using namespace PowerISA;
namespace
{
class PowerLinuxObjectFileLoader : public Process::Loader
class LinuxLoader : public Process::Loader
{
public:
Process *
load(const ProcessParams &params, ::Loader::ObjectFile *obj_file) override
load(const ProcessParams &params, ::Loader::ObjectFile *obj) override
{
if (obj_file->getArch() != ::Loader::Power)
if (obj->getArch() != ::Loader::Power)
return nullptr;
auto opsys = obj_file->getOpSys();
auto opsys = obj->getOpSys();
if (opsys == ::Loader::UnknownOpSys) {
warn("Unknown operating system; assuming Linux.");
@@ -66,14 +57,28 @@ class PowerLinuxObjectFileLoader : public Process::Loader
if (opsys != ::Loader::Linux)
return nullptr;
return new PowerLinuxProcess(params, obj_file);
return new PowerProcess(params, obj);
}
};
PowerLinuxObjectFileLoader loader;
LinuxLoader loader;
} // anonymous namespace
namespace PowerISA
{
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(0))->doSyscall(tc);
}
/// Target uname() handler.
static SyscallReturn
unameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<Linux::utsname> name)
@@ -89,7 +94,7 @@ unameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr<Linux::utsname> name)
return 0;
}
SyscallDescTable<PowerProcess::SyscallABI> PowerLinuxProcess::syscallDescs = {
SyscallDescTable<PowerISA::SEWorkload::SyscallABI> EmuLinux::syscallDescs = {
{ 0, "syscall" },
{ 1, "exit", exitFunc },
{ 2, "fork" },
@@ -439,20 +444,10 @@ SyscallDescTable<PowerProcess::SyscallABI> PowerLinuxProcess::syscallDescs = {
{ 346, "epoll_pwait" },
};
PowerLinuxProcess::PowerLinuxProcess(const ProcessParams &params,
::Loader::ObjectFile *objFile) :
PowerProcess(params, objFile)
{}
} // namespace PowerISA
void
PowerLinuxProcess::initState()
PowerISA::EmuLinux *
PowerEmuLinuxParams::create() const
{
PowerProcess::initState();
}
void
PowerLinuxProcess::syscall(ThreadContext *tc)
{
PowerProcess::syscall(tc);
syscallDescs.get(tc->readIntReg(0))->doSyscall(tc);
return new PowerISA::EmuLinux(*this);
}

View File

@@ -1,7 +1,5 @@
/*
* Copyright (c) 2007-2008 The Florida State University
* Copyright (c) 2009 The University of Edinburgh
* All rights reserved.
* 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,26 +25,36 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __POWER_LINUX_PROCESS_HH__
#define __POWER_LINUX_PROCESS_HH__
#include "arch/power/process.hh"
#ifndef __ARCH_POWER_LINUX_SE_WORKLOAD_HH__
#define __ARCH_POWER_LINUX_SE_WORKLOAD_HH__
#include "arch/power/linux/linux.hh"
#include "arch/power/se_workload.hh"
#include "params/PowerEmuLinux.hh"
#include "sim/syscall_desc.hh"
/// A process with emulated PPC/Linux syscalls.
class PowerLinuxProcess : public PowerProcess
namespace PowerISA
{
class EmuLinux : public SEWorkload
{
public:
PowerLinuxProcess(const ProcessParams &params,
::Loader::ObjectFile *objFile);
using Params = PowerEmuLinuxParams;
void initState() override;
void syscall(ThreadContext *tc) override;
protected:
const Params &_params;
/// Syscall descriptors, indexed by call number.
static SyscallDescTable<SyscallABI> syscallDescs;
static SyscallDescTable<SEWorkload::SyscallABI> syscallDescs;
public:
const Params &params() const { return _params; }
EmuLinux(const Params &p) : SEWorkload(p), _params(p) {}
void syscall(ThreadContext *tc) override;
};
#endif // __POWER_LINUX_PROCESS_HH__
} // namespace PowerISA
#endif // __ARCH_POWER_LINUX_SE_WORKLOAD_HH__

View File

@@ -277,7 +277,3 @@ PowerProcess::argsInit(int intSize, int pageSize)
//Align the "stack_min" to a page boundary.
memState->setStackMin(roundDown(stack_min, pageSize));
}
const std::vector<int> PowerProcess::SyscallABI::ArgumentRegs = {
3, 4, 5, 6, 7, 8
};

View File

@@ -30,12 +30,7 @@
#ifndef __POWER_PROCESS_HH__
#define __POWER_PROCESS_HH__
#include <string>
#include <vector>
#include "mem/page_table.hh"
#include "sim/process.hh"
#include "sim/syscall_abi.hh"
namespace Loader
{
@@ -45,43 +40,13 @@ class ObjectFile;
class PowerProcess : public Process
{
protected:
PowerProcess(const ProcessParams &params, ::Loader::ObjectFile *objFile);
void initState() override;
public:
PowerProcess(const ProcessParams &params, ::Loader::ObjectFile *objFile);
void argsInit(int intSize, int pageSize);
struct SyscallABI : public GenericSyscallABI64
{
static const std::vector<int> ArgumentRegs;
};
};
namespace GuestABI
{
template <>
struct Result<PowerProcess::SyscallABI, SyscallReturn>
{
static void
store(ThreadContext *tc, const SyscallReturn &ret)
{
if (ret.suppressed() || ret.needsRetry())
return;
PowerISA::Cr cr = tc->readIntReg(PowerISA::INTREG_CR);
if (ret.successful()) {
cr.cr0.so = 0;
} else {
cr.cr0.so = 1;
}
tc->setIntReg(PowerISA::INTREG_CR, cr);
tc->setIntReg(PowerISA::ReturnValueReg, ret.encodedValue());
}
};
} // namespace GuestABI
#endif // __POWER_PROCESS_HH__

View 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/power/se_workload.hh"
namespace PowerISA
{
const std::vector<int> SEWorkload::SyscallABI::ArgumentRegs = {
3, 4, 5, 6, 7, 8
};
} // namespace PowerISA

View File

@@ -0,0 +1,88 @@
/*
* 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_POWER_SE_WORKLOAD_HH__
#define __ARCH_POWER_SE_WORKLOAD_HH__
#include "arch/power/registers.hh"
#include "params/PowerSEWorkload.hh"
#include "sim/se_workload.hh"
#include "sim/syscall_abi.hh"
#include "sim/syscall_desc.hh"
namespace PowerISA
{
class SEWorkload : public ::SEWorkload
{
public:
using Params = PowerSEWorkloadParams;
protected:
const Params &_params;
public:
const Params &params() const { return _params; }
SEWorkload(const Params &p) : ::SEWorkload(p), _params(p) {}
::Loader::Arch getArch() const override { return ::Loader::Power; }
struct SyscallABI : public GenericSyscallABI64
{
static const std::vector<int> ArgumentRegs;
};
};
} // namespace PowerISA
namespace GuestABI
{
template <>
struct Result<PowerISA::SEWorkload::SyscallABI, SyscallReturn>
{
static void
store(ThreadContext *tc, const SyscallReturn &ret)
{
if (ret.suppressed() || ret.needsRetry())
return;
PowerISA::Cr cr = tc->readIntReg(PowerISA::INTREG_CR);
if (ret.successful()) {
cr.cr0.so = 0;
} else {
cr.cr0.so = 1;
}
tc->setIntReg(PowerISA::INTREG_CR, cr);
tc->setIntReg(PowerISA::ReturnValueReg, ret.encodedValue());
}
};
} // namespace GuestABI
#endif // __ARCH_POWER_SE_WORKLOAD_HH__