2 * Copyright (c) 2011 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * Authors: Steve Reinhardt
45 #ifndef __CPU_SIMPLE_BASE_HH__
46 #define __CPU_SIMPLE_BASE_HH__
48 #include "arch/predecoder.hh"
49 #include "base/statistics.hh"
50 #include "config/full_system.hh"
51 #include "config/the_isa.hh"
52 #include "config/use_checker.hh"
53 #include "cpu/base.hh"
54 #include "cpu/decode.hh"
55 #include "cpu/pc_event.hh"
56 #include "cpu/simple_thread.hh"
57 #include "cpu/static_inst.hh"
58 #include "mem/packet.hh"
59 #include "mem/port.hh"
60 #include "mem/request.hh"
61 #include "sim/eventq.hh"
62 #include "sim/system.hh"
65 #include "cpu/checker/cpu.hh"
68 // forward declarations
95 class BaseSimpleCPUParams;
98 class BaseSimpleCPU : public BaseCPU
101 typedef TheISA::MiscReg MiscReg;
102 typedef TheISA::FloatReg FloatReg;
103 typedef TheISA::FloatRegBits FloatRegBits;
106 Trace::InstRecord *traceData;
108 inline void checkPcEventQueue() {
109 Addr oldpc, pc = thread->instAddr();
112 system->pcEventQueue.service(tc);
113 pc = thread->instAddr();
114 } while (oldpc != pc);
120 void zero_fill_64(Addr addr) {
121 static int warned = 0;
123 warn ("WH64 is not implemented");
129 BaseSimpleCPU(BaseSimpleCPUParams *params);
130 virtual ~BaseSimpleCPU();
133 /** SimpleThread object, provides all the architectural state. */
134 SimpleThread *thread;
136 /** ThreadContext object, provides an interface for external
137 * objects to modify this thread's state.
166 Addr dbg_vtophys(Addr addr);
171 // current instruction
172 TheISA::MachInst inst;
175 TheISA::Predecoder predecoder;
177 StaticInstPtr curStaticInst;
178 StaticInstPtr curMacroStaticInst;
180 //This is the offset from the current pc that fetch should be performed at
182 //This flag says to stay at the current pc. This is useful for
183 //instructions which go beyond MachInst boundaries.
186 void checkForInterrupts();
187 void setupFetchRequest(Request *req);
190 void advancePC(Fault fault);
192 virtual void deallocateContext(int thread_num);
193 virtual void haltContext(int thread_num);
196 virtual void regStats();
197 virtual void resetStats();
199 // number of simulated instructions
201 Counter startNumInst;
202 Stats::Scalar numInsts;
208 system->totalNumInsts++;
209 thread->funcExeInst++;
212 virtual Counter totalInstructions() const
214 return numInst - startNumInst;
217 //number of integer alu accesses
218 Stats::Scalar numIntAluAccesses;
220 //number of float alu accesses
221 Stats::Scalar numFpAluAccesses;
223 //number of function calls/returns
224 Stats::Scalar numCallsReturns;
226 //conditional control instructions;
227 Stats::Scalar numCondCtrlInsts;
229 //number of int instructions
230 Stats::Scalar numIntInsts;
232 //number of float instructions
233 Stats::Scalar numFpInsts;
235 //number of integer register file accesses
236 Stats::Scalar numIntRegReads;
237 Stats::Scalar numIntRegWrites;
239 //number of float register file accesses
240 Stats::Scalar numFpRegReads;
241 Stats::Scalar numFpRegWrites;
243 // number of simulated memory references
244 Stats::Scalar numMemRefs;
245 Stats::Scalar numLoadInsts;
246 Stats::Scalar numStoreInsts;
248 // number of idle cycles
249 Stats::Formula numIdleCycles;
251 // number of busy cycles
252 Stats::Formula numBusyCycles;
254 // number of simulated loads
256 Counter startNumLoad;
258 // number of idle cycles
259 Stats::Average notIdleFraction;
260 Stats::Formula idleFraction;
262 // number of cycles stalled for I-cache responses
263 Stats::Scalar icacheStallCycles;
264 Counter lastIcacheStall;
266 // number of cycles stalled for I-cache retries
267 Stats::Scalar icacheRetryCycles;
268 Counter lastIcacheRetry;
270 // number of cycles stalled for D-cache responses
271 Stats::Scalar dcacheStallCycles;
272 Counter lastDcacheStall;
274 // number of cycles stalled for D-cache retries
275 Stats::Scalar dcacheRetryCycles;
276 Counter lastDcacheRetry;
278 virtual void serialize(std::ostream &os);
279 virtual void unserialize(Checkpoint *cp, const std::string §ion);
281 // These functions are only used in CPU models that split
282 // effective address computation from the actual memory access.
283 void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); }
284 Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n");
287 // The register accessor methods provide the index of the
288 // instruction's operand (e.g., 0 or 1), not the architectural
289 // register index, to simplify the implementation of register
290 // renaming. We find the architectural register index by indexing
291 // into the instruction's own operand index table. Note that a
292 // raw pointer to the StaticInst is provided instead of a
293 // ref-counted StaticInstPtr to redice overhead. This is fine as
294 // long as these methods don't copy the pointer into any long-term
295 // storage (which is pretty hard to imagine they would have reason
298 uint64_t readIntRegOperand(const StaticInst *si, int idx)
301 return thread->readIntReg(si->srcRegIdx(idx));
304 FloatReg readFloatRegOperand(const StaticInst *si, int idx)
307 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
308 return thread->readFloatReg(reg_idx);
311 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
314 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
315 return thread->readFloatRegBits(reg_idx);
318 void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
321 thread->setIntReg(si->destRegIdx(idx), val);
324 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
327 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
328 thread->setFloatReg(reg_idx, val);
331 void setFloatRegOperandBits(const StaticInst *si, int idx,
335 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
336 thread->setFloatRegBits(reg_idx, val);
339 bool readPredicate() { return thread->readPredicate(); }
340 void setPredicate(bool val)
342 thread->setPredicate(val);
344 traceData->setPredicate(val);
347 TheISA::PCState pcState() { return thread->pcState(); }
348 void pcState(const TheISA::PCState &val) { thread->pcState(val); }
349 Addr instAddr() { return thread->instAddr(); }
350 Addr nextInstAddr() { return thread->nextInstAddr(); }
351 MicroPC microPC() { return thread->microPC(); }
353 MiscReg readMiscRegNoEffect(int misc_reg)
355 return thread->readMiscRegNoEffect(misc_reg);
358 MiscReg readMiscReg(int misc_reg)
361 return thread->readMiscReg(misc_reg);
364 void setMiscReg(int misc_reg, const MiscReg &val)
367 return thread->setMiscReg(misc_reg, val);
370 MiscReg readMiscRegOperand(const StaticInst *si, int idx)
373 int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
374 return thread->readMiscReg(reg_idx);
377 void setMiscRegOperand(
378 const StaticInst *si, int idx, const MiscReg &val)
381 int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
382 return thread->setMiscReg(reg_idx, val);
385 void demapPage(Addr vaddr, uint64_t asn)
387 thread->demapPage(vaddr, asn);
390 void demapInstPage(Addr vaddr, uint64_t asn)
392 thread->demapInstPage(vaddr, asn);
395 void demapDataPage(Addr vaddr, uint64_t asn)
397 thread->demapDataPage(vaddr, asn);
400 unsigned readStCondFailures() {
401 return thread->readStCondFailures();
404 void setStCondFailures(unsigned sc_failures) {
405 thread->setStCondFailures(sc_failures);
408 MiscReg readRegOtherThread(int regIdx, ThreadID tid = InvalidThreadID)
410 panic("Simple CPU models do not support multithreaded "
411 "register access.\n");
414 void setRegOtherThread(int regIdx, const MiscReg &val,
415 ThreadID tid = InvalidThreadID)
417 panic("Simple CPU models do not support multithreaded "
418 "register access.\n");
421 //Fault CacheOp(uint8_t Op, Addr EA);
424 Fault hwrei() { return thread->hwrei(); }
425 bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); }
429 syscall(int64_t callnum)
432 panic("Syscall emulation isn't available in FS mode.\n");
434 thread->syscall(callnum);
438 bool misspeculating() { return thread->misspeculating(); }
439 ThreadContext *tcBase() { return tc; }
442 #endif // __CPU_SIMPLE_BASE_HH__