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"
57 class MemoryController;
73 class EndQuiesceEvent;
85 * Light weight out of order CPU model that approximates an out of
86 * order CPU. It is separated into a front end and a back end, with
87 * the template parameter Impl describing the classes used for each.
88 * The goal is to be able to specify through the Impl the class to use
89 * for the front end and back end, with different classes used to
90 * model different levels of detail.
93 class OzoneCPU : public BaseCPU
96 typedef typename Impl::FrontEnd FrontEnd;
97 typedef typename Impl::BackEnd BackEnd;
98 typedef typename Impl::DynInst DynInst;
99 typedef typename Impl::DynInstPtr DynInstPtr;
101 typedef TheISA::FloatReg FloatReg;
102 typedef TheISA::FloatRegBits FloatRegBits;
103 typedef TheISA::MiscReg MiscReg;
106 class OzoneTC : public ThreadContext {
110 OzoneThreadState<Impl> *thread;
112 BaseCPU *getCpuPtr();
114 void setCpuId(int id);
116 int readCpuId() { return thread->readCpuId(); }
119 System *getSystemPtr() { return cpu->system; }
121 PhysicalMemory *getPhysMemPtr() { return cpu->physmem; }
123 AlphaITB *getITBPtr() { return cpu->itb; }
125 AlphaDTB * getDTBPtr() { return cpu->dtb; }
127 Kernel::Statistics *getKernelStats()
128 { return thread->getKernelStats(); }
130 FunctionalPort *getPhysPort() { return thread->getPhysPort(); }
132 VirtualPort *getVirtPort(ThreadContext *tc = NULL)
133 { return thread->getVirtPort(tc); }
135 void delVirtPort(VirtualPort *vp);
137 TranslatingPort *getMemPort() { return thread->getMemPort(); }
139 Process *getProcessPtr() { return thread->getProcessPtr(); }
142 Status status() const { return thread->status(); }
144 void setStatus(Status new_status);
146 /// Set the status to Active. Optional delay indicates number of
147 /// cycles to wait before beginning execution.
148 void activate(int delay = 1);
150 /// Set the status to Suspended.
153 /// Set the status to Unallocated.
154 void deallocate(int delay = 0);
156 /// Set the status to Halted.
160 void dumpFuncProfile();
163 void takeOverFrom(ThreadContext *old_context);
165 void regStats(const std::string &name);
167 void serialize(std::ostream &os);
168 void unserialize(Checkpoint *cp, const std::string §ion);
171 EndQuiesceEvent *getQuiesceEvent();
173 Tick readLastActivate();
174 Tick readLastSuspend();
177 void profileSample();
182 // Also somewhat obnoxious. Really only used for the TLB fault.
183 TheISA::MachInst getInst();
185 void copyArchRegs(ThreadContext *tc);
187 void clearArchRegs();
189 uint64_t readIntReg(int reg_idx);
191 FloatReg readFloatReg(int reg_idx, int width);
193 FloatReg readFloatReg(int reg_idx);
195 FloatRegBits readFloatRegBits(int reg_idx, int width);
197 FloatRegBits readFloatRegBits(int reg_idx);
199 void setIntReg(int reg_idx, uint64_t val);
201 void setFloatReg(int reg_idx, FloatReg val, int width);
203 void setFloatReg(int reg_idx, FloatReg val);
205 void setFloatRegBits(int reg_idx, FloatRegBits val, int width);
207 void setFloatRegBits(int reg_idx, FloatRegBits val);
209 uint64_t readPC() { return thread->PC; }
210 void setPC(Addr val);
212 uint64_t readNextPC() { return thread->nextPC; }
213 void setNextPC(Addr val);
215 uint64_t readNextNPC()
220 void setNextNPC(uint64_t val)
225 MiscReg readMiscReg(int misc_reg);
227 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault);
229 Fault setMiscReg(int misc_reg, const MiscReg &val);
231 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val);
233 unsigned readStCondFailures()
234 { return thread->storeCondFailures; }
236 void setStCondFailures(unsigned sc_failures)
237 { thread->storeCondFailures = sc_failures; }
240 bool inPalMode() { return cpu->inPalMode(); }
243 bool misspeculating() { return false; }
246 TheISA::IntReg getSyscallArg(int i)
247 { return thread->renameTable[TheISA::ArgumentReg0 + i]->readIntResult(); }
249 // used to shift args for indirect syscall
250 void setSyscallArg(int i, TheISA::IntReg val)
251 { thread->renameTable[TheISA::ArgumentReg0 + i]->setIntResult(i); }
253 void setSyscallReturn(SyscallReturn return_value)
254 { cpu->setSyscallReturn(return_value, thread->readTid()); }
256 Counter readFuncExeInst() { return thread->funcExeInst; }
258 void setFuncExeInst(Counter new_val)
259 { thread->funcExeInst = new_val; }
261 void changeRegFileContext(TheISA::RegContextParam param,
262 TheISA::RegContextVal val)
263 { panic("Not supported on Alpha!"); }
266 // Ozone specific thread context
268 // Thread context to be used
270 // Checker thread context; will wrap the OzoneTC if a checker is
272 ThreadContext *checkerTC;
274 typedef OzoneThreadState<Impl> ImplState;
277 // Committed thread state for the OzoneCPU.
278 OzoneThreadState<Impl> thread;
281 // main simulation loop (one cycle)
284 std::set<InstSeqNum> snList;
285 std::set<Addr> lockAddrList;
287 struct TickEvent : public Event
292 TickEvent(OzoneCPU *c, int w);
294 const char *description();
299 /// Schedule tick event, regardless of its current state.
300 void scheduleTickEvent(int delay)
302 if (tickEvent.squashed())
303 tickEvent.reschedule(curTick + cycles(delay));
304 else if (!tickEvent.scheduled())
305 tickEvent.schedule(curTick + cycles(delay));
308 /// Unschedule tick event, regardless of its current state.
309 void unscheduleTickEvent()
311 if (tickEvent.scheduled())
325 void post_interrupt(int int_num, int index);
327 void zero_fill_64(Addr addr) {
328 static int warned = 0;
330 warn ("WH64 is not implemented");
335 typedef typename Impl::Params Params;
337 OzoneCPU(Params *params);
344 BaseCPU *getCpuPtr() { return this; }
346 void setCpuId(int id) { cpuId = id; }
348 int readCpuId() { return cpuId; }
353 void signalSwitched();
354 void takeOverFrom(BaseCPU *oldCPU);
359 Addr dbg_vtophys(Addr addr);
366 PhysicalMemory *physmem;
369 virtual Port *getPort(const std::string &name, int idx);
378 Status status() const { return _status; }
379 void setStatus(Status new_status) { _status = new_status; }
381 virtual void activateContext(int thread_num, int delay);
382 virtual void suspendContext(int thread_num);
383 virtual void deallocateContext(int thread_num, int delay);
384 virtual void haltContext(int thread_num);
387 virtual void regStats();
388 virtual void resetStats();
390 // number of simulated instructions
393 Counter startNumInst;
395 virtual Counter totalInstructions() const
397 return numInst - startNumInst;
401 // number of simulated loads
403 Counter startNumLoad;
405 // number of idle cycles
406 Stats::Average<> notIdleFraction;
407 Stats::Formula idleFraction;
410 virtual void serialize(std::ostream &os);
411 virtual void unserialize(Checkpoint *cp, const std::string §ion);
414 /** Translates instruction requestion. */
415 Fault translateInstReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
417 return itb->translate(req, thread->getTC());
420 /** Translates data read request. */
421 Fault translateDataReadReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
423 return dtb->translate(req, thread->getTC(), false);
426 /** Translates data write request. */
427 Fault translateDataWriteReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
429 return dtb->translate(req, thread->getTC(), true);
433 /** Translates instruction requestion in syscall emulation mode. */
434 Fault translateInstReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
436 return thread->getProcessPtr()->pTable->translate(req);
439 /** Translates data read request in syscall emulation mode. */
440 Fault translateDataReadReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
442 return thread->getProcessPtr()->pTable->translate(req);
445 /** Translates data write request in syscall emulation mode. */
446 Fault translateDataWriteReq(RequestPtr &req, OzoneThreadState<Impl> *thread)
448 return thread->getProcessPtr()->pTable->translate(req);
452 /** Old CPU read from memory function. No longer used. */
454 Fault read(Request *req, T &data)
457 #if FULL_SYSTEM && defined(TARGET_ALPHA)
458 if (req->flags & LOCKED) {
459 req->xc->setMiscReg(TheISA::Lock_Addr_DepTag, req->paddr);
460 req->xc->setMiscReg(TheISA::Lock_Flag_DepTag, true);
463 if (req->flags & LOCKED) {
464 lockAddrList.insert(req->paddr);
470 error = this->mem->read(req, data);
476 /** CPU read function, forwards read to LSQ. */
478 Fault read(Request *req, T &data, int load_idx)
480 return backEnd->read(req, data, load_idx);
483 /** Old CPU write to memory function. No longer used. */
485 Fault write(Request *req, T &data)
488 #if FULL_SYSTEM && defined(TARGET_ALPHA)
491 // If this is a store conditional, act appropriately
492 if (req->flags & LOCKED) {
495 if (req->flags & UNCACHEABLE) {
496 // Don't update result register (see stq_c in isa_desc)
498 xc->setStCondFailures(0);//Needed? [RGD]
500 bool lock_flag = xc->readMiscReg(TheISA::Lock_Flag_DepTag);
501 Addr lock_addr = xc->readMiscReg(TheISA::Lock_Addr_DepTag);
502 req->result = lock_flag;
504 ((lock_addr & ~0xf) != (req->paddr & ~0xf))) {
505 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
506 xc->setStCondFailures(xc->readStCondFailures() + 1);
507 if (((xc->readStCondFailures()) % 100000) == 0) {
508 std::cerr << "Warning: "
509 << xc->readStCondFailures()
510 << " consecutive store conditional failures "
511 << "on cpu " << req->xc->readCpuId()
516 else xc->setStCondFailures(0);
520 // Need to clear any locked flags on other proccessors for
521 // this address. Only do this for succsful Store Conditionals
522 // and all other stores (WH64?). Unsuccessful Store
523 // Conditionals would have returned above, and wouldn't fall
525 for (int i = 0; i < this->system->threadContexts.size(); i++){
526 xc = this->system->threadContexts[i];
527 if ((xc->readMiscReg(TheISA::Lock_Addr_DepTag) & ~0xf) ==
528 (req->paddr & ~0xf)) {
529 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
535 if (req->flags & LOCKED) {
536 if (req->flags & UNCACHEABLE) {
539 if (this->lockFlag) {
540 if (lockAddrList.find(req->paddr) !=
541 lockAddrList.end()) {
555 return this->mem->write(req, (T)htog(data));
558 /** CPU write function, forwards write to LSQ. */
560 Fault write(Request *req, T &data, int store_idx)
562 return backEnd->write(req, data, store_idx);
565 void prefetch(Addr addr, unsigned flags)
567 // need to do this...
570 void writeHint(Addr addr, int size, unsigned flags)
572 // need to do this...
575 Fault copySrcTranslate(Addr src);
577 Fault copy(Addr dest);
582 void dumpInsts() { frontEnd->dumpInsts(); }
586 int readIntrFlag() { return thread.intrflag; }
587 void setIntrFlag(int val) { thread.intrflag = val; }
588 bool inPalMode() { return AlphaISA::PcPAL(thread.PC); }
589 bool inPalMode(Addr pc) { return AlphaISA::PcPAL(pc); }
590 bool simPalCheck(int palFunc);
591 void processInterrupts();
593 void syscall(uint64_t &callnum);
594 void setSyscallReturn(SyscallReturn return_value, int tid);
597 ThreadContext *tcBase() { return tc; }
600 InstSeqNum doneSeqNum;
601 InstSeqNum nonSpecSeqNum;
608 InstSeqNum globalSeqNum;
610 TimeBuffer<CommStruct> comm;
612 bool decoupledFrontEnd;
616 Stats::Scalar<> quiesceCycles;
618 Checker<DynInstPtr> *checker;
621 #endif // __CPU_OZONE_CPU_HH__