2 * Copyright (c) 2002-2004 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 "cpu/pc_event.hh"
35 #include "base/statistics.hh"
36 #include "cpu/exec_context.hh"
37 #include "cpu/static_inst.hh"
39 // forward declarations
62 class SimpleCPU : public BaseCPU
65 // main simulation loop (one cycle)
69 struct TickEvent : public Event
74 TickEvent(SimpleCPU *c);
76 const char *description();
81 /// Schedule tick event, regardless of its current state.
82 void scheduleTickEvent(int delay)
84 if (tickEvent.squashed())
85 tickEvent.reschedule(curTick + delay);
86 else if (!tickEvent.scheduled())
87 tickEvent.schedule(curTick + delay);
90 /// Unschedule tick event, regardless of its current state.
91 void unscheduleTickEvent()
93 if (tickEvent.scheduled())
98 void setTickMultiplier(int multiplier)
100 tickEvent.multiplier = multiplier;
104 Trace::InstRecord *traceData;
106 void trace_data(T data) {
108 traceData->setData(data);
127 void post_interrupt(int int_num, int index);
129 void zero_fill_64(Addr addr) {
130 static int warned = 0;
132 warn ("WH64 is not implemented");
139 SimpleCPU(const std::string &_name,
141 Counter max_insts_any_thread, Counter max_insts_all_threads,
142 Counter max_loads_any_thread, Counter max_loads_all_threads,
143 AlphaITB *itb, AlphaDTB *dtb, FunctionalMemory *mem,
144 MemInterface *icache_interface, MemInterface *dcache_interface,
145 bool _def_reg, Tick freq,
146 bool _function_trace, Tick _function_trace_start);
150 SimpleCPU(const std::string &_name, Process *_process,
151 Counter max_insts_any_thread,
152 Counter max_insts_all_threads,
153 Counter max_loads_any_thread,
154 Counter max_loads_all_threads,
155 MemInterface *icache_interface, MemInterface *dcache_interface,
157 bool _function_trace, Tick _function_trace_start);
161 virtual ~SimpleCPU();
167 void takeOverFrom(BaseCPU *oldCPU);
170 Addr dbg_vtophys(Addr addr);
175 // L1 instruction cache
176 MemInterface *icacheInterface;
179 MemInterface *dcacheInterface;
181 // current instruction
184 // Refcounted pointer to the one memory request.
187 class CacheCompletionEvent : public Event
193 CacheCompletionEvent(SimpleCPU *_cpu);
195 virtual void process();
196 virtual const char *description();
199 CacheCompletionEvent cacheCompletionEvent;
201 Status status() const { return _status; }
203 virtual void activateContext(int thread_num, int delay);
204 virtual void suspendContext(int thread_num);
205 virtual void deallocateContext(int thread_num);
206 virtual void haltContext(int thread_num);
209 virtual void regStats();
210 virtual void resetStats();
212 // number of simulated instructions
214 Counter startNumInst;
215 Stats::Scalar<> numInsts;
217 virtual Counter totalInstructions() const
219 return numInst - startNumInst;
222 // number of simulated memory references
223 Stats::Scalar<> numMemRefs;
225 // number of simulated loads
227 Counter startNumLoad;
229 // number of idle cycles
230 Stats::Average<> notIdleFraction;
231 Stats::Formula idleFraction;
233 // number of cycles stalled for I-cache misses
234 Stats::Scalar<> icacheStallCycles;
235 Counter lastIcacheStall;
237 // number of cycles stalled for D-cache misses
238 Stats::Scalar<> dcacheStallCycles;
239 Counter lastDcacheStall;
241 void processCacheCompletion();
243 virtual void serialize(std::ostream &os);
244 virtual void unserialize(Checkpoint *cp, const std::string §ion);
247 Fault read(Addr addr, T &data, unsigned flags);
250 Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
252 void prefetch(Addr addr, unsigned flags)
254 // need to do this...
257 void writeHint(Addr addr, int size, unsigned flags)
259 // need to do this...
262 Fault copySrcTranslate(Addr src);
264 Fault copy(Addr dest);
266 // The register accessor methods provide the index of the
267 // instruction's operand (e.g., 0 or 1), not the architectural
268 // register index, to simplify the implementation of register
269 // renaming. We find the architectural register index by indexing
270 // into the instruction's own operand index table. Note that a
271 // raw pointer to the StaticInst is provided instead of a
272 // ref-counted StaticInstPtr to redice overhead. This is fine as
273 // long as these methods don't copy the pointer into any long-term
274 // storage (which is pretty hard to imagine they would have reason
277 uint64_t readIntReg(StaticInst<TheISA> *si, int idx)
279 return xc->readIntReg(si->srcRegIdx(idx));
282 float readFloatRegSingle(StaticInst<TheISA> *si, int idx)
284 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
285 return xc->readFloatRegSingle(reg_idx);
288 double readFloatRegDouble(StaticInst<TheISA> *si, int idx)
290 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
291 return xc->readFloatRegDouble(reg_idx);
294 uint64_t readFloatRegInt(StaticInst<TheISA> *si, int idx)
296 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
297 return xc->readFloatRegInt(reg_idx);
300 void setIntReg(StaticInst<TheISA> *si, int idx, uint64_t val)
302 xc->setIntReg(si->destRegIdx(idx), val);
305 void setFloatRegSingle(StaticInst<TheISA> *si, int idx, float val)
307 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
308 xc->setFloatRegSingle(reg_idx, val);
311 void setFloatRegDouble(StaticInst<TheISA> *si, int idx, double val)
313 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
314 xc->setFloatRegDouble(reg_idx, val);
317 void setFloatRegInt(StaticInst<TheISA> *si, int idx, uint64_t val)
319 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
320 xc->setFloatRegInt(reg_idx, val);
323 uint64_t readPC() { return xc->readPC(); }
324 void setNextPC(uint64_t val) { xc->setNextPC(val); }
326 uint64_t readUniq() { return xc->readUniq(); }
327 void setUniq(uint64_t val) { xc->setUniq(val); }
329 uint64_t readFpcr() { return xc->readFpcr(); }
330 void setFpcr(uint64_t val) { xc->setFpcr(val); }
333 uint64_t readIpr(int idx, Fault &fault) { return xc->readIpr(idx, fault); }
334 Fault setIpr(int idx, uint64_t val) { return xc->setIpr(idx, val); }
335 Fault hwrei() { return xc->hwrei(); }
336 int readIntrFlag() { return xc->readIntrFlag(); }
337 void setIntrFlag(int val) { xc->setIntrFlag(val); }
338 bool inPalMode() { return xc->inPalMode(); }
339 void ev5_trap(Fault fault) { xc->ev5_trap(fault); }
340 bool simPalCheck(int palFunc) { return xc->simPalCheck(palFunc); }
342 void syscall() { xc->syscall(); }
345 bool misspeculating() { return xc->misspeculating(); }
346 ExecContext *xcBase() { return xc; }
349 #endif // __SIMPLE_CPU_HH__