2 * Copyright (c) 2011-2012 ARM Limited
3 * Copyright (c) 2013 Advanced Micro Devices, Inc.
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.
15 * Copyright (c) 2002-2005 The Regents of The University of Michigan
16 * All rights reserved.
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.
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.
41 * Authors: Steve Reinhardt
46 #ifndef __CPU_SIMPLE_BASE_HH__
47 #define __CPU_SIMPLE_BASE_HH__
49 #include "base/statistics.hh"
50 #include "config/the_isa.hh"
51 #include "cpu/base.hh"
52 #include "cpu/checker/cpu.hh"
53 #include "cpu/pc_event.hh"
54 #include "cpu/simple_thread.hh"
55 #include "cpu/static_inst.hh"
56 #include "mem/packet.hh"
57 #include "mem/port.hh"
58 #include "mem/request.hh"
59 #include "sim/eventq.hh"
60 #include "sim/full_system.hh"
61 #include "sim/system.hh"
63 // forward declarations
79 struct BaseSimpleCPUParams;
82 class BaseSimpleCPU : public BaseCPU
85 typedef TheISA::MiscReg MiscReg;
86 typedef TheISA::FloatReg FloatReg;
87 typedef TheISA::FloatRegBits FloatRegBits;
88 typedef TheISA::CCReg CCReg;
90 BPredUnit *branchPred;
93 Trace::InstRecord *traceData;
95 inline void checkPcEventQueue() {
96 Addr oldpc, pc = thread->instAddr();
99 system->pcEventQueue.service(tc);
100 pc = thread->instAddr();
101 } while (oldpc != pc);
107 void zero_fill_64(Addr addr) {
108 static int warned = 0;
110 warn ("WH64 is not implemented");
116 BaseSimpleCPU(BaseSimpleCPUParams *params);
117 virtual ~BaseSimpleCPU();
120 /** SimpleThread object, provides all the architectural state. */
121 SimpleThread *thread;
123 /** ThreadContext object, provides an interface for external
124 * objects to modify this thread's state.
150 Addr dbg_vtophys(Addr addr);
154 // current instruction
155 TheISA::MachInst inst;
157 StaticInstPtr curStaticInst;
158 StaticInstPtr curMacroStaticInst;
160 //This is the offset from the current pc that fetch should be performed at
162 //This flag says to stay at the current pc. This is useful for
163 //instructions which go beyond MachInst boundaries.
166 void checkForInterrupts();
167 void setupFetchRequest(Request *req);
170 void advancePC(Fault fault);
172 virtual void deallocateContext(ThreadID thread_num);
173 virtual void haltContext(ThreadID thread_num);
176 virtual void regStats();
177 virtual void resetStats();
179 virtual void startup();
181 // number of simulated instructions
183 Counter startNumInst;
184 Stats::Scalar numInsts;
187 Stats::Scalar numOps;
191 if (!curStaticInst->isMicroop() || curStaticInst->isLastMicroop()) {
198 system->totalNumInsts++;
199 thread->funcExeInst++;
202 virtual Counter totalInsts() const
204 return numInst - startNumInst;
207 virtual Counter totalOps() const
209 return numOp - startNumOp;
212 //number of integer alu accesses
213 Stats::Scalar numIntAluAccesses;
215 //number of float alu accesses
216 Stats::Scalar numFpAluAccesses;
218 //number of function calls/returns
219 Stats::Scalar numCallsReturns;
221 //conditional control instructions;
222 Stats::Scalar numCondCtrlInsts;
224 //number of int instructions
225 Stats::Scalar numIntInsts;
227 //number of float instructions
228 Stats::Scalar numFpInsts;
230 //number of integer register file accesses
231 Stats::Scalar numIntRegReads;
232 Stats::Scalar numIntRegWrites;
234 //number of float register file accesses
235 Stats::Scalar numFpRegReads;
236 Stats::Scalar numFpRegWrites;
238 //number of condition code register file accesses
239 Stats::Scalar numCCRegReads;
240 Stats::Scalar numCCRegWrites;
242 // number of simulated memory references
243 Stats::Scalar numMemRefs;
244 Stats::Scalar numLoadInsts;
245 Stats::Scalar numStoreInsts;
247 // number of idle cycles
248 Stats::Formula numIdleCycles;
250 // number of busy cycles
251 Stats::Formula numBusyCycles;
253 // number of simulated loads
255 Counter startNumLoad;
257 // number of idle cycles
258 Stats::Average notIdleFraction;
259 Stats::Formula idleFraction;
261 // number of cycles stalled for I-cache responses
262 Stats::Scalar icacheStallCycles;
263 Counter lastIcacheStall;
265 // number of cycles stalled for I-cache retries
266 Stats::Scalar icacheRetryCycles;
267 Counter lastIcacheRetry;
269 // number of cycles stalled for D-cache responses
270 Stats::Scalar dcacheStallCycles;
271 Counter lastDcacheStall;
273 // number of cycles stalled for D-cache retries
274 Stats::Scalar dcacheRetryCycles;
275 Counter lastDcacheRetry;
278 /// Total number of branches fetched
279 Stats::Scalar numBranches;
280 /// Number of branches predicted as taken
281 Stats::Scalar numPredictedBranches;
282 /// Number of misprediced branches
283 Stats::Scalar numBranchMispred;
286 void serializeThread(std::ostream &os, ThreadID tid);
287 void unserializeThread(Checkpoint *cp, const std::string §ion,
290 // These functions are only used in CPU models that split
291 // effective address computation from the actual memory access.
292 void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); }
293 Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n");
296 // The register accessor methods provide the index of the
297 // instruction's operand (e.g., 0 or 1), not the architectural
298 // register index, to simplify the implementation of register
299 // renaming. We find the architectural register index by indexing
300 // into the instruction's own operand index table. Note that a
301 // raw pointer to the StaticInst is provided instead of a
302 // ref-counted StaticInstPtr to redice overhead. This is fine as
303 // long as these methods don't copy the pointer into any long-term
304 // storage (which is pretty hard to imagine they would have reason
307 uint64_t readIntRegOperand(const StaticInst *si, int idx)
310 return thread->readIntReg(si->srcRegIdx(idx));
313 FloatReg readFloatRegOperand(const StaticInst *si, int idx)
316 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
317 return thread->readFloatReg(reg_idx);
320 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
323 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
324 return thread->readFloatRegBits(reg_idx);
327 CCReg readCCRegOperand(const StaticInst *si, int idx)
330 int reg_idx = si->srcRegIdx(idx) - TheISA::CC_Reg_Base;
331 return thread->readCCReg(reg_idx);
334 void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
337 thread->setIntReg(si->destRegIdx(idx), val);
340 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
343 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
344 thread->setFloatReg(reg_idx, val);
347 void setFloatRegOperandBits(const StaticInst *si, int idx,
351 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
352 thread->setFloatRegBits(reg_idx, val);
355 void setCCRegOperand(const StaticInst *si, int idx, CCReg val)
358 int reg_idx = si->destRegIdx(idx) - TheISA::CC_Reg_Base;
359 thread->setCCReg(reg_idx, val);
362 bool readPredicate() { return thread->readPredicate(); }
363 void setPredicate(bool val)
365 thread->setPredicate(val);
367 traceData->setPredicate(val);
370 TheISA::PCState pcState() { return thread->pcState(); }
371 void pcState(const TheISA::PCState &val) { thread->pcState(val); }
372 Addr instAddr() { return thread->instAddr(); }
373 Addr nextInstAddr() { return thread->nextInstAddr(); }
374 MicroPC microPC() { return thread->microPC(); }
376 MiscReg readMiscRegNoEffect(int misc_reg)
378 return thread->readMiscRegNoEffect(misc_reg);
381 MiscReg readMiscReg(int misc_reg)
384 return thread->readMiscReg(misc_reg);
387 void setMiscReg(int misc_reg, const MiscReg &val)
390 return thread->setMiscReg(misc_reg, val);
393 MiscReg readMiscRegOperand(const StaticInst *si, int idx)
396 int reg_idx = si->srcRegIdx(idx) - TheISA::Misc_Reg_Base;
397 return thread->readMiscReg(reg_idx);
400 void setMiscRegOperand(
401 const StaticInst *si, int idx, const MiscReg &val)
404 int reg_idx = si->destRegIdx(idx) - TheISA::Misc_Reg_Base;
405 return thread->setMiscReg(reg_idx, val);
408 void demapPage(Addr vaddr, uint64_t asn)
410 thread->demapPage(vaddr, asn);
413 void demapInstPage(Addr vaddr, uint64_t asn)
415 thread->demapInstPage(vaddr, asn);
418 void demapDataPage(Addr vaddr, uint64_t asn)
420 thread->demapDataPage(vaddr, asn);
423 unsigned readStCondFailures() {
424 return thread->readStCondFailures();
427 void setStCondFailures(unsigned sc_failures) {
428 thread->setStCondFailures(sc_failures);
431 MiscReg readRegOtherThread(int regIdx, ThreadID tid = InvalidThreadID)
433 panic("Simple CPU models do not support multithreaded "
434 "register access.\n");
437 void setRegOtherThread(int regIdx, const MiscReg &val,
438 ThreadID tid = InvalidThreadID)
440 panic("Simple CPU models do not support multithreaded "
441 "register access.\n");
444 //Fault CacheOp(uint8_t Op, Addr EA);
446 Fault hwrei() { return thread->hwrei(); }
447 bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); }
450 syscall(int64_t callnum)
453 panic("Syscall emulation isn't available in FS mode.\n");
455 thread->syscall(callnum);
458 bool misspeculating() { return thread->misspeculating(); }
459 ThreadContext *tcBase() { return tc; }
462 TheISA::PCState pred_pc;
465 #endif // __CPU_SIMPLE_BASE_HH__