gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
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
47
48#ifndef __CPU_MINOR_EXEC_CONTEXT_HH__
49#define __CPU_MINOR_EXEC_CONTEXT_HH__
50
51#include "cpu/base.hh"
52#include "cpu/exec_context.hh"
53#include "cpu/minor/execute.hh"
54#include "cpu/minor/pipeline.hh"
55#include "cpu/simple_thread.hh"
56#include "debug/MinorExecute.hh"
57#include "mem/request.hh"
58
59namespace gem5
60{
61
62namespace minor
63{
64
65/* Forward declaration of Execute */
66class Execute;
67
73{
74 public:
76
79
82
85
87 MinorCPU &cpu_,
88 SimpleThread &thread_, Execute &execute_,
89 MinorDynInstPtr inst_) :
90 cpu(cpu_),
91 thread(thread_),
92 execute(execute_),
93 inst(inst_)
94 {
95 DPRINTF(MinorExecute, "ExecContext setting PC: %s\n", *inst->pc);
96 pcState(*inst->pc);
97 setPredicate(inst->readPredicate());
98 setMemAccPredicate(inst->readMemAccPredicate());
99 }
100
102 {
103 inst->setPredicate(readPredicate());
104 inst->setMemAccPredicate(readMemAccPredicate());
105 }
106
107 Fault
108 initiateMemRead(Addr addr, unsigned int size,
109 Request::Flags flags,
110 const std::vector<bool>& byte_enable) override
111 {
112 assert(byte_enable.size() == size);
113 return execute.getLSQ().pushRequest(inst, true /* load */, nullptr,
114 size, addr, flags, nullptr, nullptr, byte_enable);
115 }
116
117 Fault
119 {
120 panic("ExecContext::initiateMemMgmtCmd() not implemented "
121 " on MinorCPU\n");
122 return NoFault;
123 }
124
125 Fault
126 writeMem(uint8_t *data, unsigned int size, Addr addr,
127 Request::Flags flags, uint64_t *res,
128 const std::vector<bool>& byte_enable)
129 override
130 {
131 assert(byte_enable.size() == size);
132 return execute.getLSQ().pushRequest(inst, false /* store */, data,
133 size, addr, flags, res, nullptr, byte_enable);
134 }
135
136 Fault
137 initiateMemAMO(Addr addr, unsigned int size, Request::Flags flags,
138 AtomicOpFunctorPtr amo_op) override
139 {
140 // AMO requests are pushed through the store path
141 return execute.getLSQ().pushRequest(inst, false /* amo */, nullptr,
142 size, addr, flags, nullptr, std::move(amo_op),
143 std::vector<bool>(size, true));
144 }
145
146 RegVal
147 getRegOperand(const StaticInst *si, int idx) override
148 {
149 const RegId &reg = si->srcRegIdx(idx);
150 int tid = thread.threadId();
151 if (reg.is(InvalidRegClass))
152 return 0;
153 switch (reg.classValue()) {
154 case IntRegClass:
155 cpu.executeStats[tid]->numIntRegReads++;
156 break;
157 case FloatRegClass:
158 cpu.executeStats[tid]->numFpRegReads++;
159 break;
160 case CCRegClass:
161 cpu.executeStats[tid]->numCCRegReads++;
162 break;
163 case VecRegClass:
164 case VecElemClass:
165 cpu.executeStats[tid]->numVecRegReads++;
166 break;
167 case VecPredRegClass:
168 cpu.executeStats[tid]->numVecPredRegReads++;
169 break;
170 default:
171 break;
172 }
173 return thread.getReg(reg);
174 }
175
176 void
177 getRegOperand(const StaticInst *si, int idx, void *val) override
178 {
179 const RegId &reg = si->srcRegIdx(idx);
180 int tid = thread.threadId();
181 switch (reg.classValue()) {
182 case IntRegClass:
183 cpu.executeStats[tid]->numIntRegReads++;
184 break;
185 case FloatRegClass:
186 cpu.executeStats[tid]->numFpRegReads++;
187 break;
188 case CCRegClass:
189 cpu.executeStats[tid]->numCCRegReads++;
190 break;
191 case VecRegClass:
192 case VecElemClass:
193 cpu.executeStats[tid]->numVecRegReads++;
194 break;
195 case VecPredRegClass:
196 cpu.executeStats[tid]->numVecPredRegReads++;
197 break;
198 default:
199 break;
200 }
201
202 thread.getReg(si->srcRegIdx(idx), val);
203 }
204
205 void *
206 getWritableRegOperand(const StaticInst *si, int idx) override
207 {
208 const RegId &reg = si->destRegIdx(idx);
209 int tid = thread.threadId();
210 switch (reg.classValue()) {
211 case VecRegClass:
212 cpu.executeStats[tid]->numVecRegWrites++;
213 break;
214 case VecPredRegClass:
215 cpu.executeStats[tid]->numVecPredRegWrites++;
216 break;
217 default:
218 break;
219 }
220 return thread.getWritableReg(reg);
221 }
222
223 void
224 setRegOperand(const StaticInst *si, int idx, RegVal val) override
225 {
226 const RegId &reg = si->destRegIdx(idx);
227 int tid = thread.threadId();
228 if (reg.is(InvalidRegClass))
229 return;
230 switch (reg.classValue()) {
231 case IntRegClass:
232 cpu.executeStats[tid]->numIntRegWrites++;
233 break;
234 case FloatRegClass:
235 cpu.executeStats[tid]->numFpRegWrites++;
236 break;
237 case CCRegClass:
238 cpu.executeStats[tid]->numCCRegWrites++;
239 break;
240 case VecRegClass:
241 case VecElemClass:
242 cpu.executeStats[tid]->numVecRegWrites++;
243 break;
244 case VecPredRegClass:
245 cpu.executeStats[tid]->numVecPredRegWrites++;
246 break;
247 default:
248 break;
249 }
250 thread.setReg(si->destRegIdx(idx), val);
251 }
252
253 void
254 setRegOperand(const StaticInst *si, int idx, const void *val) override
255 {
256 const RegId &reg = si->destRegIdx(idx);
257 int tid = thread.threadId();
258 switch (reg.classValue()) {
259 case IntRegClass:
260 cpu.executeStats[tid]->numIntRegWrites++;
261 break;
262 case FloatRegClass:
263 cpu.executeStats[tid]->numFpRegWrites++;
264 break;
265 case CCRegClass:
266 cpu.executeStats[tid]->numCCRegWrites++;
267 break;
268 case VecRegClass:
269 case VecElemClass:
270 cpu.executeStats[tid]->numVecRegWrites++;
271 break;
272 case VecPredRegClass:
273 cpu.executeStats[tid]->numVecPredRegWrites++;
274 break;
275 default:
276 break;
277 }
278 thread.setReg(si->destRegIdx(idx), val);
279 }
280
281 bool
282 readPredicate() const override
283 {
284 return thread.readPredicate();
285 }
286
287 void
288 setPredicate(bool val) override
289 {
290 thread.setPredicate(val);
291 }
292
293 bool
294 readMemAccPredicate() const override
295 {
296 return thread.readMemAccPredicate();
297 }
298
299 void
300 setMemAccPredicate(bool val) override
301 {
302 thread.setMemAccPredicate(val);
303 }
304
305 // hardware transactional memory
306 uint64_t
307 getHtmTransactionUid() const override
308 {
309 panic("ExecContext::getHtmTransactionUid() not"
310 "implemented on MinorCPU\n");
311 return 0;
312 }
313
314 uint64_t
315 newHtmTransactionUid() const override
316 {
317 panic("ExecContext::newHtmTransactionUid() not"
318 "implemented on MinorCPU\n");
319 return 0;
320 }
321
322 bool
323 inHtmTransactionalState() const override
324 {
325 // ExecContext::inHtmTransactionalState() not
326 // implemented on MinorCPU
327 return false;
328 }
329
330 uint64_t
332 {
333 panic("ExecContext::getHtmTransactionalDepth() not"
334 "implemented on MinorCPU\n");
335 return 0;
336 }
337
338 const PCStateBase &
339 pcState() const override
340 {
341 return thread.pcState();
342 }
343
344 void
345 pcState(const PCStateBase &val) override
346 {
347 thread.pcState(val);
348 }
349
350 RegVal
352 {
353 return thread.readMiscRegNoEffect(misc_reg);
354 }
355
356 RegVal
357 readMiscReg(int misc_reg) override
358 {
359 return thread.readMiscReg(misc_reg);
360 }
361
362 void
364 {
365 thread.setMiscReg(misc_reg, val);
366 }
367
368 RegVal
369 readMiscRegOperand(const StaticInst *si, int idx) override
370 {
371 const RegId& reg = si->srcRegIdx(idx);
372 assert(reg.is(MiscRegClass));
373 return thread.readMiscReg(reg.index());
374 }
375
376 void
377 setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
378 {
379 const RegId& reg = si->destRegIdx(idx);
380 assert(reg.is(MiscRegClass));
381 return thread.setMiscReg(reg.index(), val);
382 }
383
384 ThreadContext *tcBase() const override { return thread.getTC(); }
385
386 /* @todo, should make stCondFailures persistent somewhere */
387 unsigned int readStCondFailures() const override { return 0; }
388 void setStCondFailures(unsigned int st_cond_failures) override {}
389
390 ContextID contextId() { return thread.contextId(); }
391 /* ISA-specific (or at least currently ISA singleton) functions */
392
393 /* X86: TLB twiddling */
394 void
395 demapPage(Addr vaddr, uint64_t asn) override
396 {
397 thread.getMMUPtr()->demapPage(vaddr, asn);
398 }
399
400 BaseCPU *getCpuPtr() { return &cpu; }
401
402 public:
403 // monitor/mwait funtions
404 void
405 armMonitor(Addr address) override
406 {
407 getCpuPtr()->armMonitor(inst->id.threadId, address);
408 }
409
410 bool
411 mwait(PacketPtr pkt) override
412 {
413 return getCpuPtr()->mwait(inst->id.threadId, pkt);
414 }
415
416 void
418 {
419 return getCpuPtr()->mwaitAtomic(inst->id.threadId, tc, thread.mmu);
420 }
421
423 getAddrMonitor() override
424 {
425 return getCpuPtr()->getCpuAddrMonitor(inst->id.threadId);
426 }
427};
428
429} // namespace minor
430} // namespace gem5
431
432#endif /* __CPU_MINOR_EXEC_CONTEXT_HH__ */
#define DPRINTF(x,...)
Definition trace.hh:209
const char data[]
void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseMMU *mmu)
Definition base.cc:297
AddressMonitor * getCpuAddrMonitor(ThreadID tid)
Definition base.hh:680
bool mwait(ThreadID tid, PacketPtr pkt)
Definition base.cc:274
void armMonitor(ThreadID tid, Addr address)
Definition base.cc:262
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
MinorCPU is an in-order CPU model with four fixed pipeline stages:
Definition cpu.hh:85
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
gem5::Flags< FlagsType > Flags
Definition request.hh:102
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
Base, ISA-independent static instruction class.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
ExecContext(MinorCPU &cpu_, SimpleThread &thread_, Execute &execute_, MinorDynInstPtr inst_)
ThreadContext * tcBase() const override
Returns a pointer to the ThreadContext.
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.
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
const PCStateBase & pcState() const 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.
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
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.
void * getWritableRegOperand(const StaticInst *si, int idx) override
void setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
void mwaitAtomic(ThreadContext *tc) override
SimpleThread & thread
ThreadState object, provides all the architectural state.
bool readPredicate() const override
Execute & execute
The execute stage so we can peek at its contents.
AddressMonitor * getAddrMonitor() override
Execute stage.
Definition execute.hh:68
STL vector class.
Definition stl.hh:37
All the fun of executing instructions from Decode and sending branch/new instruction stream info.
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition amo.hh:269
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
Bitfield< 6 > si
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
RefCountingPtr< MinorDynInst > MinorDynInstPtr
MinorDynInsts are currently reference counted.
Definition dyn_inst.hh:71
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint64_t RegVal
Definition types.hh:173
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Packet * PacketPtr
int ContextID
Globally unique thread context ID.
Definition types.hh:239
constexpr decltype(nullptr) NoFault
Definition types.hh:253
@ VecPredRegClass
Definition reg_class.hh:67
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:62
@ CCRegClass
Condition-code register.
Definition reg_class.hh:69
@ VecRegClass
Vector Register.
Definition reg_class.hh:64
@ IntRegClass
Integer register.
Definition reg_class.hh:61
@ InvalidRegClass
Definition reg_class.hh:71
@ MiscRegClass
Control (misc) register.
Definition reg_class.hh:70
@ VecElemClass
Vector Register Native Elem lane.
Definition reg_class.hh:66
The constructed pipeline.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0