gem5  v21.1.0.2
se_workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2007 The Hewlett-Packard Development Company
3  *
4  * The license below extends only to copyright in the software and shall
5  * not be construed as granting a license to any other intellectual
6  * property including but not limited to intellectual property relating
7  * to a hardware implementation of the functionality of the software
8  * licensed hereunder. You may use the software subject to the license
9  * terms below provided that you ensure that this notice is replicated
10  * unmodified and in its entirety in all distributions of the software,
11  * modified or unmodified, in source code or in binary form.
12  *
13  * Copyright 2020 Google Inc.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
40 
41 #include <sys/syscall.h>
42 
43 #include "arch/x86/linux/linux.hh"
44 #include "arch/x86/page_size.hh"
45 #include "arch/x86/process.hh"
46 #include "arch/x86/regs/int.hh"
47 #include "arch/x86/se_workload.hh"
48 #include "base/trace.hh"
49 #include "cpu/thread_context.hh"
50 #include "kern/linux/linux.hh"
51 #include "sim/process.hh"
52 #include "sim/syscall_desc.hh"
53 #include "sim/syscall_emul.hh"
54 
55 namespace gem5
56 {
57 
58 namespace
59 {
60 
61 class LinuxLoader : public Process::Loader
62 {
63  public:
64  Process *
65  load(const ProcessParams &params, loader::ObjectFile *obj_file)
66  {
67  auto arch = obj_file->getArch();
68  auto opsys = obj_file->getOpSys();
69 
70  if (arch != loader::X86_64 && arch != loader::I386)
71  return nullptr;
72 
73  if (opsys == loader::UnknownOpSys) {
74  warn("Unknown operating system; assuming Linux.");
75  opsys = loader::Linux;
76  }
77 
78  if (opsys != loader::Linux)
79  return nullptr;
80 
81  if (arch == loader::X86_64)
82  return new X86ISA::X86_64Process(params, obj_file);
83  else
84  return new X86ISA::I386Process(params, obj_file);
85  }
86 };
87 
88 LinuxLoader linuxLoader;
89 
90 } // anonymous namespace
91 
92 namespace X86ISA
93 {
94 
96 {}
97 
99  INTREG_RDI, INTREG_RSI, INTREG_RDX, INTREG_R10W, INTREG_R8W, INTREG_R9W
100 };
101 
103  INTREG_EBX, INTREG_ECX, INTREG_EDX, INTREG_ESI, INTREG_EDI, INTREG_EBP
104 };
105 
106 void
108 {
109  Process *process = tc->getProcessPtr();
110  // Call the syscall function in the base Process class to update stats.
111  // This will move into the base SEWorkload function at some point.
112  process->Process::syscall(tc);
113 
114  RegVal rax = tc->readIntReg(INTREG_RAX);
115  if (dynamic_cast<X86_64Process *>(process)) {
116  syscallDescs64.get(rax)->doSyscall(tc);
117  } else if (auto *proc32 = dynamic_cast<I386Process *>(process)) {
118  PCState pc = tc->pcState();
119  Addr eip = pc.pc();
120  const auto &vsyscall = proc32->getVSyscallPage();
121  if (eip >= vsyscall.base && eip < vsyscall.base + vsyscall.size) {
122  pc.npc(vsyscall.base + vsyscall.vsysexitOffset);
123  tc->pcState(pc);
124  }
125  syscallDescs32.get(rax)->doSyscall(tc);
126  } else {
127  panic("Unrecognized process type.");
128  }
129 }
130 
131 void
133 {
134  Process *process = tc->getProcessPtr();
135  auto pcState = tc->pcState();
136 
137  if (process->kvmInSE) {
138  Addr pc_page = mbits(pcState.pc(), 63, 12);
139  if (pc_page == syscallCodeVirtAddr) {
140  syscall(tc);
141  return;
142  } else if (pc_page == PFHandlerVirtAddr) {
143  pageFault(tc);
144  return;
145  }
146  }
147  warn("Unexpected workload event at pc %#x.", pcState.pc());
148 }
149 
150 void
152 {
153  Process *p = tc->getProcessPtr();
154  if (!p->fixupFault(tc->readMiscReg(MISCREG_CR2))) {
155  PortProxy &proxy = tc->getVirtProxy();
156  // at this point we should have 6 values on the interrupt stack
157  int size = 6;
158  uint64_t is[size];
159  // reading the interrupt handler stack
160  proxy.readBlob(ISTVirtAddr + PageBytes - size * sizeof(uint64_t),
161  &is, sizeof(is));
162  panic("Page fault at addr %#x\n\tInterrupt handler stack:\n"
163  "\tss: %#x\n"
164  "\trsp: %#x\n"
165  "\trflags: %#x\n"
166  "\tcs: %#x\n"
167  "\trip: %#x\n"
168  "\terr_code: %#x\n",
170  is[5], is[4], is[3], is[2], is[1], is[0]);
171  }
172 }
173 
174 } // namespace X86ISA
175 } // namespace gem5
gem5::X86ISA::pc
Bitfield< 19 > pc
Definition: misc.hh:811
gem5::ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
warn
#define warn(...)
Definition: logging.hh:245
linux.hh
gem5::RegVal
uint64_t RegVal
Definition: types.hh:173
se_workload.hh
gem5::X86ISA::PFHandlerVirtAddr
const Addr PFHandlerVirtAddr
Definition: se_workload.hh:46
gem5::loader::X86_64
@ X86_64
Definition: object_file.hh:56
gem5::X86ISA::EmuLinux::syscallDescs64
static SyscallDescTable< SyscallABI64 > syscallDescs64
Definition: se_workload.hh:90
std::vector< IntRegIndex >
gem5::X86ISA::EmuLinux::event
void event(ThreadContext *tc) override
Definition: se_workload.cc:132
gem5::mbits
constexpr T mbits(T val, unsigned first, unsigned last)
Mask off the given bits in place like bits() but without shifting.
Definition: bitfield.hh:103
gem5::MipsISA::is
Bitfield< 24, 22 > is
Definition: pra_constants.hh:235
gem5::X86ISA::I386Process
Definition: process.hh:137
gem5::loader::UnknownOpSys
@ UnknownOpSys
Definition: object_file.hh:71
gem5::X86ISA::MISCREG_CR2
@ MISCREG_CR2
Definition: misc.hh:113
gem5::X86ISA::EmuLinux::SyscallABI32::ArgumentRegs
static const std::vector< IntRegIndex > ArgumentRegs
Definition: se_workload.hh:86
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::ThreadContext::getVirtProxy
virtual PortProxy & getVirtProxy()=0
int.hh
process.hh
gem5::PortProxy
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:86
page_size.hh
gem5::PortProxy::readBlob
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:182
gem5::ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
gem5::ArmISA::SEWorkload
Definition: se_workload.hh:42
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
se_workload.hh
gem5::X86ISA::EmuLinux::EmuLinux
EmuLinux(const Params &p)
Definition: se_workload.cc:95
gem5::ArmISA::SEWorkload::Params
ArmSEWorkloadParams Params
Definition: se_workload.hh:45
gem5::Process
Definition: process.hh:67
gem5::ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
gem5::X86ISA::EmuLinux::syscall
void syscall(ThreadContext *tc) override
Definition: se_workload.cc:107
syscall_emul.hh
process.hh
gem5::X86ISA::EmuLinux::pageFault
void pageFault(ThreadContext *tc)
Definition: se_workload.cc:151
gem5::X86ISA::ISTVirtAddr
const Addr ISTVirtAddr
Definition: se_workload.hh:45
gem5::X86ISA::EmuLinux::syscallDescs32
static SyscallDescTable< SyscallABI32 > syscallDescs32
Definition: se_workload.hh:91
linux.hh
gem5::X86ISA::PCState
Definition: pcstate.hh:50
gem5::loader::I386
@ I386
Definition: object_file.hh:57
gem5::X86ISA::p
Bitfield< 0 > p
Definition: pagetable.hh:151
trace.hh
gem5::X86ISA::X86_64Process
Definition: process.hh:99
gem5::X86ISA::EmuLinux::SyscallABI64::ArgumentRegs
static const std::vector< IntRegIndex > ArgumentRegs
Definition: se_workload.hh:80
gem5::X86ISA::PageBytes
const Addr PageBytes
Definition: page_size.hh:49
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::Process::kvmInSE
bool kvmInSE
Definition: process.hh:167
gem5::X86ISA::syscallCodeVirtAddr
const Addr syscallCodeVirtAddr
Definition: se_workload.hh:40
thread_context.hh
gem5::loader::Linux
@ Linux
Definition: object_file.hh:73
syscall_desc.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177

Generated on Tue Sep 21 2021 12:24:34 for gem5 by doxygen 1.8.17