gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
cpu.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011, 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) 2006 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
42#ifndef __CPU_CHECKER_CPU_HH__
43#define __CPU_CHECKER_CPU_HH__
44
45#include <list>
46#include <map>
47#include <queue>
48
50#include "base/statistics.hh"
51#include "cpu/base.hh"
52#include "cpu/exec_context.hh"
53#include "cpu/inst_res.hh"
54#include "cpu/pc_event.hh"
55#include "cpu/simple_thread.hh"
56#include "cpu/static_inst.hh"
57#include "debug/Checker.hh"
58#include "mem/request.hh"
59#include "params/CheckerCPU.hh"
60#include "sim/eventq.hh"
61
62namespace gem5
63{
64
65class ThreadContext;
66class Request;
67
84class CheckerCPU : public BaseCPU, public ExecContext
85{
86 protected:
89
90 public:
91 void init() override;
92
94 CheckerCPU(const Params &p);
95 virtual ~CheckerCPU();
96
97 void setSystem(System *system);
98
99 void setIcachePort(RequestPort *icache_port);
100
101 void setDcachePort(RequestPort *dcache_port);
102
103 Port &
104 getDataPort() override
105 {
106 // the checker does not have ports on its own so return the
107 // data port of the actual CPU core
108 assert(dcachePort);
109 return *dcachePort;
110 }
111
112 Port &
113 getInstPort() override
114 {
115 // the checker does not have ports on its own so return the
116 // data port of the actual CPU core
117 assert(icachePort);
118 return *icachePort;
119 }
120
121 protected:
122
124
126
129
131
133
134 // ISAs like ARM can have multiple destination registers to check,
135 // keep them all in a std::queue
136 std::queue<InstResult> result;
137
140
141 // number of simulated instructions
144
145 std::queue<int> miscRegIdxs;
146
147 public:
148
149 // Primary thread being run.
151
152 BaseMMU* getMMUPtr() { return mmu; }
153
154 virtual Counter totalInsts() const override { return 0; }
155
156 virtual Counter totalOps() const override { return 0; }
157
158 // number of simulated loads
161
162 void serialize(CheckpointOut &cp) const override;
163 void unserialize(CheckpointIn &cp) override;
164
165 // The register accessor methods provide the index of the
166 // instruction's operand (e.g., 0 or 1), not the architectural
167 // register index, to simplify the implementation of register
168 // renaming. We find the architectural register index by indexing
169 // into the instruction's own operand index table. Note that a
170 // raw pointer to the StaticInst is provided instead of a
171 // ref-counted StaticInstPtr to redice overhead. This is fine as
172 // long as these methods don't copy the pointer into any long-term
173 // storage (which is pretty hard to imagine they would have reason
174 // to do).
175
176 RegVal
177 getRegOperand(const StaticInst *si, int idx) override
178 {
179 const RegId& id = si->srcRegIdx(idx);
180 if (id.is(InvalidRegClass))
181 return 0;
182 return thread->getReg(id);
183 }
184
185 void
186 getRegOperand(const StaticInst *si, int idx, void *val) override
187 {
188 thread->getReg(si->srcRegIdx(idx), val);
189 }
190
191 void *
192 getWritableRegOperand(const StaticInst *si, int idx) override
193 {
194 return thread->getWritableReg(si->destRegIdx(idx));
195 }
196
197 void
198 setRegOperand(const StaticInst *si, int idx, RegVal val) override
199 {
200 const RegId& id = si->destRegIdx(idx);
201 if (id.is(InvalidRegClass))
202 return;
203 const RegId flat = id.flatten(*thread->getIsaPtr());
204 thread->setReg(flat, val);
205 result.emplace(flat.regClass(), val);
206 }
207
208 void
209 setRegOperand(const StaticInst *si, int idx, const void *val) override
210 {
211 const RegId& id = si->destRegIdx(idx);
212 if (id.is(InvalidRegClass))
213 return;
214 const RegId flat = id.flatten(*thread->getIsaPtr());
215 thread->setReg(flat, val);
216 result.emplace(flat.regClass(), val);
217 }
218
219 bool readPredicate() const override { return thread->readPredicate(); }
220
221 void
222 setPredicate(bool val) override
223 {
224 thread->setPredicate(val);
225 }
226
227 bool
228 readMemAccPredicate() const override
229 {
230 return thread->readMemAccPredicate();
231 }
232
233 void
234 setMemAccPredicate(bool val) override
235 {
236 thread->setMemAccPredicate(val);
237 }
238
239 uint64_t
240 getHtmTransactionUid() const override
241 {
242 panic("not yet supported!");
243 return 0;
244 };
245
246 uint64_t
247 newHtmTransactionUid() const override
248 {
249 panic("not yet supported!");
250 return 0;
251 };
252
253 Fault
255 {
256 panic("not yet supported!");
257 return NoFault;
258 }
259
260 bool
261 inHtmTransactionalState() const override
262 {
263 return (getHtmTransactionalDepth() > 0);
264 }
265
266 uint64_t
268 {
269 assert(thread->htmTransactionStarts >= thread->htmTransactionStops);
270 return (thread->htmTransactionStarts - thread->htmTransactionStops);
271 }
272
273 const PCStateBase &
274 pcState() const override
275 {
276 return thread->pcState();
277 }
278 void
279 pcState(const PCStateBase &val) override
280 {
281 DPRINTF(Checker, "Changing PC to %s, old PC %s.\n",
282 val, thread->pcState());
283 thread->pcState(val);
284 }
285
286
287 RegVal
289 {
290 return thread->readMiscRegNoEffect(misc_reg);
291 }
292
293 RegVal
294 readMiscReg(int misc_reg) override
295 {
296 return thread->readMiscReg(misc_reg);
297 }
298
299 void
301 {
302 DPRINTF(Checker, "Setting misc reg %d with no effect to check later\n",
303 misc_reg);
304 miscRegIdxs.push(misc_reg);
305 return thread->setMiscRegNoEffect(misc_reg, val);
306 }
307
308 void
310 {
311 DPRINTF(Checker, "Setting misc reg %d with effect to check later\n",
312 misc_reg);
313 miscRegIdxs.push(misc_reg);
314 return thread->setMiscReg(misc_reg, val);
315 }
316
317 RegVal
318 readMiscRegOperand(const StaticInst *si, int idx) override
319 {
320 const RegId& reg = si->srcRegIdx(idx);
321 assert(reg.is(MiscRegClass));
322 return thread->readMiscReg(reg.index());
323 }
324
325 void
326 setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
327 {
328 const RegId& reg = si->destRegIdx(idx);
329 assert(reg.is(MiscRegClass));
330 return this->setMiscReg(reg.index(), val);
331 }
332
334
335 void
337 {
338 changedPC = true;
340 }
341
342 void
343 demapPage(Addr vaddr, uint64_t asn) override
344 {
345 mmu->demapPage(vaddr, asn);
346 }
347
348 // monitor/mwait funtions
349 void armMonitor(Addr address) override { BaseCPU::armMonitor(0, address); }
350 bool mwait(PacketPtr pkt) override { return BaseCPU::mwait(0, pkt); }
351
352 void
354 {
355 return BaseCPU::mwaitAtomic(0, tc, thread->mmu);
356 }
357
359 getAddrMonitor() override
360 {
362 }
363
380 RequestPtr genMemFragmentRequest(Addr frag_addr, int size,
381 Request::Flags flags,
382 const std::vector<bool>& byte_enable,
383 int& frag_size, int& size_left) const;
384
385 Fault readMem(Addr addr, uint8_t *data, unsigned size,
386 Request::Flags flags,
387 const std::vector<bool>& byte_enable) override;
388
389 Fault writeMem(uint8_t *data, unsigned size, Addr addr,
390 Request::Flags flags, uint64_t *res,
391 const std::vector<bool>& byte_enable) override;
392
393 Fault
394 amoMem(Addr addr, uint8_t* data, unsigned size,
395 Request::Flags flags, AtomicOpFunctorPtr amo_op) override
396 {
397 panic("AMO is not supported yet in CPU checker\n");
398 }
399
400 unsigned int
401 readStCondFailures() const override
402 {
403 return thread->readStCondFailures();
404 }
405
406 void setStCondFailures(unsigned int sc_failures) override {}
408
409 void wakeup(ThreadID tid) override { }
410
411 void
413 {
414 if (exitOnError)
415 dumpAndExit();
416 }
417
418 bool checkFlags(const RequestPtr &unverified_req, Addr vAddr,
419 Addr pAddr, int flags);
420
421 void dumpAndExit();
422
423 ThreadContext *tcBase() const override { return tc; }
425
429
432 std::unique_ptr<PCStateBase> newPCState;
436
438};
439
446template <class DynInstPtr>
447class Checker : public CheckerCPU
448{
449 public:
452 { }
453
454 void switchOut();
455 void takeOverFrom(BaseCPU *oldCPU);
456
457 void advancePC(const Fault &fault);
458
459 void verify(const DynInstPtr &inst);
460
461 void validateInst(const DynInstPtr &inst);
462 void validateExecution(const DynInstPtr &inst);
463 void validateState();
464
465 void copyResult(const DynInstPtr &inst, const InstResult& mismatch_val,
466 int start_idx);
467 void handlePendingInt();
468
469 private:
470 void
471 handleError(const DynInstPtr &inst)
472 {
473 if (exitOnError) {
474 dumpAndExit(inst);
475 } else if (updateOnError) {
476 updateThisCycle = true;
477 }
478 }
479
480 void dumpAndExit(const DynInstPtr &inst);
481
483
484 DynInstPtr unverifiedInst;
485
488 void dumpInsts();
489};
490
491} // namespace gem5
492
493#endif // __CPU_CHECKER_CPU_HH__
#define DPRINTF(x,...)
Definition trace.hh:209
const char data[]
System * system
Definition base.hh:419
void mwaitAtomic(ThreadID tid, ThreadContext *tc, BaseMMU *mmu)
Definition base.cc:287
AddressMonitor * getCpuAddrMonitor(ThreadID tid)
Definition base.hh:683
bool mwait(ThreadID tid, PacketPtr pkt)
Definition base.cc:264
void armMonitor(ThreadID tid, Addr address)
Definition base.cc:252
BaseCPU(const Params &params, bool is_checker=false)
Definition base.cc:129
void demapPage(Addr vaddr, uint64_t asn) override
Invalidate a page in the DTLB and ITLB.
Definition cpu.hh:343
uint64_t newHtmTransactionUid() const override
Definition cpu.hh:247
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition cpu.cc:59
unsigned int readStCondFailures() const override
Returns the number of consecutive store conditional failures.
Definition cpu.hh:401
uint64_t getHtmTransactionalDepth() const override
Definition cpu.hh:267
void recordPCChange(const PCStateBase &val)
Definition cpu.hh:336
void setMiscReg(int misc_reg, RegVal val) override
Sets a miscellaneous register, handling any architectural side effects due to writing that register.
Definition cpu.hh:309
Fault readMem(Addr addr, uint8_t *data, unsigned size, Request::Flags flags, const std::vector< bool > &byte_enable) override
Definition cpu.cc:167
virtual Counter totalOps() const override
Definition cpu.hh:156
RegVal readMiscRegOperand(const StaticInst *si, int idx) override
Definition cpu.hh:318
Counter numInst
Definition cpu.hh:142
RequestPort * icachePort
Definition cpu.hh:127
void setStCondFailures(unsigned int sc_failures) override
Sets the number of consecutive store conditional failures.
Definition cpu.hh:406
InstResult unverifiedResult
Definition cpu.hh:426
StaticInstPtr curStaticInst
Definition cpu.hh:138
Counter numLoad
Definition cpu.hh:159
bool updateOnError
Definition cpu.hh:434
void serialize(CheckpointOut &cp) const override
Serialize this object to the given output stream.
Definition cpu.cc:130
std::queue< int > miscRegIdxs
Definition cpu.hh:145
std::unique_ptr< PCStateBase > newPCState
Definition cpu.hh:432
bool exitOnError
Definition cpu.hh:433
std::queue< InstResult > result
Definition cpu.hh:136
void setIcachePort(RequestPort *icache_port)
Definition cpu.cc:118
bool willChangePC
Definition cpu.hh:431
CheckerCPU(const Params &p)
Definition cpu.cc:65
void setSystem(System *system)
Definition cpu.cc:96
RegVal getRegOperand(const StaticInst *si, int idx) override
Definition cpu.hh:177
uint64_t getHtmTransactionUid() const override
Definition cpu.hh:240
ThreadContext * tc
Definition cpu.hh:130
const PCStateBase & pcState() const override
Definition cpu.hh:274
std::vector< Process * > workload
Definition cpu.hh:123
PARAMS(CheckerCPU)
void pcState(const PCStateBase &val) override
Definition cpu.hh:279
SimpleThread * thread
Definition cpu.hh:150
void setRegOperand(const StaticInst *si, int idx, RegVal val) override
Definition cpu.hh:198
Port & getDataPort() override
Purely virtual method that returns a reference to the data port.
Definition cpu.hh:104
bool warnOnlyOnLoadError
Definition cpu.hh:435
Fault initiateMemMgmtCmd(Request::Flags flags) override
Initiate a memory management command with no valid address.
Definition cpu.hh:254
void armMonitor(Addr address) override
Definition cpu.hh:349
Fault writeMem(uint8_t *data, unsigned size, Addr addr, Request::Flags flags, uint64_t *res, const std::vector< bool > &byte_enable) override
Definition cpu.cc:251
Counter startNumLoad
Definition cpu.hh:160
RegVal readMiscRegNoEffect(int misc_reg) const
Definition cpu.hh:288
RequestPort * dcachePort
Definition cpu.hh:128
void setPredicate(bool val) override
Definition cpu.hh:222
virtual Counter totalInsts() const override
Definition cpu.hh:154
void handleError()
Definition cpu.hh:412
void wakeup(ThreadID tid) override
Definition cpu.hh:409
RegVal readMiscReg(int misc_reg) override
Reads a miscellaneous register, handling any architectural side effects due to reading that register.
Definition cpu.hh:294
void setMemAccPredicate(bool val) override
Definition cpu.hh:234
SimpleThread * threadBase()
Definition cpu.hh:424
RequestorID requestorId
id attached to all issued requests
Definition cpu.hh:88
bool readPredicate() const override
Definition cpu.hh:219
void setMiscRegNoEffect(int misc_reg, RegVal val)
Definition cpu.hh:300
void unserialize(CheckpointIn &cp) override
Reconstruct the state of this object from a checkpoint.
Definition cpu.cc:135
bool changedPC
Definition cpu.hh:430
bool checkFlags(const RequestPtr &unverified_req, Addr vAddr, Addr pAddr, int flags)
Checks if the flags set by the Checker and Checkee match.
Definition cpu.cc:356
System * systemPtr
Definition cpu.hh:125
void setMiscRegOperand(const StaticInst *si, int idx, RegVal val) override
Definition cpu.hh:326
bool inHtmTransactionalState() const override
Definition cpu.hh:261
void setRegOperand(const StaticInst *si, int idx, const void *val) override
Definition cpu.hh:209
uint8_t * unverifiedMemData
Definition cpu.hh:428
InstSeqNum youngestSN
Definition cpu.hh:437
Port & getInstPort() override
Purely virtual method that returns a reference to the instruction port.
Definition cpu.hh:113
bool readMemAccPredicate() const override
Definition cpu.hh:228
RequestPtr genMemFragmentRequest(Addr frag_addr, int size, Request::Flags flags, const std::vector< bool > &byte_enable, int &frag_size, int &size_left) const
Helper function used to generate the request for a single fragment of a memory access.
Definition cpu.cc:140
ThreadContext * tcBase() const override
Returns a pointer to the ThreadContext.
Definition cpu.hh:423
Fault amoMem(Addr addr, uint8_t *data, unsigned size, Request::Flags flags, AtomicOpFunctorPtr amo_op) override
Definition cpu.hh:394
void mwaitAtomic(ThreadContext *tc) override
Definition cpu.hh:353
bool mwait(PacketPtr pkt) override
Definition cpu.hh:350
BaseMMU * mmu
Definition cpu.hh:132
void dumpAndExit()
Definition cpu.cc:373
AddressMonitor * getAddrMonitor() override
Definition cpu.hh:359
RequestPtr unverifiedReq
Definition cpu.hh:427
void getRegOperand(const StaticInst *si, int idx, void *val) override
Definition cpu.hh:186
void setDcachePort(RequestPort *dcache_port)
Definition cpu.cc:124
Counter startNumInst
Definition cpu.hh:143
BaseMMU * getMMUPtr()
Definition cpu.hh:152
StaticInstPtr curMacroStaticInst
Definition cpu.hh:139
void * getWritableRegOperand(const StaticInst *si, int idx) override
Definition cpu.hh:192
virtual ~CheckerCPU()
Definition cpu.cc:91
Templated Checker class.
Definition cpu.hh:448
void validateState()
Definition cpu_impl.hh:544
void validateExecution(const DynInstPtr &inst)
Definition cpu_impl.hh:462
Checker(const Params &p)
Definition cpu.hh:450
DynInstPtr unverifiedInst
Definition cpu.hh:484
void verify(const DynInstPtr &inst)
Definition cpu_impl.hh:119
void validateInst(const DynInstPtr &inst)
Definition cpu_impl.hh:441
std::list< DynInstPtr > instList
Definition cpu.hh:486
void advancePC(const Fault &fault)
Definition cpu_impl.hh:66
void copyResult(const DynInstPtr &inst, const InstResult &mismatch_val, int start_idx)
Definition cpu_impl.hh:570
void handlePendingInt()
Definition cpu_impl.hh:85
void handleError(const DynInstPtr &inst)
Definition cpu.hh:471
void dumpInsts()
Definition cpu_impl.hh:621
void switchOut()
Prepare for another CPU to take over execution.
Definition cpu_impl.hh:431
bool updateThisCycle
Definition cpu.hh:482
std::list< DynInstPtr >::iterator InstListIt
Definition cpu.hh:487
void takeOverFrom(BaseCPU *oldCPU)
Load the state of a CPU from the previous CPU object, invoked on all new CPUs that are about to be sw...
Definition cpu_impl.hh:437
ClockedObjectParams Params
Parameters of ClockedObject.
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Ports are used to interface objects to each other.
Definition port.hh:62
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
constexpr const RegClass & regClass() const
Class accessor.
Definition reg_class.hh:154
constexpr RegIndex index() const
Index accessors.
Definition reg_class.hh:151
RegId flatten(const BaseISA &isa) const
Definition reg_class.hh:285
A RequestPort is a specialisation of a Port, which implements the default protocol for the three diff...
Definition port.hh:136
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.
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
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< 12, 11 > set
Bitfield< 24, 22 > is
Bitfield< 0 > p
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
double Counter
All counters are of 64-bit values.
Definition types.hh:46
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
int16_t ThreadID
Thread index/ID type.
Definition types.hh:235
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
uint64_t RegVal
Definition types.hh:173
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint16_t RequestorID
Definition request.hh:95
Packet * PacketPtr
RefCountingPtr< StaticInst > StaticInstPtr
constexpr decltype(nullptr) NoFault
Definition types.hh:253
uint64_t InstSeqNum
Definition inst_seq.hh:40
@ InvalidRegClass
Definition reg_class.hh:71
@ MiscRegClass
Control (misc) register.
Definition reg_class.hh:70
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Declaration of Statistics objects.

Generated on Mon May 26 2025 09:19:07 for gem5 by doxygen 1.13.2