gem5  v21.1.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
syscalls.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Google Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
29 
30 #include "arch/x86/linux/linux.hh"
31 #include "arch/x86/process.hh"
32 #include "arch/x86/regs/misc.hh"
33 #include "base/trace.hh"
34 #include "cpu/thread_context.hh"
35 #include "kern/linux/linux.hh"
36 #include "sim/process.hh"
37 #include "sim/syscall_desc.hh"
38 #include "sim/syscall_emul.hh"
39 
40 namespace gem5
41 {
42 
43 namespace X86ISA
44 {
45 
47 SyscallReturn
49 {
50  auto process = tc->getProcessPtr();
51 
52  strcpy(name->sysname, "Linux");
53  strcpy(name->nodename, "sim.gem5.org");
54  strcpy(name->release, process->release.c_str());
55  strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");
56  strcpy(name->machine, "x86_64");
57 
58  return 0;
59 }
60 
62 archPrctlFunc(SyscallDesc *desc, ThreadContext *tc, int code, uint64_t addr)
63 {
64  enum ArchPrctlCodes
65  {
66  SetFS = 0x1002,
67  GetFS = 0x1003,
68  SetGS = 0x1001,
69  GetGS = 0x1004
70  };
71 
72  uint64_t fsBase, gsBase;
73  PortProxy &p = tc->getVirtProxy();
74  switch(code)
75  {
76  // Each of these valid options should actually check addr.
77  case SetFS:
80  return 0;
81  case GetFS:
83  p.write(addr, fsBase);
84  return 0;
85  case SetGS:
88  return 0;
89  case GetGS:
91  p.write(addr, gsBase);
92  return 0;
93  default:
94  return -EINVAL;
95  }
96 }
97 
100  VPtr<UserDesc32> userDesc)
101 {
102  const int minTLSEntry = 6;
103  const int numTLSEntries = 3;
104  const int maxTLSEntry = minTLSEntry + numTLSEntries - 1;
105 
106  auto process = tc->getProcessPtr();
107 
108  X86Process *x86p = dynamic_cast<X86Process *>(process);
109  assert(x86p);
110 
111  assert((maxTLSEntry + 1) * sizeof(uint64_t) <= x86p->gdtSize());
112 
114  gdt(x86p->gdtStart() + minTLSEntry * sizeof(uint64_t),
115  numTLSEntries * sizeof(uint64_t));
116 
117  if (!gdt.copyIn(tc->getVirtProxy()))
118  panic("Failed to copy in GDT for %s.\n", desc->name());
119 
120  if (userDesc->entry_number == (uint32_t)(-1)) {
121  // Find a free TLS entry.
122  for (int i = 0; i < numTLSEntries; i++) {
123  if (gdt[i] == 0) {
124  userDesc->entry_number = i + minTLSEntry;
125  break;
126  }
127  }
128  // We failed to find one.
129  if (userDesc->entry_number == (uint32_t)(-1))
130  return -ESRCH;
131  }
132 
133  int index = userDesc->entry_number;
134 
135  if (index < minTLSEntry || index > maxTLSEntry)
136  return -EINVAL;
137 
138  index -= minTLSEntry;
139 
140  // Build the entry we're going to add.
141  SegDescriptor segDesc = 0;
142  UserDescFlags flags = userDesc->flags;
143 
144  segDesc.limitLow = bits(userDesc->limit, 15, 0);
145  segDesc.baseLow = bits(userDesc->base_addr, 23, 0);
146  segDesc.type.a = 1;
147  if (!flags.read_exec_only)
148  segDesc.type.w = 1;
149  if (bits((uint8_t)flags.contents, 0))
150  segDesc.type.e = 1;
151  if (bits((uint8_t)flags.contents, 1))
152  segDesc.type.codeOrData = 1;
153  segDesc.s = 1;
154  segDesc.dpl = 3;
155  if (!flags.seg_not_present)
156  segDesc.p = 1;
157  segDesc.limitHigh = bits(userDesc->limit, 19, 16);
158  if (flags.useable)
159  segDesc.avl = 1;
160  segDesc.l = 0;
161  if (flags.seg_32bit)
162  segDesc.d = 1;
163  if (flags.limit_in_pages)
164  segDesc.g = 1;
165  segDesc.baseHigh = bits(userDesc->base_addr, 31, 24);
166 
167  gdt[index] = (uint64_t)segDesc;
168 
169  if (!gdt.copyOut(tc->getVirtProxy()))
170  panic("Failed to copy out GDT for %s.\n", desc->name());
171 
172  return 0;
173 }
174 
175 } // namespace X86ISA
176 } // namespace gem5
gem5::X86ISA::MISCREG_FS_BASE
@ MISCREG_FS_BASE
Definition: misc.hh:322
linux.hh
gem5::TypedBufferArg
TypedBufferArg is a class template; instances of this template represent typed buffers in target user...
Definition: syscall_emul_buf.hh:132
gem5::SyscallReturn
This class represents the return value from an emulated system call, including any errno setting.
Definition: syscall_return.hh:55
gem5::X86ISA::archPrctlFunc
SyscallReturn archPrctlFunc(SyscallDesc *desc, ThreadContext *tc, int code, uint64_t addr)
Definition: syscalls.cc:62
gem5::X86ISA::unameFunc
SyscallReturn unameFunc(SyscallDesc *desc, ThreadContext *tc, VPtr< Linux::utsname > name)
Target uname() handler.
Definition: syscalls.cc:48
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::X86ISA::X86Process::gdtSize
Addr gdtSize() const
Definition: process.hh:81
gem5::X86ISA::X86Process
Definition: process.hh:67
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
gem5::X86ISA::MISCREG_FS_EFF_BASE
@ MISCREG_FS_EFF_BASE
Definition: misc.hh:340
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
gem5::ProxyPtr
Definition: proxy_ptr.hh:238
gem5::bits
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
gem5::ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
name
const std::string & name()
Definition: trace.cc:49
gem5::X86ISA::setThreadArea32Func
SyscallReturn setThreadArea32Func(SyscallDesc *desc, ThreadContext *tc, VPtr< UserDesc32 > userDesc)
Definition: syscalls.cc:99
gem5::BaseBufferArg::copyIn
bool copyIn(const PortProxy &memproxy)
copy data into simulator space (read from target memory)
Definition: syscall_emul_buf.hh:81
gem5::ThreadContext::getProcessPtr
virtual Process * getProcessPtr()=0
syscalls.hh
syscall_emul.hh
process.hh
gem5::X86ISA::index
Bitfield< 5, 3 > index
Definition: types.hh:98
gem5::BaseBufferArg::copyOut
bool copyOut(const PortProxy &memproxy)
copy data out of simulator space (write to target memory)
Definition: syscall_emul_buf.hh:91
gem5::X86ISA::MISCREG_GS_BASE
@ MISCREG_GS_BASE
Definition: misc.hh:323
linux.hh
gem5::X86ISA::p
Bitfield< 0 > p
Definition: pagetable.hh:151
gem5::X86ISA::MISCREG_GS_EFF_BASE
@ MISCREG_GS_EFF_BASE
Definition: misc.hh:341
gem5::X86ISA::X86Process::gdtStart
Addr gdtStart() const
Definition: process.hh:80
trace.hh
gem5::SyscallDesc
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:69
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::SyscallDesc::name
std::string name() const
Definition: syscall_desc.hh:80
misc.hh
thread_context.hh
syscall_desc.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:84
gem5::ThreadContext::setMiscRegNoEffect
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0

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