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"
39 // forward declarations
63 class SimpleCPU : public BaseCPU
66 // main simulation loop (one cycle)
70 class TickEvent : public Event
76 TickEvent(SimpleCPU *c);
78 const char *description();
83 /// Schedule tick event, regardless of its current state.
84 void scheduleTickEvent(int delay)
86 if (tickEvent.squashed())
87 tickEvent.reschedule(curTick + delay);
88 else if (!tickEvent.scheduled())
89 tickEvent.schedule(curTick + delay);
92 /// Unschedule tick event, regardless of its current state.
93 void unscheduleTickEvent()
95 if (tickEvent.scheduled())
100 Trace::InstRecord *traceData;
102 void trace_data(T data) {
104 traceData->setData(data);
123 void post_interrupt(int int_num, int index);
125 void zero_fill_64(Addr addr) {
126 static int warned = 0;
128 warn ("WH64 is not implemented");
135 SimpleCPU(const std::string &_name,
137 Counter max_insts_any_thread, Counter max_insts_all_threads,
138 Counter max_loads_any_thread, Counter max_loads_all_threads,
139 AlphaITB *itb, AlphaDTB *dtb, FunctionalMemory *mem,
140 MemInterface *icache_interface, MemInterface *dcache_interface,
141 bool _def_reg, Tick freq);
145 SimpleCPU(const std::string &_name, Process *_process,
146 Counter max_insts_any_thread,
147 Counter max_insts_all_threads,
148 Counter max_loads_any_thread,
149 Counter max_loads_all_threads,
150 MemInterface *icache_interface, MemInterface *dcache_interface,
155 virtual ~SimpleCPU();
162 void takeOverFrom(BaseCPU *oldCPU);
165 Addr dbg_vtophys(Addr addr);
170 // L1 instruction cache
171 MemInterface *icacheInterface;
174 MemInterface *dcacheInterface;
176 bool defer_registration;
178 // current instruction
181 // Refcounted pointer to the one memory request.
184 class CacheCompletionEvent : public Event
190 CacheCompletionEvent(SimpleCPU *_cpu);
192 virtual void process();
193 virtual const char *description();
196 CacheCompletionEvent cacheCompletionEvent;
198 Status status() const { return _status; }
200 virtual void activateContext(int thread_num, int delay);
201 virtual void suspendContext(int thread_num);
202 virtual void deallocateContext(int thread_num);
203 virtual void haltContext(int thread_num);
206 virtual void regStats();
207 virtual void resetStats();
209 // number of simulated instructions
211 Counter startNumInst;
212 Statistics::Scalar<> numInsts;
214 virtual Counter totalInstructions() const
216 return numInst - startNumInst;
219 // number of simulated memory references
220 Statistics::Scalar<> numMemRefs;
222 // number of simulated loads
224 Counter startNumLoad;
226 // number of idle cycles
227 Statistics::Average<> notIdleFraction;
228 Statistics::Formula idleFraction;
230 // number of cycles stalled for I-cache misses
231 Statistics::Scalar<> icacheStallCycles;
232 Counter lastIcacheStall;
234 // number of cycles stalled for D-cache misses
235 Statistics::Scalar<> dcacheStallCycles;
236 Counter lastDcacheStall;
238 void processCacheCompletion();
240 virtual void serialize(std::ostream &os);
241 virtual void unserialize(Checkpoint *cp, const std::string §ion);
244 Fault read(Addr addr, T &data, unsigned flags);
247 Fault write(T data, Addr addr, unsigned flags,
250 void prefetch(Addr addr, unsigned flags)
252 // need to do this...
255 void writeHint(Addr addr, int size)
257 // need to do this...
260 Fault copySrcTranslate(Addr src);
262 Fault copy(Addr dest);
264 uint64_t readIntReg(int reg_idx) { return xc->readIntReg(reg_idx); }
266 float readFloatRegSingle(int reg_idx)
267 { return xc->readFloatRegSingle(reg_idx); }
269 double readFloatRegDouble(int reg_idx)
270 { return xc->readFloatRegDouble(reg_idx); }
272 uint64_t readFloatRegInt(int reg_idx)
273 { return xc->readFloatRegInt(reg_idx); }
275 void setIntReg(int reg_idx, uint64_t val)
276 { return xc->setIntReg(reg_idx, val); }
278 void setFloatRegSingle(int reg_idx, float val)
279 { return xc->setFloatRegSingle(reg_idx, val); }
281 void setFloatRegDouble(int reg_idx, double val)
282 { return xc->setFloatRegDouble(reg_idx, val); }
284 void setFloatRegInt(int reg_idx, uint64_t val)
285 { return xc->setFloatRegInt(reg_idx, val); }
287 uint64_t readPC() { return xc->readPC(); }
288 void setNextPC(uint64_t val) { return xc->setNextPC(val); }
290 uint64_t readUniq() { return xc->readUniq(); }
291 void setUniq(uint64_t val) { return xc->setUniq(val); }
293 uint64_t readFpcr() { return xc->readFpcr(); }
294 void setFpcr(uint64_t val) { return xc->setFpcr(val); }
297 uint64_t readIpr(int idx, Fault &fault) { return xc->readIpr(idx, fault); }
298 Fault setIpr(int idx, uint64_t val) { return xc->setIpr(idx, val); }
299 Fault hwrei() { return xc->hwrei(); }
300 int readIntrFlag() { return xc->readIntrFlag(); }
301 void setIntrFlag(int val) { xc->setIntrFlag(val); }
302 bool inPalMode() { return xc->inPalMode(); }
303 void ev5_trap(Fault fault) { return xc->ev5_trap(fault); }
304 bool simPalCheck(int palFunc) { return xc->simPalCheck(palFunc); }
306 void syscall() { xc->syscall(); }
309 bool misspeculating() { return xc->misspeculating(); }
310 ExecContext *xcBase() { return xc; }
313 #endif // __SIMPLE_CPU_HH__