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 // Also somewhat obnoxious. Really only used for the TLB fault.
175 TheISA::MachInst getInst();
177 void copyArchRegs(ThreadContext *tc);
179 void clearArchRegs();
181 uint64_t readIntReg(int reg_idx);
183 FloatReg readFloatReg(int reg_idx);
185 FloatRegBits readFloatRegBits(int reg_idx);
187 void setIntReg(int reg_idx, uint64_t val);
189 void setFloatReg(int reg_idx, FloatReg val);
191 void setFloatRegBits(int reg_idx, FloatRegBits val);
193 uint64_t readPC() { return thread->PC; }
194 void setPC(Addr val);
196 uint64_t readNextPC() { return thread->nextPC; }
197 void setNextPC(Addr val);
199 uint64_t readNextNPC()
201 #if ISA_HAS_DELAY_SLOT
202 panic("Ozone needs to support nextNPC");
204 return thread->nextPC + sizeof(TheISA::MachInst);
208 void setNextNPC(uint64_t val)
210 #if ISA_HAS_DELAY_SLOT
211 panic("Ozone needs to support nextNPC");
217 MiscReg readMiscRegNoEffect(int misc_reg);
219 MiscReg readMiscReg(int misc_reg);
221 void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
223 void setMiscReg(int misc_reg, const MiscReg &val);
225 unsigned readStCondFailures()
226 { return thread->storeCondFailures; }
228 void setStCondFailures(unsigned sc_failures)
229 { thread->storeCondFailures = sc_failures; }
231 bool misspeculating() { return false; }
234 Counter readFuncExeInst() { return thread->funcExeInst; }
236 void setFuncExeInst(Counter new_val)
237 { thread->funcExeInst = new_val; }
241 // Ozone specific thread context
243 // Thread context to be used
245 // Checker thread context; will wrap the OzoneTC if a checker is
247 ThreadContext *checkerTC;
249 typedef OzoneThreadState<Impl> ImplState;
252 // Committed thread state for the OzoneCPU.
253 OzoneThreadState<Impl> thread;
256 // main simulation loop (one cycle)
260 /** Count of total number of dynamic instructions in flight. */
264 std::set<InstSeqNum> snList;
265 std::set<Addr> lockAddrList;
267 struct TickEvent : public Event
272 TickEvent(OzoneCPU *c, int w);
274 const char *description() const;
279 /// Schedule tick event, regardless of its current state.
280 void scheduleTickEvent(int delay)
282 if (tickEvent.squashed())
283 tickEvent.reschedule(curTick + ticks(delay));
284 else if (!tickEvent.scheduled())
285 tickEvent.schedule(curTick + ticks(delay));
288 /// Unschedule tick event, regardless of its current state.
289 void unscheduleTickEvent()
291 if (tickEvent.scheduled())
307 void zero_fill_64(Addr addr) {
308 static int warned = 0;
310 warn ("WH64 is not implemented");
315 typedef typename Impl::Params Params;
317 OzoneCPU(Params *params);
324 BaseCPU *getCpuPtr() { return this; }
327 void signalSwitched();
328 void takeOverFrom(BaseCPU *oldCPU);
333 Addr dbg_vtophys(Addr addr);
340 PhysicalMemory *physmem;
343 virtual Port *getPort(const std::string &name, int idx);
350 Status status() const { return _status; }
351 void setStatus(Status new_status) { _status = new_status; }
353 virtual void activateContext(int thread_num, int delay);
354 virtual void suspendContext(int thread_num);
355 virtual void deallocateContext(int thread_num, int delay);
356 virtual void haltContext(int thread_num);
359 virtual void regStats();
360 virtual void resetStats();
362 // number of simulated instructions
365 Counter startNumInst;
367 virtual Counter totalInstructions() const
369 return numInst - startNumInst;
373 // number of simulated loads
375 Counter startNumLoad;
377 // number of idle cycles
378 Stats::Average notIdleFraction;
379 Stats::Formula idleFraction;
382 virtual void serialize(std::ostream &os);
383 virtual void unserialize(Checkpoint *cp, const std::string §ion);
385 void demapPage(Addr vaddr, uint64_t asn)
387 cpu->itb->demap(vaddr, asn);
388 cpu->dtb->demap(vaddr, asn);
391 void demapInstPage(Addr vaddr, uint64_t asn)
393 cpu->itb->demap(vaddr, asn);
396 void demapDataPage(Addr vaddr, uint64_t asn)
398 cpu->dtb->demap(vaddr, asn);
401 /** CPU read function, forwards read to LSQ. */
403 Fault read(Request *req, T &data, int load_idx)
405 return backEnd->read(req, data, load_idx);
408 /** CPU write function, forwards write to LSQ. */
410 Fault write(Request *req, T &data, int store_idx)
412 return backEnd->write(req, data, store_idx);
415 void prefetch(Addr addr, unsigned flags)
417 // need to do this...
420 void writeHint(Addr addr, int size, unsigned flags)
422 // need to do this...
425 Fault copySrcTranslate(Addr src);
427 Fault copy(Addr dest);
432 void dumpInsts() { frontEnd->dumpInsts(); }
436 bool simPalCheck(int palFunc);
437 void processInterrupts();
439 void syscall(uint64_t &callnum);
442 ThreadContext *tcBase() { return tc; }
445 InstSeqNum doneSeqNum;
446 InstSeqNum nonSpecSeqNum;
453 InstSeqNum globalSeqNum;
455 TimeBuffer<CommStruct> comm;
457 bool decoupledFrontEnd;
461 Stats::Scalar quiesceCycles;
463 Checker<DynInstPtr> *checker;
466 #endif // __CPU_OZONE_CPU_HH__