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 "arch/regfile.hh"
37 #include "base/statistics.hh"
38 #include "base/timebuf.hh"
39 #include "config/full_system.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"
60 class MemoryController;
76 class EndQuiesceEvent;
88 * Light weight out of order CPU model that approximates an out of
89 * order CPU. It is separated into a front end and a back end, with
90 * the template parameter Impl describing the classes used for each.
91 * The goal is to be able to specify through the Impl the class to use
92 * for the front end and back end, with different classes used to
93 * model different levels of detail.
96 class OzoneCPU : public BaseCPU
99 typedef typename Impl::FrontEnd FrontEnd;
100 typedef typename Impl::BackEnd BackEnd;
101 typedef typename Impl::DynInst DynInst;
102 typedef typename Impl::DynInstPtr DynInstPtr;
104 typedef TheISA::FloatReg FloatReg;
105 typedef TheISA::FloatRegBits FloatRegBits;
106 typedef TheISA::MiscReg MiscReg;
109 class OzoneTC : public ThreadContext {
113 OzoneThreadState<Impl> *thread;
115 BaseCPU *getCpuPtr();
117 void setCpuId(int id);
119 int readCpuId() { return thread->readCpuId(); }
122 System *getSystemPtr() { return cpu->system; }
124 PhysicalMemory *getPhysMemPtr() { return cpu->physmem; }
126 TheISA::ITB *getITBPtr() { return cpu->itb; }
128 TheISA::DTB * getDTBPtr() { return cpu->dtb; }
130 Kernel::Statistics *getKernelStats()
131 { return thread->getKernelStats(); }
133 FunctionalPort *getPhysPort() { return thread->getPhysPort(); }
135 VirtualPort *getVirtPort(ThreadContext *tc = NULL)
136 { return thread->getVirtPort(tc); }
138 void delVirtPort(VirtualPort *vp);
140 TranslatingPort *getMemPort() { return thread->getMemPort(); }
142 Process *getProcessPtr() { return thread->getProcessPtr(); }
145 Status status() const { return thread->status(); }
147 void setStatus(Status new_status);
149 /// Set the status to Active. Optional delay indicates number of
150 /// cycles to wait before beginning execution.
151 void activate(int delay = 1);
153 /// Set the status to Suspended.
156 /// Set the status to Unallocated.
157 void deallocate(int delay = 0);
159 /// Set the status to Halted.
163 void dumpFuncProfile();
166 void takeOverFrom(ThreadContext *old_context);
168 void regStats(const std::string &name);
170 void serialize(std::ostream &os);
171 void unserialize(Checkpoint *cp, const std::string §ion);
174 EndQuiesceEvent *getQuiesceEvent();
176 Tick readLastActivate();
177 Tick readLastSuspend();
180 void profileSample();
185 // Also somewhat obnoxious. Really only used for the TLB fault.
186 TheISA::MachInst getInst();
188 void copyArchRegs(ThreadContext *tc);
190 void clearArchRegs();
192 uint64_t readIntReg(int reg_idx);
194 FloatReg readFloatReg(int reg_idx, int width);
196 FloatReg readFloatReg(int reg_idx);
198 FloatRegBits readFloatRegBits(int reg_idx, int width);
200 FloatRegBits readFloatRegBits(int reg_idx);
202 void setIntReg(int reg_idx, uint64_t val);
204 void setFloatReg(int reg_idx, FloatReg val, int width);
206 void setFloatReg(int reg_idx, FloatReg val);
208 void setFloatRegBits(int reg_idx, FloatRegBits val, int width);
210 void setFloatRegBits(int reg_idx, FloatRegBits val);
212 uint64_t readPC() { return thread->PC; }
213 void setPC(Addr val);
215 uint64_t readNextPC() { return thread->nextPC; }
216 void setNextPC(Addr val);
218 uint64_t readNextNPC()
223 void setNextNPC(uint64_t val)
228 MiscReg readMiscReg(int misc_reg);
230 MiscReg readMiscRegWithEffect(int misc_reg);
232 void setMiscReg(int misc_reg, const MiscReg &val);
234 void setMiscRegWithEffect(int misc_reg, const MiscReg &val);
236 unsigned readStCondFailures()
237 { return thread->storeCondFailures; }
239 void setStCondFailures(unsigned sc_failures)
240 { thread->storeCondFailures = sc_failures; }
243 bool inPalMode() { return cpu->inPalMode(); }
246 bool misspeculating() { return false; }
249 TheISA::IntReg getSyscallArg(int i)
250 { return thread->renameTable[TheISA::ArgumentReg0 + i]->readIntResult(); }
252 // used to shift args for indirect syscall
253 void setSyscallArg(int i, TheISA::IntReg val)
254 { thread->renameTable[TheISA::ArgumentReg0 + i]->setIntResult(i); }
256 void setSyscallReturn(SyscallReturn return_value)
257 { cpu->setSyscallReturn(return_value, thread->readTid()); }
259 Counter readFuncExeInst() { return thread->funcExeInst; }
261 void setFuncExeInst(Counter new_val)
262 { thread->funcExeInst = new_val; }
264 void changeRegFileContext(TheISA::RegContextParam param,
265 TheISA::RegContextVal val)
266 { panic("Not supported on Alpha!"); }
269 // Ozone specific thread context
271 // Thread context to be used
273 // Checker thread context; will wrap the OzoneTC if a checker is
275 ThreadContext *checkerTC;
277 typedef OzoneThreadState<Impl> ImplState;
280 // Committed thread state for the OzoneCPU.
281 OzoneThreadState<Impl> thread;
284 // main simulation loop (one cycle)
287 std::set<InstSeqNum> snList;
288 std::set<Addr> lockAddrList;
290 struct TickEvent : public Event
295 TickEvent(OzoneCPU *c, int w);
297 const char *description();
302 /// Schedule tick event, regardless of its current state.
303 void scheduleTickEvent(int delay)
305 if (tickEvent.squashed())
306 tickEvent.reschedule(curTick + cycles(delay));
307 else if (!tickEvent.scheduled())
308 tickEvent.schedule(curTick + cycles(delay));
311 /// Unschedule tick event, regardless of its current state.
312 void unscheduleTickEvent()
314 if (tickEvent.scheduled())
328 void post_interrupt(int int_num, int index);
330 void zero_fill_64(Addr addr) {
331 static int warned = 0;
333 warn ("WH64 is not implemented");
338 typedef typename Impl::Params Params;
340 OzoneCPU(Params *params);
347 BaseCPU *getCpuPtr() { return this; }
349 void setCpuId(int id) { cpuId = id; }
351 int readCpuId() { return cpuId; }
356 void signalSwitched();
357 void takeOverFrom(BaseCPU *oldCPU);
362 Addr dbg_vtophys(Addr addr);
369 PhysicalMemory *physmem;
372 virtual Port *getPort(const std::string &name, int idx);
381 Status status() const { return _status; }
382 void setStatus(Status new_status) { _status = new_status; }
384 virtual void activateContext(int thread_num, int delay);
385 virtual void suspendContext(int thread_num);
386 virtual void deallocateContext(int thread_num, int delay);
387 virtual void haltContext(int thread_num);
390 virtual void regStats();
391 virtual void resetStats();
393 // number of simulated instructions
396 Counter startNumInst;
398 virtual Counter totalInstructions() const
400 return numInst - startNumInst;
404 // number of simulated loads
406 Counter startNumLoad;
408 // number of idle cycles
409 Stats::Average<> notIdleFraction;
410 Stats::Formula idleFraction;
413 virtual void serialize(std::ostream &os);
414 virtual void unserialize(Checkpoint *cp, const std::string §ion);
417 /** Translates instruction requestion. */
418 Fault translateInstReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
420 return itb->translate(req, thread->getTC());
423 /** Translates data read request. */
424 Fault translateDataReadReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
426 return dtb->translate(req, thread->getTC(), false);
429 /** Translates data write request. */
430 Fault translateDataWriteReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
432 return dtb->translate(req, thread->getTC(), true);
436 /** Translates instruction requestion in syscall emulation mode. */
437 Fault translateInstReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
439 return thread->getProcessPtr()->pTable->translate(req);
442 /** Translates data read request in syscall emulation mode. */
443 Fault translateDataReadReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
445 return thread->getProcessPtr()->pTable->translate(req);
448 /** Translates data write request in syscall emulation mode. */
449 Fault translateDataWriteReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
451 return thread->getProcessPtr()->pTable->translate(req);
455 /** Old CPU read from memory function. No longer used. */
457 Fault read(Request *req, T &data)
460 #if FULL_SYSTEM && defined(TARGET_ALPHA)
461 if (req->isLocked()) {
462 req->xc->setMiscReg(TheISA::Lock_Addr_DepTag, req->paddr);
463 req->xc->setMiscReg(TheISA::Lock_Flag_DepTag, true);
466 if (req->isLocked()) {
467 lockAddrList.insert(req->paddr);
473 error = this->mem->read(req, data);
479 /** CPU read function, forwards read to LSQ. */
481 Fault read(Request *req, T &data, int load_idx)
483 return backEnd->read(req, data, load_idx);
486 /** Old CPU write to memory function. No longer used. */
488 Fault write(Request *req, T &data)
491 #if FULL_SYSTEM && defined(TARGET_ALPHA)
494 // If this is a store conditional, act appropriately
495 if (req->isLocked()) {
498 if (req->isUncacheable()) {
499 // Don't update result register (see stq_c in isa_desc)
501 xc->setStCondFailures(0);//Needed? [RGD]
503 bool lock_flag = xc->readMiscReg(TheISA::Lock_Flag_DepTag);
504 Addr lock_addr = xc->readMiscReg(TheISA::Lock_Addr_DepTag);
505 req->result = lock_flag;
507 ((lock_addr & ~0xf) != (req->paddr & ~0xf))) {
508 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
509 xc->setStCondFailures(xc->readStCondFailures() + 1);
510 if (((xc->readStCondFailures()) % 100000) == 0) {
511 std::cerr << "Warning: "
512 << xc->readStCondFailures()
513 << " consecutive store conditional failures "
514 << "on cpu " << req->xc->readCpuId()
519 else xc->setStCondFailures(0);
523 // Need to clear any locked flags on other proccessors for
524 // this address. Only do this for succsful Store Conditionals
525 // and all other stores (WH64?). Unsuccessful Store
526 // Conditionals would have returned above, and wouldn't fall
528 for (int i = 0; i < this->system->threadContexts.size(); i++){
529 xc = this->system->threadContexts[i];
530 if ((xc->readMiscReg(TheISA::Lock_Addr_DepTag) & ~0xf) ==
531 (req->paddr & ~0xf)) {
532 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
538 if (req->isLocked()) {
539 if (req->isUncacheable()) {
542 if (this->lockFlag) {
543 if (lockAddrList.find(req->paddr) !=
544 lockAddrList.end()) {
558 return this->mem->write(req, (T)htog(data));
561 /** CPU write function, forwards write to LSQ. */
563 Fault write(Request *req, T &data, int store_idx)
565 return backEnd->write(req, data, store_idx);
568 void prefetch(Addr addr, unsigned flags)
570 // need to do this...
573 void writeHint(Addr addr, int size, unsigned flags)
575 // need to do this...
578 Fault copySrcTranslate(Addr src);
580 Fault copy(Addr dest);
585 void dumpInsts() { frontEnd->dumpInsts(); }
589 bool inPalMode() { return AlphaISA::PcPAL(thread.PC); }
590 bool inPalMode(Addr pc) { return AlphaISA::PcPAL(pc); }
591 bool simPalCheck(int palFunc);
592 void processInterrupts();
594 void syscall(uint64_t &callnum);
595 void setSyscallReturn(SyscallReturn return_value, int tid);
598 ThreadContext *tcBase() { return tc; }
601 InstSeqNum doneSeqNum;
602 InstSeqNum nonSpecSeqNum;
609 InstSeqNum globalSeqNum;
611 TimeBuffer<CommStruct> comm;
613 bool decoupledFrontEnd;
617 Stats::Scalar<> quiesceCycles;
619 Checker<DynInstPtr> *checker;
622 #endif // __CPU_OZONE_CPU_HH__