2 * Copyright (c) 2005 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 "cpu/base.hh"
40 #include "cpu/thread_context.hh"
41 #include "cpu/inst_seq.hh"
42 #include "cpu/ozone/rename_table.hh"
43 #include "cpu/ozone/thread_state.hh"
44 #include "cpu/pc_event.hh"
45 #include "cpu/static_inst.hh"
46 #include "sim/eventq.hh"
48 // forward declarations
50 #include "arch/alpha/tlb.hh"
55 class MemoryController;
72 class EndQuiesceEvent;
83 * Declaration of Out-of-Order CPU class. Basically it is a SimpleCPU with
84 * simple out-of-order capabilities added to it. It is still a 1 CPI machine
85 * (?), but is capable of handling cache misses. Basically it models having
86 * a ROB/IQ by only allowing a certain amount of instructions to execute while
87 * the cache miss is outstanding.
91 class OzoneCPU : public BaseCPU
94 typedef typename Impl::FrontEnd FrontEnd;
95 typedef typename Impl::BackEnd BackEnd;
96 typedef typename Impl::DynInst DynInst;
97 typedef typename Impl::DynInstPtr DynInstPtr;
99 typedef TheISA::FloatReg FloatReg;
100 typedef TheISA::FloatRegBits FloatRegBits;
101 typedef TheISA::MiscReg MiscReg;
104 class OzoneTC : public ThreadContext {
108 OzoneThreadState<Impl> *thread;
110 BaseCPU *getCpuPtr();
112 void setCpuId(int id);
114 int readCpuId() { return thread->cpuId; }
117 System *getSystemPtr() { return cpu->system; }
119 PhysicalMemory *getPhysMemPtr() { return cpu->physmem; }
121 AlphaITB *getITBPtr() { return cpu->itb; }
123 AlphaDTB * getDTBPtr() { return cpu->dtb; }
125 Kernel::Statistics *getKernelStats() { return thread->kernelStats; }
127 FunctionalPort *getPhysPort() { return thread->getPhysPort(); }
129 VirtualPort *getVirtPort(ThreadContext *tc = NULL)
130 { return thread->getVirtPort(tc); }
132 void delVirtPort(VirtualPort *vp)
133 { thread->delVirtPort(vp); }
135 TranslatingPort *getMemPort() { return thread->port; }
137 Process *getProcessPtr() { return thread->process; }
140 Status status() const { return thread->_status; }
142 void setStatus(Status new_status);
144 /// Set the status to Active. Optional delay indicates number of
145 /// cycles to wait before beginning execution.
146 void activate(int delay = 1);
148 /// Set the status to Suspended.
151 /// Set the status to Unallocated.
154 /// Set the status to Halted.
158 void dumpFuncProfile();
161 void takeOverFrom(ThreadContext *old_context);
163 void regStats(const std::string &name);
165 void serialize(std::ostream &os);
166 void unserialize(Checkpoint *cp, const std::string §ion);
169 EndQuiesceEvent *getQuiesceEvent();
171 Tick readLastActivate();
172 Tick readLastSuspend();
175 void profileSample();
180 // Also somewhat obnoxious. Really only used for the TLB fault.
181 TheISA::MachInst getInst();
183 void copyArchRegs(ThreadContext *tc);
185 void clearArchRegs();
187 uint64_t readIntReg(int reg_idx);
189 FloatReg readFloatReg(int reg_idx, int width);
191 FloatReg readFloatReg(int reg_idx);
193 FloatRegBits readFloatRegBits(int reg_idx, int width);
195 FloatRegBits readFloatRegBits(int reg_idx);
197 void setIntReg(int reg_idx, uint64_t val);
199 void setFloatReg(int reg_idx, FloatReg val, int width);
201 void setFloatReg(int reg_idx, FloatReg val);
203 void setFloatRegBits(int reg_idx, FloatRegBits val, int width);
205 void setFloatRegBits(int reg_idx, FloatRegBits val);
207 uint64_t readPC() { return thread->PC; }
208 void setPC(Addr val);
210 uint64_t readNextPC() { return thread->nextPC; }
211 void setNextPC(Addr val);
213 uint64_t readNextNPC()
215 panic("Alpha has no NextNPC!");
219 void setNextNPC(uint64_t val)
220 { panic("Alpha has no NextNPC!"); }
224 MiscReg readMiscReg(int misc_reg);
226 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault);
228 Fault setMiscReg(int misc_reg, const MiscReg &val);
230 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val);
232 unsigned readStCondFailures()
233 { return thread->storeCondFailures; }
235 void setStCondFailures(unsigned sc_failures)
236 { thread->storeCondFailures = sc_failures; }
239 bool inPalMode() { return cpu->inPalMode(); }
242 bool misspeculating() { return false; }
245 TheISA::IntReg getSyscallArg(int i)
246 { return thread->renameTable[TheISA::ArgumentReg0 + i]->readIntResult(); }
248 // used to shift args for indirect syscall
249 void setSyscallArg(int i, TheISA::IntReg val)
250 { thread->renameTable[TheISA::ArgumentReg0 + i]->setIntResult(i); }
252 void setSyscallReturn(SyscallReturn return_value)
253 { cpu->setSyscallReturn(return_value, thread->tid); }
255 Counter readFuncExeInst() { return thread->funcExeInst; }
257 void setFuncExeInst(Counter new_val)
258 { thread->funcExeInst = new_val; }
260 void changeRegFileContext(TheISA::RegFile::ContextParam param,
261 TheISA::RegFile::ContextVal val)
262 { panic("Not supported on Alpha!"); }
265 // Ozone specific thread context
267 // Thread context to be used
269 // Checker thread context; will wrap the OzoneTC if a checker is
271 ThreadContext *checkerTC;
273 typedef OzoneThreadState<Impl> ImplState;
276 OzoneThreadState<Impl> thread;
279 // main simulation loop (one cycle)
282 std::set<InstSeqNum> snList;
283 std::set<Addr> lockAddrList;
285 struct TickEvent : public Event
290 TickEvent(OzoneCPU *c, int w);
292 const char *description();
297 /// Schedule tick event, regardless of its current state.
298 void scheduleTickEvent(int delay)
300 if (tickEvent.squashed())
301 tickEvent.reschedule(curTick + cycles(delay));
302 else if (!tickEvent.scheduled())
303 tickEvent.schedule(curTick + cycles(delay));
306 /// Unschedule tick event, regardless of its current state.
307 void unscheduleTickEvent()
309 if (tickEvent.scheduled())
314 Trace::InstRecord *traceData;
317 void trace_data(T data);
329 bool checkInterrupts;
331 void post_interrupt(int int_num, int index);
333 void zero_fill_64(Addr addr) {
334 static int warned = 0;
336 warn ("WH64 is not implemented");
341 typedef typename Impl::Params Params;
343 OzoneCPU(Params *params);
350 BaseCPU *getCpuPtr() { return this; }
352 void setCpuId(int id) { cpuId = id; }
354 int readCpuId() { return cpuId; }
358 void switchOut(Sampler *sampler);
359 void signalSwitched();
360 void takeOverFrom(BaseCPU *oldCPU);
367 Addr dbg_vtophys(Addr addr);
374 PhysicalMemory *physmem;
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);
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);
418 bool validInstAddr(Addr addr) { return true; }
419 bool validDataAddr(Addr addr) { return true; }
421 Fault translateInstReq(Request *req)
423 return itb->translate(req, tc);
426 Fault translateDataReadReq(Request *req)
428 return dtb->translate(req, tc, false);
431 Fault translateDataWriteReq(Request *req)
433 return dtb->translate(req, tc, true);
437 bool validInstAddr(Addr addr)
440 bool validDataAddr(Addr addr)
443 int getInstAsid() { return thread.asid; }
444 int getDataAsid() { return thread.asid; }
446 /** Translates instruction requestion in syscall emulation mode. */
447 Fault translateInstReq(Request *req)
449 return thread.translateInstReq(req);
452 /** Translates data read request in syscall emulation mode. */
453 Fault translateDataReadReq(Request *req)
455 return thread.translateDataReadReq(req);
458 /** Translates data write request in syscall emulation mode. */
459 Fault translateDataWriteReq(Request *req)
461 return thread.translateDataWriteReq(req);
465 /** Old CPU read from memory function. No longer used. */
467 Fault read(Request *req, T &data)
470 #if FULL_SYSTEM && defined(TARGET_ALPHA)
471 if (req->flags & LOCKED) {
472 req->xc->setMiscReg(TheISA::Lock_Addr_DepTag, req->paddr);
473 req->xc->setMiscReg(TheISA::Lock_Flag_DepTag, true);
476 if (req->flags & LOCKED) {
477 lockAddrList.insert(req->paddr);
483 error = this->mem->read(req, data);
489 /** CPU read function, forwards read to LSQ. */
491 Fault read(Request *req, T &data, int load_idx)
493 return backEnd->read(req, data, load_idx);
496 /** Old CPU write to memory function. No longer used. */
498 Fault write(Request *req, T &data)
501 #if FULL_SYSTEM && defined(TARGET_ALPHA)
504 // If this is a store conditional, act appropriately
505 if (req->flags & LOCKED) {
508 if (req->flags & UNCACHEABLE) {
509 // Don't update result register (see stq_c in isa_desc)
511 xc->setStCondFailures(0);//Needed? [RGD]
513 bool lock_flag = xc->readMiscReg(TheISA::Lock_Flag_DepTag);
514 Addr lock_addr = xc->readMiscReg(TheISA::Lock_Addr_DepTag);
515 req->result = lock_flag;
517 ((lock_addr & ~0xf) != (req->paddr & ~0xf))) {
518 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
519 xc->setStCondFailures(xc->readStCondFailures() + 1);
520 if (((xc->readStCondFailures()) % 100000) == 0) {
521 std::cerr << "Warning: "
522 << xc->readStCondFailures()
523 << " consecutive store conditional failures "
524 << "on cpu " << req->xc->readCpuId()
529 else xc->setStCondFailures(0);
533 // Need to clear any locked flags on other proccessors for
534 // this address. Only do this for succsful Store Conditionals
535 // and all other stores (WH64?). Unsuccessful Store
536 // Conditionals would have returned above, and wouldn't fall
538 for (int i = 0; i < this->system->threadContexts.size(); i++){
539 xc = this->system->threadContexts[i];
540 if ((xc->readMiscReg(TheISA::Lock_Addr_DepTag) & ~0xf) ==
541 (req->paddr & ~0xf)) {
542 xc->setMiscReg(TheISA::Lock_Flag_DepTag, false);
548 if (req->flags & LOCKED) {
549 if (req->flags & UNCACHEABLE) {
552 if (this->lockFlag) {
553 if (lockAddrList.find(req->paddr) !=
554 lockAddrList.end()) {
568 return this->mem->write(req, (T)htog(data));
571 /** CPU write function, forwards write to LSQ. */
573 Fault write(Request *req, T &data, int store_idx)
575 return backEnd->write(req, data, store_idx);
578 void prefetch(Addr addr, unsigned flags)
580 // need to do this...
583 void writeHint(Addr addr, int size, unsigned flags)
585 // need to do this...
588 Fault copySrcTranslate(Addr src);
590 Fault copy(Addr dest);
592 InstSeqNum globalSeqNum;
597 // @todo: This can be a useful debug function. Implement it.
598 void dumpInsts() { frontEnd->dumpInsts(); }
602 int readIntrFlag() { return thread.regs.intrflag; }
603 void setIntrFlag(int val) { thread.regs.intrflag = val; }
604 bool inPalMode() { return AlphaISA::PcPAL(thread.PC); }
605 bool inPalMode(Addr pc) { return AlphaISA::PcPAL(pc); }
606 bool simPalCheck(int palFunc);
607 void processInterrupts();
610 void setSyscallReturn(SyscallReturn return_value, int tid);
613 ThreadContext *tcBase() { return tc; }
615 bool decoupledFrontEnd;
617 InstSeqNum doneSeqNum;
618 InstSeqNum nonSpecSeqNum;
624 TimeBuffer<CommStruct> comm;
628 Stats::Scalar<> quiesceCycles;
630 Checker<DynInstPtr> *checker;
633 #endif // __CPU_OZONE_CPU_HH__