2 * Copyright (c) 2006 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.
31 #ifndef __CPU_OZONE_CPU_HH__
32 #define __CPU_OZONE_CPU_HH__
36 #include "base/statistics.hh"
37 #include "base/timebuf.hh"
38 #include "config/full_system.hh"
39 #include "config/the_isa.hh"
40 #include "cpu/base.hh"
41 #include "cpu/thread_context.hh"
42 #include "cpu/inst_seq.hh"
43 #include "cpu/ozone/rename_table.hh"
44 #include "cpu/ozone/thread_state.hh"
45 #include "cpu/pc_event.hh"
46 #include "cpu/static_inst.hh"
47 #include "mem/page_table.hh"
48 #include "sim/eventq.hh"
50 // forward declarations
52 #include "arch/alpha/tlb.hh"
59 class MemoryController;
74 class EndQuiesceEvent;
86 * Light weight out of order CPU model that approximates an out of
87 * order CPU. It is separated into a front end and a back end, with
88 * the template parameter Impl describing the classes used for each.
89 * The goal is to be able to specify through the Impl the class to use
90 * for the front end and back end, with different classes used to
91 * model different levels of detail.
94 class OzoneCPU : public BaseCPU
97 typedef typename Impl::FrontEnd FrontEnd;
98 typedef typename Impl::BackEnd BackEnd;
99 typedef typename Impl::DynInst DynInst;
100 typedef typename Impl::DynInstPtr DynInstPtr;
102 typedef TheISA::FloatReg FloatReg;
103 typedef TheISA::FloatRegBits FloatRegBits;
104 typedef TheISA::MiscReg MiscReg;
107 class OzoneTC : public ThreadContext {
111 OzoneThreadState<Impl> *thread;
113 BaseCPU *getCpuPtr();
115 TheISA::TLB *getITBPtr() { return cpu->itb; }
117 TheISA::TLB * getDTBPtr() { return cpu->dtb; }
120 System *getSystemPtr() { return cpu->system; }
122 PhysicalMemory *getPhysMemPtr() { return cpu->physmem; }
124 TheISA::Kernel::Statistics *getKernelStats()
125 { return thread->getKernelStats(); }
127 FunctionalPort *getPhysPort() { return thread->getPhysPort(); }
129 VirtualPort *getVirtPort()
130 { return thread->getVirtPort(); }
132 TranslatingPort *getMemPort() { return thread->getMemPort(); }
134 Process *getProcessPtr() { return thread->getProcessPtr(); }
137 Status status() const { return thread->status(); }
139 void setStatus(Status new_status);
141 /// Set the status to Active. Optional delay indicates number of
142 /// cycles to wait before beginning execution.
143 void activate(int delay = 1);
145 /// Set the status to Suspended.
148 /// Set the status to Halted.
152 void dumpFuncProfile();
155 void takeOverFrom(ThreadContext *old_context);
157 void regStats(const std::string &name);
159 void serialize(std::ostream &os);
160 void unserialize(Checkpoint *cp, const std::string §ion);
163 EndQuiesceEvent *getQuiesceEvent();
165 Tick readLastActivate();
166 Tick readLastSuspend();
169 void profileSample();
174 void copyArchRegs(ThreadContext *tc);
176 void clearArchRegs();
178 uint64_t readIntReg(int reg_idx);
180 FloatReg readFloatReg(int reg_idx);
182 FloatRegBits readFloatRegBits(int reg_idx);
184 void setIntReg(int reg_idx, uint64_t val);
186 void setFloatReg(int reg_idx, FloatReg val);
188 void setFloatRegBits(int reg_idx, FloatRegBits val);
190 uint64_t readPC() { return thread->PC; }
191 void setPC(Addr val);
193 uint64_t readNextPC() { return thread->nextPC; }
194 void setNextPC(Addr val);
196 uint64_t readNextNPC()
198 #if ISA_HAS_DELAY_SLOT
199 panic("Ozone needs to support nextNPC");
201 return thread->nextPC + sizeof(TheISA::MachInst);
205 void setNextNPC(uint64_t val)
207 #if ISA_HAS_DELAY_SLOT
208 panic("Ozone needs to support nextNPC");
214 MiscReg readMiscRegNoEffect(int misc_reg);
216 MiscReg readMiscReg(int misc_reg);
218 void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
220 void setMiscReg(int misc_reg, const MiscReg &val);
222 unsigned readStCondFailures()
223 { return thread->storeCondFailures; }
225 void setStCondFailures(unsigned sc_failures)
226 { thread->storeCondFailures = sc_failures; }
228 bool misspeculating() { return false; }
231 Counter readFuncExeInst() { return thread->funcExeInst; }
233 void setFuncExeInst(Counter new_val)
234 { thread->funcExeInst = new_val; }
238 // Ozone specific thread context
240 // Thread context to be used
242 // Checker thread context; will wrap the OzoneTC if a checker is
244 ThreadContext *checkerTC;
246 typedef OzoneThreadState<Impl> ImplState;
249 // Committed thread state for the OzoneCPU.
250 OzoneThreadState<Impl> thread;
253 // main simulation loop (one cycle)
257 /** Count of total number of dynamic instructions in flight. */
261 std::set<InstSeqNum> snList;
262 std::set<Addr> lockAddrList;
264 struct TickEvent : public Event
269 TickEvent(OzoneCPU *c, int w);
271 const char *description() const;
276 /// Schedule tick event, regardless of its current state.
277 void scheduleTickEvent(int delay)
279 if (tickEvent.squashed())
280 tickEvent.reschedule(curTick + ticks(delay));
281 else if (!tickEvent.scheduled())
282 tickEvent.schedule(curTick + ticks(delay));
285 /// Unschedule tick event, regardless of its current state.
286 void unscheduleTickEvent()
288 if (tickEvent.scheduled())
304 void zero_fill_64(Addr addr) {
305 static int warned = 0;
307 warn ("WH64 is not implemented");
312 typedef typename Impl::Params Params;
314 OzoneCPU(Params *params);
321 BaseCPU *getCpuPtr() { return this; }
324 void signalSwitched();
325 void takeOverFrom(BaseCPU *oldCPU);
330 Addr dbg_vtophys(Addr addr);
337 PhysicalMemory *physmem;
340 virtual Port *getPort(const std::string &name, int idx);
347 Status status() const { return _status; }
348 void setStatus(Status new_status) { _status = new_status; }
350 virtual void activateContext(int thread_num, int delay);
351 virtual void suspendContext(int thread_num);
352 virtual void deallocateContext(int thread_num, int delay);
353 virtual void haltContext(int thread_num);
356 virtual void regStats();
357 virtual void resetStats();
359 // number of simulated instructions
362 Counter startNumInst;
364 virtual Counter totalInstructions() const
366 return numInst - startNumInst;
370 // number of simulated loads
372 Counter startNumLoad;
374 // number of idle cycles
375 Stats::Average notIdleFraction;
376 Stats::Formula idleFraction;
379 virtual void serialize(std::ostream &os);
380 virtual void unserialize(Checkpoint *cp, const std::string §ion);
382 void demapPage(Addr vaddr, uint64_t asn)
384 cpu->itb->demap(vaddr, asn);
385 cpu->dtb->demap(vaddr, asn);
388 void demapInstPage(Addr vaddr, uint64_t asn)
390 cpu->itb->demap(vaddr, asn);
393 void demapDataPage(Addr vaddr, uint64_t asn)
395 cpu->dtb->demap(vaddr, asn);
398 /** CPU read function, forwards read to LSQ. */
400 Fault read(Request *req, T &data, int load_idx)
402 return backEnd->read(req, data, load_idx);
405 /** CPU write function, forwards write to LSQ. */
407 Fault write(Request *req, T &data, int store_idx)
409 return backEnd->write(req, data, store_idx);
412 void prefetch(Addr addr, unsigned flags)
414 // need to do this...
417 void writeHint(Addr addr, int size, unsigned flags)
419 // need to do this...
422 Fault copySrcTranslate(Addr src);
424 Fault copy(Addr dest);
429 void dumpInsts() { frontEnd->dumpInsts(); }
433 bool simPalCheck(int palFunc);
434 void processInterrupts();
436 void syscall(uint64_t &callnum);
439 ThreadContext *tcBase() { return tc; }
442 InstSeqNum doneSeqNum;
443 InstSeqNum nonSpecSeqNum;
450 InstSeqNum globalSeqNum;
452 TimeBuffer<CommStruct> comm;
454 bool decoupledFrontEnd;
458 Stats::Scalar quiesceCycles;
460 Checker<DynInstPtr> *checker;
463 #endif // __CPU_OZONE_CPU_HH__