gem5  v22.1.0.0
exec_context.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2014, 2016-2018, 2020-2021 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2002-2005 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
48 #ifndef __CPU_MINOR_EXEC_CONTEXT_HH__
49 #define __CPU_MINOR_EXEC_CONTEXT_HH__
50 
51 #include "cpu/exec_context.hh"
52 #include "cpu/minor/execute.hh"
53 #include "cpu/minor/pipeline.hh"
54 #include "cpu/base.hh"
55 #include "cpu/simple_thread.hh"
56 #include "mem/request.hh"
57 #include "debug/MinorExecute.hh"
58 
59 namespace gem5
60 {
61 
63 namespace minor
64 {
65 
66 /* Forward declaration of Execute */
67 class Execute;
68 
74 {
75  public:
77 
80 
83 
86 
88  MinorCPU &cpu_,
89  SimpleThread &thread_, Execute &execute_,
90  MinorDynInstPtr inst_) :
91  cpu(cpu_),
92  thread(thread_),
93  execute(execute_),
94  inst(inst_)
95  {
96  DPRINTF(MinorExecute, "ExecContext setting PC: %s\n", *inst->pc);
97  pcState(*inst->pc);
98  setPredicate(inst->readPredicate());
99  setMemAccPredicate(inst->readMemAccPredicate());
100  }
101 
103  {
104  inst->setPredicate(readPredicate());
105  inst->setMemAccPredicate(readMemAccPredicate());
106  }
107 
108  Fault
109  initiateMemRead(Addr addr, unsigned int size,
111  const std::vector<bool>& byte_enable) override
112  {
113  assert(byte_enable.size() == size);
114  return execute.getLSQ().pushRequest(inst, true /* load */, nullptr,
115  size, addr, flags, nullptr, nullptr, byte_enable);
116  }
117 
118  Fault
120  {
121  panic("ExecContext::initiateMemMgmtCmd() not implemented "
122  " on MinorCPU\n");
123  return NoFault;
124  }
125 
126  Fault
127  writeMem(uint8_t *data, unsigned int size, Addr addr,
128  Request::Flags flags, uint64_t *res,
129  const std::vector<bool>& byte_enable)
130  override
131  {
132  assert(byte_enable.size() == size);
133  return execute.getLSQ().pushRequest(inst, false /* store */, data,
134  size, addr, flags, res, nullptr, byte_enable);
135  }
136 
137  Fault
139  AtomicOpFunctorPtr amo_op) override
140  {
141  // AMO requests are pushed through the store path
142  return execute.getLSQ().pushRequest(inst, false /* amo */, nullptr,
143  size, addr, flags, nullptr, std::move(amo_op),
144  std::vector<bool>(size, true));
145  }
146 
147  RegVal
148  getRegOperand(const StaticInst *si, int idx) override
149  {
150  const RegId &reg = si->srcRegIdx(idx);
151  if (reg.is(InvalidRegClass))
152  return 0;
153  return thread.getReg(reg);
154  }
155 
156  void
157  getRegOperand(const StaticInst *si, int idx, void *val) override
158  {
159  thread.getReg(si->srcRegIdx(idx), val);
160  }
161 
162  void *
163  getWritableRegOperand(const StaticInst *si, int idx) override
164  {
165  return thread.getWritableReg(si->destRegIdx(idx));
166  }
167 
168  void
169  setRegOperand(const StaticInst *si, int idx, RegVal val) override
170  {
171  const RegId &reg = si->destRegIdx(idx);
172  if (reg.is(InvalidRegClass))
173  return;
174  thread.setReg(si->destRegIdx(idx), val);
175  }
176 
177  void
178  setRegOperand(const StaticInst *si, int idx, const void *val) override
179  {
180  thread.setReg(si->destRegIdx(idx), val);
181  }
182 
183  bool
184  readPredicate() const override
185  {
186  return thread.readPredicate();
187  }
188 
189  void
190  setPredicate(bool val) override
191  {
193  }
194 
195  bool
196  readMemAccPredicate() const override
197  {
198  return thread.readMemAccPredicate();
199  }
200 
201  void
202  setMemAccPredicate(bool val) override
203  {
205  }
206 
207  // hardware transactional memory
208  uint64_t
209  getHtmTransactionUid() const override
210  {
211  panic("ExecContext::getHtmTransactionUid() not"
212  "implemented on MinorCPU\n");
213  return 0;
214  }
215 
216  uint64_t
217  newHtmTransactionUid() const override
218  {
219  panic("ExecContext::newHtmTransactionUid() not"
220  "implemented on MinorCPU\n");
221  return 0;
222  }
223 
224  bool
225  inHtmTransactionalState() const override
226  {
227  // ExecContext::inHtmTransactionalState() not
228  // implemented on MinorCPU
229  return false;
230  }
231 
232  uint64_t
233  getHtmTransactionalDepth() const override
234  {
235  panic("ExecContext::getHtmTransactionalDepth() not"
236  "implemented on MinorCPU\n");
237  return 0;
238  }
239 
240  const PCStateBase &
241  pcState() const override
242  {
243  return thread.pcState();
244  }
245 
246  void
247  pcState(const PCStateBase &val) override
248  {
249  thread.pcState(val);
250  }
251 
252  RegVal
253  readMiscRegNoEffect(int misc_reg) const
254  {
255  return thread.readMiscRegNoEffect(misc_reg);
256  }
257 
258  RegVal
259  readMiscReg(int misc_reg) override
260  {
261  return thread.readMiscReg(misc_reg);
262  }
263 
264  void
265  setMiscReg(int misc_reg, RegVal val) override
266  {
267  thread.setMiscReg(misc_reg, val);
268  }
269 
270  RegVal
271  readMiscRegOperand(const StaticInst *si, int idx) override
272  {
273  const RegId& reg = si->srcRegIdx(idx);
274  assert(reg.is(MiscRegClass));
275  return thread.readMiscReg(reg.index());
276  }
277 
278  void
279  setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
280  {
281  const RegId& reg = si->destRegIdx(idx);
282  assert(reg.is(MiscRegClass));
283  return thread.setMiscReg(reg.index(), val);
284  }
285 
286  ThreadContext *tcBase() const override { return thread.getTC(); }
287 
288  /* @todo, should make stCondFailures persistent somewhere */
289  unsigned int readStCondFailures() const override { return 0; }
290  void setStCondFailures(unsigned int st_cond_failures) override {}
291 
293  /* ISA-specific (or at least currently ISA singleton) functions */
294 
295  /* X86: TLB twiddling */
296  void
297  demapPage(Addr vaddr, uint64_t asn) override
298  {
299  thread.getMMUPtr()->demapPage(vaddr, asn);
300  }
301 
302  BaseCPU *getCpuPtr() { return &cpu; }
303 
304  public:
305  // monitor/mwait funtions
306  void
307  armMonitor(Addr address) override
308  {
309  getCpuPtr()->armMonitor(inst->id.threadId, address);
310  }
311 
312  bool
313  mwait(PacketPtr pkt) override
314  {
315  return getCpuPtr()->mwait(inst->id.threadId, pkt);
316  }
317 
318  void
320  {
321  return getCpuPtr()->mwaitAtomic(inst->id.threadId, tc, thread.mmu);
322  }
323 
325  getAddrMonitor() override
326  {
327  return getCpuPtr()->getCpuAddrMonitor(inst->id.threadId);
328  }
329 };
330 
331 } // namespace minor
332 } // namespace gem5
333 
334 #endif /* __CPU_MINOR_EXEC_CONTEXT_HH__ */
#define DPRINTF(x,...)
Definition: trace.hh:186
const char data[]
AddressMonitor * getCpuAddrMonitor(ThreadID tid)
Definition: base.hh:633
void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseMMU *mmu)
Definition: base.cc:240
bool mwait(ThreadID tid, PacketPtr pkt)
Definition: base.cc:217
void armMonitor(ThreadID tid, Addr address)
Definition: base.cc:205
void demapPage(Addr vaddr, uint64_t asn)
Definition: mmu.cc:97
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:72
MinorCPU is an in-order CPU model with four fixed pipeline stages:
Definition: cpu.hh:86
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
RegVal readMiscRegNoEffect(RegIndex misc_reg) const override
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
bool readPredicate() const
void setPredicate(bool val)
const PCStateBase & pcState() const override
void setMiscReg(RegIndex misc_reg, RegVal val) override
void * getWritableReg(const RegId &arch_reg) override
ContextID contextId() const override
void setReg(const RegId &arch_reg, RegVal val) override
RegVal readMiscReg(RegIndex misc_reg) override
void setMemAccPredicate(bool val)
RegVal getReg(const RegId &arch_reg) const override
BaseMMU * getMMUPtr() override
Base, ISA-independent static instruction class.
Definition: static_inst.hh:89
ThreadContext is the external interface to all thread state for anything outside of the CPU.
ExecContext bears the exec_context interface for Minor.
Definition: exec_context.hh:74
ExecContext(MinorCPU &cpu_, SimpleThread &thread_, Execute &execute_, MinorDynInstPtr inst_)
Definition: exec_context.hh:87
uint64_t getHtmTransactionalDepth() const override
void armMonitor(Addr address) override
void setStCondFailures(unsigned int st_cond_failures) override
Sets the number of consecutive store conditional failures.
const PCStateBase & pcState() const override
Fault initiateMemAMO(Addr addr, unsigned int size, Request::Flags flags, AtomicOpFunctorPtr amo_op) override
For timing-mode contexts, initiate an atomic AMO (atomic read-modify-write memory operation)
void setMiscReg(int misc_reg, RegVal val) override
Sets a miscellaneous register, handling any architectural side effects due to writing that register.
RegVal readMiscRegOperand(const StaticInst *si, int idx) override
RegVal readMiscReg(int misc_reg) override
Reads a miscellaneous register, handling any architectural side effects due to reading that register.
bool inHtmTransactionalState() const override
RegVal getRegOperand(const StaticInst *si, int idx) override
Fault initiateMemRead(Addr addr, unsigned int size, Request::Flags flags, const std::vector< bool > &byte_enable) override
Initiate a timing memory read operation.
void setRegOperand(const StaticInst *si, int idx, RegVal val) override
RegVal readMiscRegNoEffect(int misc_reg) const
AddressMonitor * getAddrMonitor() override
uint64_t getHtmTransactionUid() const override
bool mwait(PacketPtr pkt) override
bool readMemAccPredicate() const override
unsigned int readStCondFailures() const override
Returns the number of consecutive store conditional failures.
void * getWritableRegOperand(const StaticInst *si, int idx) override
uint64_t newHtmTransactionUid() const override
Fault initiateMemMgmtCmd(Request::Flags flags) override
Initiate a memory management command with no valid address.
void getRegOperand(const StaticInst *si, int idx, void *val) override
ThreadContext * tcBase() const override
Returns a pointer to the ThreadContext.
Fault writeMem(uint8_t *data, unsigned int size, Addr addr, Request::Flags flags, uint64_t *res, const std::vector< bool > &byte_enable) override
For atomic-mode contexts, perform an atomic memory write operation.
void pcState(const PCStateBase &val) override
void demapPage(Addr vaddr, uint64_t asn) override
Invalidate a page in the DTLB and ITLB.
void setMemAccPredicate(bool val) override
void setRegOperand(const StaticInst *si, int idx, const void *val) override
void setPredicate(bool val) override
MinorDynInstPtr inst
Instruction for the benefit of memory operations and for PC.
Definition: exec_context.hh:85
void setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
void mwaitAtomic(ThreadContext *tc) override
SimpleThread & thread
ThreadState object, provides all the architectural state.
Definition: exec_context.hh:79
bool readPredicate() const override
Execute & execute
The execute stage so we can peek at its contents.
Definition: exec_context.hh:82
Execute stage.
Definition: execute.hh:69
LSQ & getLSQ()
To allow ExecContext to find the LSQ.
Definition: execute.hh:338
Fault pushRequest(MinorDynInstPtr inst, bool isLoad, uint8_t *data, unsigned int size, Addr addr, Request::Flags flags, uint64_t *res, AtomicOpFunctorPtr amo_op, const std::vector< bool > &byte_enable=std::vector< bool >())
Single interface for readMem/writeMem/amoMem to issue requests into the LSQ.
Definition: lsq.cc:1584
All the fun of executing instructions from Decode and sending branch/new instruction stream info.
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition: amo.hh:242
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
uint8_t flags
Definition: helpers.cc:66
Bitfield< 6 > si
Definition: misc_types.hh:831
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
uint64_t RegVal
Definition: types.hh:173
constexpr decltype(nullptr) NoFault
Definition: types.hh:253
@ InvalidRegClass
Definition: reg_class.hh:69
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:68
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
Minor contains all the definitions within the MinorCPU apart from the CPU class itself.
The constructed pipeline.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...

Generated on Wed Dec 21 2022 10:22:30 for gem5 by doxygen 1.9.1