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)
72 : Event(&mainEventQueue, 100), cpu(c) { }
73 void process() { cpu->tick(); }
74 virtual const char *description() { return "tick event"; }
80 Trace::InstRecord *traceData;
82 void trace_data(T data) {
84 traceData->setData(data);
103 void post_interrupt(int int_num, int index);
105 void zero_fill_64(Addr addr) {
106 static int warned = 0;
108 warn ("WH64 is not implemented");
115 SimpleCPU(const std::string &_name,
117 Counter max_insts_any_thread, Counter max_insts_all_threads,
118 Counter max_loads_any_thread, Counter max_loads_all_threads,
119 AlphaItb *itb, AlphaDtb *dtb, FunctionalMemory *mem,
120 MemInterface *icache_interface, MemInterface *dcache_interface,
125 SimpleCPU(const std::string &_name, Process *_process,
126 Counter max_insts_any_thread,
127 Counter max_insts_all_threads,
128 Counter max_loads_any_thread,
129 Counter max_loads_all_threads,
130 MemInterface *icache_interface, MemInterface *dcache_interface);
134 virtual ~SimpleCPU();
140 void takeOverFrom(BaseCPU *oldCPU);
143 Addr dbg_vtophys(Addr addr);
148 // L1 instruction cache
149 MemInterface *icacheInterface;
152 MemInterface *dcacheInterface;
154 // current instruction
157 // current fault status
160 // Refcounted pointer to the one memory request.
163 class CacheCompletionEvent : public Event
169 CacheCompletionEvent(SimpleCPU *_cpu);
171 virtual void process();
172 virtual const char *description();
175 CacheCompletionEvent cacheCompletionEvent;
177 Status status() const { return _status; }
179 virtual void execCtxStatusChg(int thread_num);
181 void setStatus(Status new_status) {
182 Status old_status = status();
184 // We should never even get here if the CPU has been switched out.
185 assert(old_status != SwitchedOut);
187 _status = new_status;
190 case IcacheMissStall:
191 assert(old_status == Running);
192 lastIcacheStall = curTick;
193 if (tickEvent.scheduled())
197 case IcacheMissComplete:
198 assert(old_status == IcacheMissStall);
199 if (tickEvent.squashed())
200 tickEvent.reschedule(curTick + 1);
201 else if (!tickEvent.scheduled())
202 tickEvent.schedule(curTick + 1);
205 case DcacheMissStall:
206 assert(old_status == Running);
207 lastDcacheStall = curTick;
208 if (tickEvent.scheduled())
213 assert(old_status == Running);
215 if (tickEvent.scheduled())
220 assert(old_status == Idle ||
221 old_status == DcacheMissStall ||
222 old_status == IcacheMissComplete);
223 if (old_status == Idle)
224 idleCycles += curTick - last_idle;
226 if (tickEvent.squashed())
227 tickEvent.reschedule(curTick + 1);
228 else if (!tickEvent.scheduled())
229 tickEvent.schedule(curTick + 1);
233 panic("can't get here");
240 // number of simulated instructions
242 Statistics::Formula numInsts;
244 // number of simulated memory references
245 Statistics::Scalar<> numMemRefs;
247 // number of simulated loads
250 // number of idle cycles
251 Statistics::Scalar<> idleCycles;
252 Statistics::Formula idleFraction;
255 // number of cycles stalled for I-cache misses
256 Statistics::Scalar<> icacheStallCycles;
257 Counter lastIcacheStall;
259 // number of cycles stalled for D-cache misses
260 Statistics::Scalar<> dcacheStallCycles;
261 Counter lastDcacheStall;
263 void processCacheCompletion();
265 virtual void serialize();
266 virtual void unserialize(IniFile &db, const std::string &category,
270 Fault read(Addr addr, T& data, unsigned flags);
273 Fault write(T data, Addr addr, unsigned flags,
276 Fault prefetch(Addr addr, unsigned flags)
278 // need to do this...
282 void writeHint(Addr addr, int size)
284 // need to do this...
288 #endif // __SIMPLE_CPU_HH__