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 "base/statistics.hh"
37 #include "config/full_system.hh"
38 #include "cpu/base.hh"
39 #include "cpu/cpu_exec_context.hh"
40 #include "cpu/pc_event.hh"
41 #include "cpu/sampler/sampler.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
72 class BaseSimpleCPU : public BaseCPU
75 typedef TheISA::MachInst MachInst;
76 typedef TheISA::MiscReg MiscReg;
77 typedef TheISA::FloatReg FloatReg;
78 typedef TheISA::FloatRegBits FloatRegBits;
83 Trace::InstRecord *traceData;
86 void post_interrupt(int int_num, int index);
88 void zero_fill_64(Addr addr) {
89 static int warned = 0;
91 warn ("WH64 is not implemented");
97 struct Params : public BaseCPU::Params
107 BaseSimpleCPU(Params *params);
108 virtual ~BaseSimpleCPU();
112 CPUExecContext *cpuXC;
117 Addr dbg_vtophys(Addr addr);
122 // current instruction
125 // Static data storage
126 TheISA::IntReg dataReg;
128 // Pointer to the sampler that is telling us to switchover.
129 // Used to signal the completion of the pipe drain and schedule
130 // the next switchover
133 StaticInstPtr curStaticInst;
135 void checkForInterrupts();
136 Fault setupFetchRequest(Request *req);
139 void advancePC(Fault fault);
141 virtual void deallocateContext(int thread_num);
142 virtual void haltContext(int thread_num);
145 virtual void regStats();
146 virtual void resetStats();
148 // number of simulated instructions
150 Counter startNumInst;
151 Stats::Scalar<> numInsts;
153 virtual Counter totalInstructions() const
155 return numInst - startNumInst;
158 // number of simulated memory references
159 Stats::Scalar<> numMemRefs;
161 // number of simulated loads
163 Counter startNumLoad;
165 // number of idle cycles
166 Stats::Average<> notIdleFraction;
167 Stats::Formula idleFraction;
169 // number of cycles stalled for I-cache responses
170 Stats::Scalar<> icacheStallCycles;
171 Counter lastIcacheStall;
173 // number of cycles stalled for I-cache retries
174 Stats::Scalar<> icacheRetryCycles;
175 Counter lastIcacheRetry;
177 // number of cycles stalled for D-cache responses
178 Stats::Scalar<> dcacheStallCycles;
179 Counter lastDcacheStall;
181 // number of cycles stalled for D-cache retries
182 Stats::Scalar<> dcacheRetryCycles;
183 Counter lastDcacheRetry;
185 virtual void serialize(std::ostream &os);
186 virtual void unserialize(Checkpoint *cp, const std::string §ion);
188 // These functions are only used in CPU models that split
189 // effective address computation from the actual memory access.
190 void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); }
191 Addr getEA() { panic("BaseSimpleCPU::getEA() not implemented\n"); }
193 void prefetch(Addr addr, unsigned flags)
195 // need to do this...
198 void writeHint(Addr addr, int size, unsigned flags)
200 // need to do this...
203 Fault copySrcTranslate(Addr src);
205 Fault copy(Addr dest);
207 // The register accessor methods provide the index of the
208 // instruction's operand (e.g., 0 or 1), not the architectural
209 // register index, to simplify the implementation of register
210 // renaming. We find the architectural register index by indexing
211 // into the instruction's own operand index table. Note that a
212 // raw pointer to the StaticInst is provided instead of a
213 // ref-counted StaticInstPtr to redice overhead. This is fine as
214 // long as these methods don't copy the pointer into any long-term
215 // storage (which is pretty hard to imagine they would have reason
218 uint64_t readIntReg(const StaticInst *si, int idx)
220 return cpuXC->readIntReg(si->srcRegIdx(idx));
223 FloatReg readFloatReg(const StaticInst *si, int idx, int width)
225 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
226 return cpuXC->readFloatReg(reg_idx, width);
229 FloatReg readFloatReg(const StaticInst *si, int idx)
231 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
232 return cpuXC->readFloatReg(reg_idx);
235 FloatRegBits readFloatRegBits(const StaticInst *si, int idx, int width)
237 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
238 return cpuXC->readFloatRegBits(reg_idx, width);
241 FloatRegBits readFloatRegBits(const StaticInst *si, int idx)
243 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
244 return cpuXC->readFloatRegBits(reg_idx);
247 void setIntReg(const StaticInst *si, int idx, uint64_t val)
249 cpuXC->setIntReg(si->destRegIdx(idx), val);
252 void setFloatReg(const StaticInst *si, int idx, FloatReg val, int width)
254 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
255 cpuXC->setFloatReg(reg_idx, val, width);
258 void setFloatReg(const StaticInst *si, int idx, FloatReg val)
260 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
261 cpuXC->setFloatReg(reg_idx, val);
264 void setFloatRegBits(const StaticInst *si, int idx,
265 FloatRegBits val, int width)
267 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
268 cpuXC->setFloatRegBits(reg_idx, val, width);
271 void setFloatRegBits(const StaticInst *si, int idx, FloatRegBits val)
273 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
274 cpuXC->setFloatRegBits(reg_idx, val);
277 uint64_t readPC() { return cpuXC->readPC(); }
278 uint64_t readNextPC() { return cpuXC->readNextPC(); }
279 uint64_t readNextNPC() { return cpuXC->readNextNPC(); }
281 void setPC(uint64_t val) { cpuXC->setPC(val); }
282 void setNextPC(uint64_t val) { cpuXC->setNextPC(val); }
283 void setNextNPC(uint64_t val) { cpuXC->setNextNPC(val); }
285 MiscReg readMiscReg(int misc_reg)
287 return cpuXC->readMiscReg(misc_reg);
290 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault)
292 return cpuXC->readMiscRegWithEffect(misc_reg, fault);
295 Fault setMiscReg(int misc_reg, const MiscReg &val)
297 return cpuXC->setMiscReg(misc_reg, val);
300 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val)
302 return cpuXC->setMiscRegWithEffect(misc_reg, val);
306 Fault hwrei() { return cpuXC->hwrei(); }
307 int readIntrFlag() { return cpuXC->readIntrFlag(); }
308 void setIntrFlag(int val) { cpuXC->setIntrFlag(val); }
309 bool inPalMode() { return cpuXC->inPalMode(); }
310 void ev5_trap(Fault fault) { fault->invoke(tc); }
311 bool simPalCheck(int palFunc) { return cpuXC->simPalCheck(palFunc); }
313 void syscall(int64_t callnum) { cpuXC->syscall(callnum); }
316 bool misspeculating() { return cpuXC->misspeculating(); }
317 ThreadContext *tcBase() { return tc; }
320 #endif // __CPU_SIMPLE_BASE_HH__