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"
38 #include "config/the_isa.hh"
39 #include "cpu/base_dyn_inst.hh"
40 #include "cpu/exetrace.hh"
41 #include "mem/request.hh"
42 #include "sim/faults.hh"
47 #include "base/hashmap.hh"
49 unsigned int MyHashFunc(const BaseDynInst *addr)
51 unsigned a = (unsigned)addr;
52 unsigned hash = (((a >> 14) ^ ((a >> 2) & 0xffff))) & 0x7FFFFFFF;
57 typedef m5::hash_map<const BaseDynInst *, const BaseDynInst *, MyHashFunc>
64 BaseDynInst<Impl>::BaseDynInst(StaticInstPtr _staticInst,
65 Addr inst_PC, Addr inst_NPC,
67 Addr pred_PC, Addr pred_NPC,
69 InstSeqNum seq_num, ImplCPU *cpu)
70 : staticInst(_staticInst), traceData(NULL), cpu(cpu)
75 staticInst->isMicroop() && !staticInst->isLastMicroop();
78 microPC = inst_MicroPC;
82 nextMicroPC = microPC + 1;
85 nextNPC = nextPC + sizeof(TheISA::MachInst);
90 predMicroPC = pred_MicroPC;
97 BaseDynInst<Impl>::BaseDynInst(TheISA::ExtMachInst inst,
98 Addr inst_PC, Addr inst_NPC,
100 Addr pred_PC, Addr pred_NPC,
102 InstSeqNum seq_num, ImplCPU *cpu)
103 : staticInst(inst, inst_PC), traceData(NULL), cpu(cpu)
108 staticInst->isMicroop() && !staticInst->isLastMicroop();
111 microPC = inst_MicroPC;
115 nextMicroPC = microPC + 1;
118 nextNPC = nextPC + sizeof(TheISA::MachInst);
123 predMicroPC = pred_MicroPC;
129 template <class Impl>
130 BaseDynInst<Impl>::BaseDynInst(StaticInstPtr &_staticInst)
131 : staticInst(_staticInst), traceData(NULL)
137 template <class Impl>
139 BaseDynInst<Impl>::initVars()
143 effAddrValid = false;
146 isUncacheable = false;
150 instResult.integer = 0;
161 // Eventually make this a parameter.
164 // Also make this a parameter, or perhaps get it from xc or cpu.
167 // Initialize the fault to be NoFault.
173 if (cpu->instcount > 1500) {
178 assert(cpu->instcount <= 1500);
182 "DynInst: [sn:%lli] Instruction created. Instcount for %s = %i\n",
183 seqNum, cpu->name(), cpu->instcount);
187 cpu->snList.insert(seqNum);
191 template <class Impl>
192 BaseDynInst<Impl>::~BaseDynInst()
208 "DynInst: [sn:%lli] Instruction destroyed. Instcount for %s = %i\n",
209 seqNum, cpu->name(), cpu->instcount);
212 cpu->snList.erase(seqNum);
217 template <class Impl>
219 BaseDynInst<Impl>::dumpSNList()
221 std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin();
224 while (sn_it != cpu->snList.end()) {
225 cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it));
232 template <class Impl>
234 BaseDynInst<Impl>::prefetch(Addr addr, unsigned flags)
236 // This is the "functional" implementation of prefetch. Not much
237 // happens here since prefetches don't affect the architectural
240 // Generate a MemReq so we can translate the effective address.
241 MemReqPtr req = new MemReq(addr, thread->getXCProxy(), 1, flags);
244 // Prefetches never cause faults.
247 // note this is a local, not BaseDynInst::fault
248 Fault trans_fault = cpu->translateDataReadReq(req);
250 if (trans_fault == NoFault && !(req->isUncacheable())) {
251 // It's a valid address to cacheable space. Record key MemReq
252 // parameters so we can generate another one just like it for
253 // the timing access without calling translate() again (which
254 // might mess up the TLB).
255 effAddr = req->vaddr;
256 physEffAddr = req->paddr;
257 memReqFlags = req->flags;
259 // Bogus address (invalid or uncacheable space). Mark it by
260 // setting the eff_addr to InvalidAddr.
261 effAddr = physEffAddr = MemReq::inval_addr;
265 traceData->setAddr(addr);
270 template <class Impl>
272 BaseDynInst<Impl>::writeHint(Addr addr, int size, unsigned flags)
274 // Not currently supported.
278 * @todo Need to find a way to get the cache block size here.
280 template <class Impl>
282 BaseDynInst<Impl>::copySrcTranslate(Addr src)
284 // Not currently supported.
289 * @todo Need to find a way to get the cache block size here.
291 template <class Impl>
293 BaseDynInst<Impl>::copy(Addr dest)
295 // Not currently supported.
299 template <class Impl>
301 BaseDynInst<Impl>::dump()
303 cprintf("T%d : %#08d `", threadNumber, PC);
304 std::cout << staticInst->disassemble(PC);
308 template <class Impl>
310 BaseDynInst<Impl>::dump(std::string &outstring)
312 std::ostringstream s;
313 s << "T" << threadNumber << " : 0x" << PC << " "
314 << staticInst->disassemble(PC);
319 template <class Impl>
321 BaseDynInst<Impl>::markSrcRegReady()
323 if (++readyRegs == numSrcRegs()) {
328 template <class Impl>
330 BaseDynInst<Impl>::markSrcRegReady(RegIndex src_idx)
332 _readySrcRegIdx[src_idx] = true;
337 template <class Impl>
339 BaseDynInst<Impl>::eaSrcsReady()
341 // For now I am assuming that src registers 1..n-1 are the ones that the
342 // EA calc depends on. (i.e. src reg 0 is the source of the data to be
345 for (int i = 1; i < numSrcRegs(); ++i) {
346 if (!_readySrcRegIdx[i])