gem5  v20.1.0.0
process.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2004 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef __SPARC_PROCESS_HH__
30 #define __SPARC_PROCESS_HH__
31 
32 #include <memory>
33 #include <string>
34 #include <vector>
35 
36 #include "arch/sparc/isa_traits.hh"
37 #include "arch/sparc/miscregs.hh"
39 #include "mem/page_table.hh"
40 #include "sim/byteswap.hh"
41 #include "sim/process.hh"
42 #include "sim/syscall_abi.hh"
43 
44 class SparcProcess : public Process
45 {
46  protected:
47 
48  const Addr StackBias;
49 
50  // The locations of the fill and spill handlers
52 
53  SparcProcess(ProcessParams * params, ::Loader::ObjectFile *objFile,
54  Addr _StackBias);
55 
56  void initState() override;
57 
58  template<class IntType>
59  void argsInit(int pageSize);
60 
61  public:
62 
63  // Handles traps which request services from the operating system
64  virtual void handleTrap(int trapNum, ThreadContext *tc);
65 
68 
69  virtual void flushWindows(ThreadContext *tc) = 0;
70 
71  struct SyscallABI
72  {
74  };
75 };
76 
77 namespace GuestABI
78 {
79 
80 template <typename ABI>
81 struct Result<ABI, SyscallReturn,
82  typename std::enable_if<std::is_base_of<
83  SparcProcess::SyscallABI, ABI>::value>::type>
84 {
85  static void
87  {
88  if (ret.suppressed() || ret.needsRetry())
89  return;
90 
91  // check for error condition. SPARC syscall convention is to
92  // indicate success/failure in reg the carry bit of the ccr
93  // and put the return value itself in the standard return value reg.
94  SparcISA::PSTATE pstate =
96  SparcISA::CCR ccr = tc->readIntReg(SparcISA::INTREG_CCR);
97  RegVal val;
98  if (ret.successful()) {
99  ccr.xcc.c = ccr.icc.c = 0;
100  val = ret.returnValue();
101  } else {
102  ccr.xcc.c = ccr.icc.c = 1;
103  val = ret.errnoValue();
104  }
106  if (pstate.am)
107  val = bits(val, 31, 0);
109  if (ret.count() == 2)
111  }
112 };
113 
114 } // namespace GuestABI
115 
117 {
118  protected:
119 
122  {
123  Addr brk_point = image.maxAddr();
124  brk_point = roundUp(brk_point, SparcISA::PageBytes);
125 
126  // Reserve 8M for main stack.
127  Addr max_stack_size = 8 * 1024 * 1024;
128 
129  // Set up stack. On SPARC Linux, stack goes from the top of memory
130  // downward, less the hole for the kernel address space.
131  Addr stack_base = 0xf0000000ULL;
132 
133  // Set pointer for next thread stack.
134  Addr next_thread_stack_base = stack_base - max_stack_size;
135 
136  // Set up region for mmaps.
137  Addr mmap_end = 0x70000000;
138 
139  memState = std::make_shared<MemState>(this, brk_point, stack_base,
140  max_stack_size,
141  next_thread_stack_base,
142  mmap_end);
143  }
144 
145  void initState() override;
146 
147  public:
148 
149  void argsInit(int intSize, int pageSize);
150 
151  void flushWindows(ThreadContext *tc) override;
152 
155  {};
156 };
157 
158 namespace GuestABI
159 {
160 
161 template <typename Arg>
162 struct Argument<Sparc32Process::SyscallABI, Arg,
163  typename std::enable_if<
164  Sparc32Process::SyscallABI::IsWide<Arg>::value>::type>
165 {
167 
168  static Arg
169  get(ThreadContext *tc, typename ABI::State &state)
170  {
171  panic_if(state + 1 >= ABI::ArgumentRegs.size(),
172  "Ran out of syscall argument registers.");
173  auto high = ABI::ArgumentRegs[state++];
174  auto low = ABI::ArgumentRegs[state++];
175  return (Arg)ABI::mergeRegs(tc, low, high);
176  }
177 };
178 
179 } // namespace GuestABI
180 
182 {
183  protected:
184 
186  : SparcProcess(params, objFile, 2047)
187  {
188  Addr brk_point = image.maxAddr();
189  brk_point = roundUp(brk_point, SparcISA::PageBytes);
190 
191  Addr max_stack_size = 8 * 1024 * 1024;
192 
193  // Set up stack. On SPARC Linux, stack goes from the top of memory
194  // downward, less the hole for the kernel address space.
195  Addr stack_base = 0x80000000000ULL;
196 
197  // Set pointer for next thread stack. Reserve 8M for main stack.
198  Addr next_thread_stack_base = stack_base - max_stack_size;
199 
200  // Set up region for mmaps.
201  Addr mmap_end = 0xfffff80000000000ULL;
202 
203  memState = std::make_shared<MemState>(this, brk_point, stack_base,
204  max_stack_size,
205  next_thread_stack_base,
206  mmap_end);
207  }
208 
209  void initState() override;
210 
211  public:
212 
213  void argsInit(int intSize, int pageSize);
214 
215  void flushWindows(ThreadContext *tc) override;
216 
219  {};
220 };
221 
222 #endif // __SPARC_PROCESS_HH__
ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
SparcProcess::readFillStart
Addr readFillStart()
Definition: process.hh:66
SparcISA::MISCREG_PSTATE
@ MISCREG_PSTATE
Definition: miscregs.hh:62
RiscvISA::ArgumentRegs
const std::vector< int > ArgumentRegs
Definition: registers.hh:100
SparcProcess::SyscallABI::ArgumentRegs
static const std::vector< int > ArgumentRegs
Definition: process.hh:73
GuestABI::Result< ABI, SyscallReturn, typename std::enable_if< std::is_base_of< SparcProcess::SyscallABI, ABI >::value >::type >::store
static void store(ThreadContext *tc, const SyscallReturn &ret)
Definition: process.hh:86
GenericSyscallABI::State
int State
Definition: syscall_abi.hh:52
Process
Definition: process.hh:65
Sparc64Process::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:169
GenericSyscallABI64
Definition: syscall_abi.hh:55
Sparc32Process::flushWindows
void flushWindows(ThreadContext *tc) override
Definition: process.cc:437
Sparc64Process::SyscallABI
Definition: process.hh:217
type
uint8_t type
Definition: inet.hh:421
ThreadContext::setIntReg
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
SyscallReturn::value2
int64_t value2() const
Definition: syscall_return.hh:120
SparcISA::INTREG_CCR
@ INTREG_CCR
Definition: registers.hh:80
std::vector< int >
syscall_abi.hh
Loader::MemoryImage::maxAddr
Addr maxAddr() const
Definition: memory_image.hh:131
SparcProcess
Definition: process.hh:44
SparcProcess::StackBias
const Addr StackBias
Definition: process.hh:48
SparcISA::PageBytes
const Addr PageBytes
Definition: isa_traits.hh:40
Sparc32Process::Sparc32Process
Sparc32Process(ProcessParams *params, ::Loader::ObjectFile *objFile)
Definition: process.hh:120
SyscallReturn::returnValue
int64_t returnValue() const
The return value.
Definition: syscall_return.hh:104
Loader::ObjectFile
Definition: object_file.hh:70
SyscallReturn::suppressed
bool suppressed() const
Should returning this value be suppressed?
Definition: syscall_return.hh:97
miscregs.hh
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
SyscallReturn::errnoValue
int errnoValue() const
The errno value.
Definition: syscall_return.hh:112
SparcProcess::spillStart
Addr spillStart
Definition: process.hh:51
GuestABI
Definition: aapcs32.hh:66
SparcProcess::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:110
SyscallReturn::needsRetry
bool needsRetry() const
Does the syscall need to be retried?
Definition: syscall_return.hh:94
SparcProcess::flushWindows
virtual void flushWindows(ThreadContext *tc)=0
isa_traits.hh
GuestABI::Argument
Definition: definition.hh:93
process.hh
SparcProcess::readSpillStart
Addr readSpillStart()
Definition: process.hh:67
Process::image
::Loader::MemoryImage image
Definition: process.hh:214
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
Sparc64Process::Sparc64Process
Sparc64Process(ProcessParams *params, ::Loader::ObjectFile *objFile)
Definition: process.hh:185
SparcProcess::fillStart
Addr fillStart
Definition: process.hh:51
Sparc64Process::argsInit
void argsInit(int intSize, int pageSize)
Definition: process.cc:414
Sparc64Process
Definition: process.hh:181
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Process::objFile
::Loader::ObjectFile * objFile
Definition: process.hh:213
SyscallReturn
This class represents the return value from an emulated system call, including any errno setting.
Definition: syscall_return.hh:52
SimObject::params
const Params * params() const
Definition: sim_object.hh:119
Sparc32Process::argsInit
void argsInit(int intSize, int pageSize)
Definition: process.cc:426
Sparc32Process::SyscallABI
Definition: process.hh:153
SparcProcess::argsInit
void argsInit(int pageSize)
Definition: process.cc:184
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
GuestABI::Result
Definition: definition.hh:58
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
SparcProcess::SparcProcess
SparcProcess(ProcessParams *params, ::Loader::ObjectFile *objFile, Addr _StackBias)
Definition: process.cc:55
roundUp
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
Definition: intmath.hh:131
GuestABI::Argument< Sparc32Process::SyscallABI, Arg, typename std::enable_if< Sparc32Process::SyscallABI::IsWide< Arg >::value >::type >::get
static Arg get(ThreadContext *tc, typename ABI::State &state)
Definition: process.hh:169
SyscallReturn::count
int count() const
How many values did the syscall attempt to return?
Definition: syscall_return.hh:100
SparcISA::ReturnValueReg
const int ReturnValueReg
Definition: registers.hh:94
Sparc32Process::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:154
Sparc64Process::flushWindows
void flushWindows(ThreadContext *tc) override
Definition: process.cc:472
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
page_table.hh
SparcISA::SyscallPseudoReturnReg
const int SyscallPseudoReturnReg
Definition: registers.hh:99
object_file.hh
SparcProcess::handleTrap
virtual void handleTrap(int trapNum, ThreadContext *tc)
Definition: process.cc:69
SparcProcess::SyscallABI
Definition: process.hh:71
Sparc32Process
Definition: process.hh:116
GenericSyscallABI32
Definition: syscall_abi.hh:58
ULL
#define ULL(N)
uint64_t constant
Definition: types.hh:50
Process::memState
std::shared_ptr< MemState > memState
Definition: process.hh:279
RegVal
uint64_t RegVal
Definition: types.hh:168
byteswap.hh
SyscallReturn::successful
bool successful() const
Was the system call successful?
Definition: syscall_return.hh:88
bits
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:75

Generated on Wed Sep 30 2020 14:02:00 for gem5 by doxygen 1.8.17