2 * Copyright (c) 2003 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 __SIMPLE_CPU_HH__
30 #define __SIMPLE_CPU_HH__
32 #include "cpu/base_cpu.hh"
33 #include "sim/eventq.hh"
34 #include "base/loader/symtab.hh"
35 #include "cpu/pc_event.hh"
36 #include "base/statistics.hh"
37 #include "cpu/exec_context.hh"
38 #include "cpu/static_inst.hh"
40 // forward declarations
64 class SimpleCPU : public BaseCPU
67 // main simulation loop (one cycle)
71 class TickEvent : public Event
77 TickEvent(SimpleCPU *c);
79 const char *description();
84 /// Schedule tick event, regardless of its current state.
85 void scheduleTickEvent(int delay)
87 if (tickEvent.squashed())
88 tickEvent.reschedule(curTick + delay);
89 else if (!tickEvent.scheduled())
90 tickEvent.schedule(curTick + delay);
93 /// Unschedule tick event, regardless of its current state.
94 void unscheduleTickEvent()
96 if (tickEvent.scheduled())
101 Trace::InstRecord *traceData;
103 void trace_data(T data) {
105 traceData->setData(data);
124 void post_interrupt(int int_num, int index);
126 void zero_fill_64(Addr addr) {
127 static int warned = 0;
129 warn ("WH64 is not implemented");
136 SimpleCPU(const std::string &_name,
138 Counter max_insts_any_thread, Counter max_insts_all_threads,
139 Counter max_loads_any_thread, Counter max_loads_all_threads,
140 AlphaITB *itb, AlphaDTB *dtb, FunctionalMemory *mem,
141 MemInterface *icache_interface, MemInterface *dcache_interface,
142 bool _def_reg, Tick freq);
146 SimpleCPU(const std::string &_name, Process *_process,
147 Counter max_insts_any_thread,
148 Counter max_insts_all_threads,
149 Counter max_loads_any_thread,
150 Counter max_loads_all_threads,
151 MemInterface *icache_interface, MemInterface *dcache_interface,
156 virtual ~SimpleCPU();
163 void takeOverFrom(BaseCPU *oldCPU);
166 Addr dbg_vtophys(Addr addr);
171 // L1 instruction cache
172 MemInterface *icacheInterface;
175 MemInterface *dcacheInterface;
177 bool defer_registration;
179 // current instruction
182 // Refcounted pointer to the one memory request.
185 class CacheCompletionEvent : public Event
191 CacheCompletionEvent(SimpleCPU *_cpu);
193 virtual void process();
194 virtual const char *description();
197 CacheCompletionEvent cacheCompletionEvent;
199 Status status() const { return _status; }
201 virtual void activateContext(int thread_num, int delay);
202 virtual void suspendContext(int thread_num);
203 virtual void deallocateContext(int thread_num);
204 virtual void haltContext(int thread_num);
207 virtual void regStats();
208 virtual void resetStats();
210 // number of simulated instructions
212 Counter startNumInst;
213 Stats::Scalar<> numInsts;
215 virtual Counter totalInstructions() const
217 return numInst - startNumInst;
220 // number of simulated memory references
221 Stats::Scalar<> numMemRefs;
223 // number of simulated loads
225 Counter startNumLoad;
227 // number of idle cycles
228 Stats::Average<> notIdleFraction;
229 Stats::Formula idleFraction;
231 // number of cycles stalled for I-cache misses
232 Stats::Scalar<> icacheStallCycles;
233 Counter lastIcacheStall;
235 // number of cycles stalled for D-cache misses
236 Stats::Scalar<> dcacheStallCycles;
237 Counter lastDcacheStall;
239 void processCacheCompletion();
241 virtual void serialize(std::ostream &os);
242 virtual void unserialize(Checkpoint *cp, const std::string §ion);
245 Fault read(Addr addr, T &data, unsigned flags);
248 Fault write(T data, Addr addr, unsigned flags,
251 void prefetch(Addr addr, unsigned flags)
253 // need to do this...
256 void writeHint(Addr addr, int size)
258 // need to do this...
261 Fault copySrcTranslate(Addr src);
263 Fault copy(Addr dest);
265 // The register accessor methods provide the index of the
266 // instruction's operand (e.g., 0 or 1), not the architectural
267 // register index, to simplify the implementation of register
268 // renaming. We find the architectural register index by indexing
269 // into the instruction's own operand index table. Note that a
270 // raw pointer to the StaticInst is provided instead of a
271 // ref-counted StaticInstPtr to redice overhead. This is fine as
272 // long as these methods don't copy the pointer into any long-term
273 // storage (which is pretty hard to imagine they would have reason
276 uint64_t readIntReg(StaticInst<TheISA> *si, int idx)
278 return xc->readIntReg(si->srcRegIdx(idx));
281 float readFloatRegSingle(StaticInst<TheISA> *si, int idx)
283 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
284 return xc->readFloatRegSingle(reg_idx);
287 double readFloatRegDouble(StaticInst<TheISA> *si, int idx)
289 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
290 return xc->readFloatRegDouble(reg_idx);
293 uint64_t readFloatRegInt(StaticInst<TheISA> *si, int idx)
295 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
296 return xc->readFloatRegInt(reg_idx);
299 void setIntReg(StaticInst<TheISA> *si, int idx, uint64_t val)
301 xc->setIntReg(si->destRegIdx(idx), val);
304 void setFloatRegSingle(StaticInst<TheISA> *si, int idx, float val)
306 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
307 xc->setFloatRegSingle(reg_idx, val);
310 void setFloatRegDouble(StaticInst<TheISA> *si, int idx, double val)
312 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
313 xc->setFloatRegDouble(reg_idx, val);
316 void setFloatRegInt(StaticInst<TheISA> *si, int idx, uint64_t val)
318 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
319 xc->setFloatRegInt(reg_idx, val);
322 uint64_t readPC() { return xc->readPC(); }
323 void setNextPC(uint64_t val) { xc->setNextPC(val); }
325 uint64_t readUniq() { return xc->readUniq(); }
326 void setUniq(uint64_t val) { xc->setUniq(val); }
328 uint64_t readFpcr() { return xc->readFpcr(); }
329 void setFpcr(uint64_t val) { xc->setFpcr(val); }
332 uint64_t readIpr(int idx, Fault &fault) { return xc->readIpr(idx, fault); }
333 Fault setIpr(int idx, uint64_t val) { return xc->setIpr(idx, val); }
334 Fault hwrei() { return xc->hwrei(); }
335 int readIntrFlag() { return xc->readIntrFlag(); }
336 void setIntrFlag(int val) { xc->setIntrFlag(val); }
337 bool inPalMode() { return xc->inPalMode(); }
338 void ev5_trap(Fault fault) { xc->ev5_trap(fault); }
339 bool simPalCheck(int palFunc) { return xc->simPalCheck(palFunc); }
341 void syscall() { xc->syscall(); }
344 bool misspeculating() { return xc->misspeculating(); }
345 ExecContext *xcBase() { return xc; }
348 #endif // __SIMPLE_CPU_HH__