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.
29 #ifndef __CPU_SIMPLE_CPU_SIMPLE_CPU_HH__
30 #define __CPU_SIMPLE_CPU_SIMPLE_CPU_HH__
32 #include "base/statistics.hh"
33 #include "config/full_system.hh"
34 #include "cpu/base.hh"
35 #include "cpu/exec_context.hh"
36 #include "cpu/pc_event.hh"
37 #include "cpu/sampler/sampler.hh"
38 #include "cpu/static_inst.hh"
39 #include "sim/eventq.hh"
41 // forward declarations
64 class SimpleCPU : public BaseCPU
67 // main simulation loop (one cycle)
71 struct TickEvent : public Event
76 TickEvent(SimpleCPU *c, int w);
78 const char *description();
83 /// Schedule tick event, regardless of its current state.
84 void scheduleTickEvent(int numCycles)
86 if (tickEvent.squashed())
87 tickEvent.reschedule(curTick + cycles(numCycles));
88 else if (!tickEvent.scheduled())
89 tickEvent.schedule(curTick + cycles(numCycles));
92 /// Unschedule tick event, regardless of its current state.
93 void unscheduleTickEvent()
95 if (tickEvent.scheduled())
100 Trace::InstRecord *traceData;
118 void post_interrupt(int int_num, int index);
120 void zero_fill_64(Addr addr) {
121 static int warned = 0;
123 warn ("WH64 is not implemented");
129 struct Params : public BaseCPU::Params
131 MemInterface *icache_interface;
132 MemInterface *dcache_interface;
137 FunctionalMemory *mem;
142 SimpleCPU(Params *params);
143 virtual ~SimpleCPU();
149 void switchOut(Sampler *s);
150 void takeOverFrom(BaseCPU *oldCPU);
153 Addr dbg_vtophys(Addr addr);
158 // L1 instruction cache
159 MemInterface *icacheInterface;
162 MemInterface *dcacheInterface;
164 // current instruction
167 // Refcounted pointer to the one memory request.
170 // Pointer to the sampler that is telling us to switchover.
171 // Used to signal the completion of the pipe drain and schedule
172 // the next switchover
175 StaticInstPtr<TheISA> curStaticInst;
177 class CacheCompletionEvent : public Event
183 CacheCompletionEvent(SimpleCPU *_cpu);
185 virtual void process();
186 virtual const char *description();
189 CacheCompletionEvent cacheCompletionEvent;
191 Status status() const { return _status; }
193 virtual void activateContext(int thread_num, int delay);
194 virtual void suspendContext(int thread_num);
195 virtual void deallocateContext(int thread_num);
196 virtual void haltContext(int thread_num);
199 virtual void regStats();
200 virtual void resetStats();
202 // number of simulated instructions
204 Counter startNumInst;
205 Stats::Scalar<> numInsts;
207 virtual Counter totalInstructions() const
209 return numInst - startNumInst;
212 // number of simulated memory references
213 Stats::Scalar<> numMemRefs;
215 // number of simulated loads
217 Counter startNumLoad;
219 // number of idle cycles
220 Stats::Average<> notIdleFraction;
221 Stats::Formula idleFraction;
223 // number of cycles stalled for I-cache misses
224 Stats::Scalar<> icacheStallCycles;
225 Counter lastIcacheStall;
227 // number of cycles stalled for D-cache misses
228 Stats::Scalar<> dcacheStallCycles;
229 Counter lastDcacheStall;
231 void processCacheCompletion();
233 virtual void serialize(std::ostream &os);
234 virtual void unserialize(Checkpoint *cp, const std::string §ion);
237 Fault read(Addr addr, T &data, unsigned flags);
240 Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
242 // These functions are only used in CPU models that split
243 // effective address computation from the actual memory access.
244 void setEA(Addr EA) { panic("SimpleCPU::setEA() not implemented\n"); }
245 Addr getEA() { panic("SimpleCPU::getEA() not implemented\n"); }
247 void prefetch(Addr addr, unsigned flags)
249 // need to do this...
252 void writeHint(Addr addr, int size, unsigned flags)
254 // need to do this...
257 Fault copySrcTranslate(Addr src);
259 Fault copy(Addr dest);
261 // The register accessor methods provide the index of the
262 // instruction's operand (e.g., 0 or 1), not the architectural
263 // register index, to simplify the implementation of register
264 // renaming. We find the architectural register index by indexing
265 // into the instruction's own operand index table. Note that a
266 // raw pointer to the StaticInst is provided instead of a
267 // ref-counted StaticInstPtr to redice overhead. This is fine as
268 // long as these methods don't copy the pointer into any long-term
269 // storage (which is pretty hard to imagine they would have reason
272 uint64_t readIntReg(const StaticInst<TheISA> *si, int idx)
274 return xc->readIntReg(si->srcRegIdx(idx));
277 float readFloatRegSingle(const StaticInst<TheISA> *si, int idx)
279 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
280 return xc->readFloatRegSingle(reg_idx);
283 double readFloatRegDouble(const StaticInst<TheISA> *si, int idx)
285 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
286 return xc->readFloatRegDouble(reg_idx);
289 uint64_t readFloatRegInt(const StaticInst<TheISA> *si, int idx)
291 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
292 return xc->readFloatRegInt(reg_idx);
295 void setIntReg(const StaticInst<TheISA> *si, int idx, uint64_t val)
297 xc->setIntReg(si->destRegIdx(idx), val);
300 void setFloatRegSingle(const StaticInst<TheISA> *si, int idx, float val)
302 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
303 xc->setFloatRegSingle(reg_idx, val);
306 void setFloatRegDouble(const StaticInst<TheISA> *si, int idx, double val)
308 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
309 xc->setFloatRegDouble(reg_idx, val);
312 void setFloatRegInt(const StaticInst<TheISA> *si, int idx, uint64_t val)
314 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
315 xc->setFloatRegInt(reg_idx, val);
318 uint64_t readPC() { return xc->readPC(); }
319 void setNextPC(uint64_t val) { xc->setNextPC(val); }
321 uint64_t readUniq() { return xc->readUniq(); }
322 void setUniq(uint64_t val) { xc->setUniq(val); }
324 uint64_t readFpcr() { return xc->readFpcr(); }
325 void setFpcr(uint64_t val) { xc->setFpcr(val); }
328 uint64_t readIpr(int idx, Fault &fault) { return xc->readIpr(idx, fault); }
329 Fault setIpr(int idx, uint64_t val) { return xc->setIpr(idx, val); }
330 Fault hwrei() { return xc->hwrei(); }
331 int readIntrFlag() { return xc->readIntrFlag(); }
332 void setIntrFlag(int val) { xc->setIntrFlag(val); }
333 bool inPalMode() { return xc->inPalMode(); }
334 void ev5_trap(Fault fault) { xc->ev5_trap(fault); }
335 bool simPalCheck(int palFunc) { return xc->simPalCheck(palFunc); }
337 void syscall() { xc->syscall(); }
340 bool misspeculating() { return xc->misspeculating(); }
341 ExecContext *xcBase() { return xc; }
344 #endif // __CPU_SIMPLE_CPU_SIMPLE_CPU_HH__