2 * Copyright (c) 2004-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.
36 #include "base/cprintf.hh"
37 #include "base/trace.hh"
39 #include "sim/faults.hh"
40 #include "cpu/exetrace.hh"
41 #include "mem/request.hh"
43 #include "cpu/base_dyn_inst.hh"
48 #include "base/hashmap.hh"
50 unsigned int MyHashFunc(const BaseDynInst *addr)
52 unsigned a = (unsigned)addr;
53 unsigned hash = (((a >> 14) ^ ((a >> 2) & 0xffff))) & 0x7FFFFFFF;
58 typedef m5::hash_map<const BaseDynInst *, const BaseDynInst *, MyHashFunc>
65 BaseDynInst<Impl>::BaseDynInst(StaticInstPtr _staticInst,
66 Addr inst_PC, Addr inst_NPC,
68 Addr pred_PC, Addr pred_NPC,
70 InstSeqNum seq_num, ImplCPU *cpu)
71 : staticInst(_staticInst), traceData(NULL), cpu(cpu)
76 staticInst->isMicroop() && !staticInst->isLastMicroop();
79 microPC = inst_MicroPC;
83 nextMicroPC = microPC + 1;
86 nextNPC = nextPC + sizeof(TheISA::MachInst);
91 predMicroPC = pred_MicroPC;
98 BaseDynInst<Impl>::BaseDynInst(TheISA::ExtMachInst inst,
99 Addr inst_PC, Addr inst_NPC,
101 Addr pred_PC, Addr pred_NPC,
103 InstSeqNum seq_num, ImplCPU *cpu)
104 : staticInst(inst, inst_PC), traceData(NULL), cpu(cpu)
109 staticInst->isMicroop() && !staticInst->isLastMicroop();
112 microPC = inst_MicroPC;
116 nextMicroPC = microPC + 1;
119 nextNPC = nextPC + sizeof(TheISA::MachInst);
124 predMicroPC = pred_MicroPC;
130 template <class Impl>
131 BaseDynInst<Impl>::BaseDynInst(StaticInstPtr &_staticInst)
132 : staticInst(_staticInst), traceData(NULL)
138 template <class Impl>
140 BaseDynInst<Impl>::initVars()
144 effAddrValid = false;
147 isUncacheable = false;
151 instResult.integer = 0;
162 // Eventually make this a parameter.
165 // Also make this a parameter, or perhaps get it from xc or cpu.
168 // Initialize the fault to be NoFault.
174 if (cpu->instcount > 1500) {
179 assert(cpu->instcount <= 1500);
183 "DynInst: [sn:%lli] Instruction created. Instcount for %s = %i\n",
184 seqNum, cpu->name(), cpu->instcount);
188 cpu->snList.insert(seqNum);
192 template <class Impl>
193 BaseDynInst<Impl>::~BaseDynInst()
209 "DynInst: [sn:%lli] Instruction destroyed. Instcount for %s = %i\n",
210 seqNum, cpu->name(), cpu->instcount);
213 cpu->snList.erase(seqNum);
218 template <class Impl>
220 BaseDynInst<Impl>::dumpSNList()
222 std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin();
225 while (sn_it != cpu->snList.end()) {
226 cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it));
233 template <class Impl>
235 BaseDynInst<Impl>::prefetch(Addr addr, unsigned flags)
237 // This is the "functional" implementation of prefetch. Not much
238 // happens here since prefetches don't affect the architectural
241 // Generate a MemReq so we can translate the effective address.
242 MemReqPtr req = new MemReq(addr, thread->getXCProxy(), 1, flags);
245 // Prefetches never cause faults.
248 // note this is a local, not BaseDynInst::fault
249 Fault trans_fault = cpu->translateDataReadReq(req);
251 if (trans_fault == NoFault && !(req->isUncacheable())) {
252 // It's a valid address to cacheable space. Record key MemReq
253 // parameters so we can generate another one just like it for
254 // the timing access without calling translate() again (which
255 // might mess up the TLB).
256 effAddr = req->vaddr;
257 physEffAddr = req->paddr;
258 memReqFlags = req->flags;
260 // Bogus address (invalid or uncacheable space). Mark it by
261 // setting the eff_addr to InvalidAddr.
262 effAddr = physEffAddr = MemReq::inval_addr;
266 traceData->setAddr(addr);
271 template <class Impl>
273 BaseDynInst<Impl>::writeHint(Addr addr, int size, unsigned flags)
275 // Not currently supported.
279 * @todo Need to find a way to get the cache block size here.
281 template <class Impl>
283 BaseDynInst<Impl>::copySrcTranslate(Addr src)
285 // Not currently supported.
290 * @todo Need to find a way to get the cache block size here.
292 template <class Impl>
294 BaseDynInst<Impl>::copy(Addr dest)
296 // Not currently supported.
300 template <class Impl>
302 BaseDynInst<Impl>::dump()
304 cprintf("T%d : %#08d `", threadNumber, PC);
305 std::cout << staticInst->disassemble(PC);
309 template <class Impl>
311 BaseDynInst<Impl>::dump(std::string &outstring)
313 std::ostringstream s;
314 s << "T" << threadNumber << " : 0x" << PC << " "
315 << staticInst->disassemble(PC);
320 template <class Impl>
322 BaseDynInst<Impl>::markSrcRegReady()
324 if (++readyRegs == numSrcRegs()) {
329 template <class Impl>
331 BaseDynInst<Impl>::markSrcRegReady(RegIndex src_idx)
333 _readySrcRegIdx[src_idx] = true;
338 template <class Impl>
340 BaseDynInst<Impl>::eaSrcsReady()
342 // For now I am assuming that src registers 1..n-1 are the ones that the
343 // EA calc depends on. (i.e. src reg 0 is the source of the data to be
346 for (int i = 1; i < numSrcRegs(); ++i) {
347 if (!_readySrcRegIdx[i])