gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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, Fault *fault);
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 
121  : SparcProcess(params, objFile, 0)
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__
const int SyscallPseudoReturnReg
Definition: registers.hh:99
const std::vector< int > ArgumentRegs
Definition: registers.hh:101
SparcProcess(ProcessParams *params, ::Loader::ObjectFile *objFile, Addr _StackBias)
Definition: process.cc:55
virtual RegVal readIntReg(RegIndex reg_idx) const =0
bool successful() const
Was the system call successful?
static const std::vector< int > ArgumentRegs
Definition: process.hh:73
void argsInit(int pageSize)
Definition: process.cc:184
uint64_t RegVal
Definition: types.hh:166
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Addr maxAddr() const
const Addr StackBias
Definition: process.hh:48
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
Definition: intmath.hh:114
std::shared_ptr< MemState > memState
Definition: process.hh:279
const Addr PageBytes
Definition: isa_traits.hh:43
ThreadContext is the external interface to all thread state for anything outside of the CPU...
int errnoValue() const
The errno value.
Bitfield< 63 > val
Definition: misc.hh:769
uint8_t type
Definition: inet.hh:328
virtual void flushWindows(ThreadContext *tc)=0
int64_t value2() const
Addr readSpillStart()
Definition: process.hh:67
Addr spillStart
Definition: process.hh:51
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
const Params * params() const
Definition: sim_object.hh:118
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
int count() const
How many values did the syscall attempt to return?
#define ULL(N)
uint64_t constant
Definition: types.hh:48
int64_t returnValue() const
The return value.
Sparc64Process(ProcessParams *params, ::Loader::ObjectFile *objFile)
Definition: process.hh:185
bool suppressed() const
Should returning this value be suppressed?
Addr fillStart
Definition: process.hh:51
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
Declarations of a non-full system Page Table.
::Loader::MemoryImage image
Definition: process.hh:214
virtual void handleTrap(int trapNum, ThreadContext *tc, Fault *fault)
Definition: process.cc:69
bool needsRetry() const
Does the syscall need to be retried?
Sparc32Process(ProcessParams *params, ::Loader::ObjectFile *objFile)
Definition: process.hh:120
This class represents the return value from an emulated system call, including any errno setting...
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:71
const int ReturnValueReg
Definition: registers.hh:94
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:181
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
::Loader::ObjectFile * objFile
Definition: process.hh:213
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: process.cc:110
Addr readFillStart()
Definition: process.hh:66

Generated on Mon Jun 8 2020 15:34:39 for gem5 by doxygen 1.8.13