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"
39 // forward declarations
58 class SimpleCPU : public BaseCPU
61 // main simulation loop (one cycle)
65 class TickEvent : public Event
71 TickEvent(SimpleCPU *c);
73 const char *description();
79 Trace::InstRecord *traceData;
81 void trace_data(T data) {
83 traceData->setData(data);
102 void post_interrupt(int int_num, int index);
104 void zero_fill_64(Addr addr) {
105 static int warned = 0;
107 warn ("WH64 is not implemented");
114 SimpleCPU(const std::string &_name,
116 Counter max_insts_any_thread, Counter max_insts_all_threads,
117 Counter max_loads_any_thread, Counter max_loads_all_threads,
118 AlphaItb *itb, AlphaDtb *dtb, FunctionalMemory *mem,
119 MemInterface *icache_interface, MemInterface *dcache_interface,
124 SimpleCPU(const std::string &_name, Process *_process,
125 Counter max_insts_any_thread,
126 Counter max_insts_all_threads,
127 Counter max_loads_any_thread,
128 Counter max_loads_all_threads,
129 MemInterface *icache_interface, MemInterface *dcache_interface);
133 virtual ~SimpleCPU();
139 void takeOverFrom(BaseCPU *oldCPU);
142 Addr dbg_vtophys(Addr addr);
147 // L1 instruction cache
148 MemInterface *icacheInterface;
151 MemInterface *dcacheInterface;
153 // current instruction
156 // Refcounted pointer to the one memory request.
159 class CacheCompletionEvent : public Event
165 CacheCompletionEvent(SimpleCPU *_cpu);
167 virtual void process();
168 virtual const char *description();
171 CacheCompletionEvent cacheCompletionEvent;
173 Status status() const { return _status; }
175 virtual void execCtxStatusChg(int thread_num);
177 void setStatus(Status new_status) {
178 Status old_status = status();
180 // We should never even get here if the CPU has been switched out.
181 assert(old_status != SwitchedOut);
183 _status = new_status;
186 case IcacheMissStall:
187 assert(old_status == Running);
188 lastIcacheStall = curTick;
189 if (tickEvent.scheduled())
193 case IcacheMissComplete:
194 assert(old_status == IcacheMissStall);
195 if (tickEvent.squashed())
196 tickEvent.reschedule(curTick + 1);
197 else if (!tickEvent.scheduled())
198 tickEvent.schedule(curTick + 1);
201 case DcacheMissStall:
202 assert(old_status == Running);
203 lastDcacheStall = curTick;
204 if (tickEvent.scheduled())
209 assert(old_status == Running);
211 if (tickEvent.scheduled())
216 assert(old_status == Idle ||
217 old_status == DcacheMissStall ||
218 old_status == IcacheMissComplete);
219 if (old_status == Idle && curTick != 0)
222 if (tickEvent.squashed())
223 tickEvent.reschedule(curTick + 1);
224 else if (!tickEvent.scheduled())
225 tickEvent.schedule(curTick + 1);
229 panic("can't get here");
234 virtual void regStats();
235 virtual void resetStats();
237 // number of simulated instructions
239 Counter startNumInst;
240 Statistics::Formula numInsts;
242 // number of simulated memory references
243 Statistics::Scalar<> numMemRefs;
245 // number of simulated loads
247 Counter startNumLoad;
249 // number of idle cycles
250 Statistics::Average<> idleFraction;
252 // number of cycles stalled for I-cache misses
253 Statistics::Scalar<> icacheStallCycles;
254 Counter lastIcacheStall;
256 // number of cycles stalled for D-cache misses
257 Statistics::Scalar<> dcacheStallCycles;
258 Counter lastDcacheStall;
260 void processCacheCompletion();
262 virtual void serialize(std::ostream &os);
263 virtual void unserialize(Checkpoint *cp, const std::string §ion);
266 Fault read(Addr addr, T& data, unsigned flags);
269 Fault write(T data, Addr addr, unsigned flags,
272 Fault prefetch(Addr addr, unsigned flags)
274 // need to do this...
278 void writeHint(Addr addr, int size)
280 // need to do this...
284 #endif // __SIMPLE_CPU_HH__