2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Steve Reinhardt
33 #ifndef __CPU_SIMPLE_BASE_HH__
34 #define __CPU_SIMPLE_BASE_HH__
36 #include "arch/predecoder.hh"
37 #include "base/statistics.hh"
38 #include "config/full_system.hh"
39 #include "cpu/base.hh"
40 #include "cpu/simple_thread.hh"
41 #include "cpu/pc_event.hh"
42 #include "cpu/static_inst.hh"
43 #include "mem/packet.hh"
44 #include "mem/port.hh"
45 #include "mem/request.hh"
46 #include "sim/eventq.hh"
48 // forward declarations
79 class BaseSimpleCPU : public BaseCPU
82 typedef TheISA::MiscReg MiscReg;
83 typedef TheISA::FloatReg FloatReg;
84 typedef TheISA::FloatRegBits FloatRegBits;
87 Trace::InstRecord *traceData;
90 void post_interrupt(int int_num, int index);
92 void zero_fill_64(Addr addr) {
93 static int warned = 0;
95 warn ("WH64 is not implemented");
101 struct Params : public BaseCPU::Params
110 BaseSimpleCPU(Params *params);
111 virtual ~BaseSimpleCPU();
114 /** SimpleThread object, provides all the architectural state. */
115 SimpleThread *thread;
117 /** ThreadContext object, provides an interface for external
118 * objects to modify this thread's state.
123 Addr dbg_vtophys(Addr addr);
128 // current instruction
129 TheISA::MachInst inst;
132 TheISA::Predecoder predecoder;
134 StaticInstPtr curStaticInst;
135 StaticInstPtr curMacroStaticInst;
137 //This is the offset from the current pc that fetch should be performed at
139 //This flag says to stay at the current pc. This is useful for
140 //instructions which go beyond MachInst boundaries.
143 void checkForInterrupts();
144 Fault setupFetchRequest(Request *req);
147 void advancePC(Fault fault);
149 virtual void deallocateContext(int thread_num);
150 virtual void haltContext(int thread_num);
153 virtual void regStats();
154 virtual void resetStats();
156 // number of simulated instructions
158 Counter startNumInst;
159 Stats::Scalar<> numInsts;
161 virtual Counter totalInstructions() const
163 return numInst - startNumInst;
166 // Mask to align PCs to MachInst sized boundaries
167 static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1);
169 // number of simulated memory references
170 Stats::Scalar<> numMemRefs;
172 // number of simulated loads
174 Counter startNumLoad;
176 // number of idle cycles
177 Stats::Average<> notIdleFraction;
178 Stats::Formula idleFraction;
180 // number of cycles stalled for I-cache responses
181 Stats::Scalar<> icacheStallCycles;
182 Counter lastIcacheStall;
184 // number of cycles stalled for I-cache retries
185 Stats::Scalar<> icacheRetryCycles;
186 Counter lastIcacheRetry;
188 // number of cycles stalled for D-cache responses
189 Stats::Scalar<> dcacheStallCycles;
190 Counter lastDcacheStall;
192 // number of cycles stalled for D-cache retries
193 Stats::Scalar<> dcacheRetryCycles;
194 Counter lastDcacheRetry;
196 virtual void serialize(std::ostream &os);
197 virtual void unserialize(Checkpoint *cp, const std::string §ion);
199 // These functions are only used in CPU models that split
200 // effective address computation from the actual memory access.
201 void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); }
202 Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n");
205 void prefetch(Addr addr, unsigned flags)
207 // need to do this...
210 void writeHint(Addr addr, int size, unsigned flags)
212 // need to do this...
216 Fault copySrcTranslate(Addr src);
218 Fault copy(Addr dest);
220 // The register accessor methods provide the index of the
221 // instruction's operand (e.g., 0 or 1), not the architectural
222 // register index, to simplify the implementation of register
223 // renaming. We find the architectural register index by indexing
224 // into the instruction's own operand index table. Note that a
225 // raw pointer to the StaticInst is provided instead of a
226 // ref-counted StaticInstPtr to redice overhead. This is fine as
227 // long as these methods don't copy the pointer into any long-term
228 // storage (which is pretty hard to imagine they would have reason
231 uint64_t readIntRegOperand(const StaticInst *si, int idx)
233 return thread->readIntReg(si->srcRegIdx(idx));
236 FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width)
238 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
239 return thread->readFloatReg(reg_idx, width);
242 FloatReg readFloatRegOperand(const StaticInst *si, int idx)
244 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
245 return thread->readFloatReg(reg_idx);
248 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
251 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
252 return thread->readFloatRegBits(reg_idx, width);
255 FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
257 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
258 return thread->readFloatRegBits(reg_idx);
261 void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
263 thread->setIntReg(si->destRegIdx(idx), val);
266 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
269 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
270 thread->setFloatReg(reg_idx, val, width);
273 void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
275 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
276 thread->setFloatReg(reg_idx, val);
279 void setFloatRegOperandBits(const StaticInst *si, int idx,
280 FloatRegBits val, int width)
282 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
283 thread->setFloatRegBits(reg_idx, val, width);
286 void setFloatRegOperandBits(const StaticInst *si, int idx,
289 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
290 thread->setFloatRegBits(reg_idx, val);
293 uint64_t readPC() { return thread->readPC(); }
294 uint64_t readNextPC() { return thread->readNextPC(); }
295 uint64_t readNextNPC() { return thread->readNextNPC(); }
297 void setPC(uint64_t val) { thread->setPC(val); }
298 void setNextPC(uint64_t val) { thread->setNextPC(val); }
299 void setNextNPC(uint64_t val) { thread->setNextNPC(val); }
301 MiscReg readMiscRegNoEffect(int misc_reg)
303 return thread->readMiscRegNoEffect(misc_reg);
306 MiscReg readMiscReg(int misc_reg)
308 return thread->readMiscReg(misc_reg);
311 void setMiscRegNoEffect(int misc_reg, const MiscReg &val)
313 return thread->setMiscRegNoEffect(misc_reg, val);
316 void setMiscReg(int misc_reg, const MiscReg &val)
318 return thread->setMiscReg(misc_reg, val);
321 MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx)
323 int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
324 return thread->readMiscRegNoEffect(reg_idx);
327 MiscReg readMiscRegOperand(const StaticInst *si, int idx)
329 int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
330 return thread->readMiscReg(reg_idx);
333 void setMiscRegOperandNoEffect(const StaticInst *si, int idx, const MiscReg &val)
335 int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
336 return thread->setMiscRegNoEffect(reg_idx, val);
339 void setMiscRegOperand(
340 const StaticInst *si, int idx, const MiscReg &val)
342 int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
343 return thread->setMiscReg(reg_idx, val);
346 unsigned readStCondFailures() {
347 return thread->readStCondFailures();
350 void setStCondFailures(unsigned sc_failures) {
351 thread->setStCondFailures(sc_failures);
354 MiscReg readRegOtherThread(int regIdx, int tid = -1)
356 panic("Simple CPU models do not support multithreaded "
357 "register access.\n");
360 void setRegOtherThread(int regIdx, const MiscReg &val, int tid = -1)
362 panic("Simple CPU models do not support multithreaded "
363 "register access.\n");
367 Fault hwrei() { return thread->hwrei(); }
368 void ev5_trap(Fault fault) { fault->invoke(tc); }
369 bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); }
371 void syscall(int64_t callnum) { thread->syscall(callnum); }
374 bool misspeculating() { return thread->misspeculating(); }
375 ThreadContext *tcBase() { return tc; }
378 #endif // __CPU_SIMPLE_BASE_HH__