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 "arch/faults.hh"
40 #include "cpu/exetrace.hh"
41 #include "mem/request.hh"
43 #include "cpu/base_dyn_inst.hh"
46 using namespace TheISA;
51 #include "base/hashmap.hh"
53 unsigned int MyHashFunc(const BaseDynInst *addr)
55 unsigned a = (unsigned)addr;
56 unsigned hash = (((a >> 14) ^ ((a >> 2) & 0xffff))) & 0x7FFFFFFF;
61 typedef m5::hash_map<const BaseDynInst *, const BaseDynInst *, MyHashFunc>
68 BaseDynInst<Impl>::BaseDynInst(ExtMachInst machInst, Addr inst_PC,
69 Addr pred_PC, InstSeqNum seq_num,
71 : staticInst(machInst), traceData(NULL), cpu(cpu)
76 nextPC = PC + sizeof(MachInst);
83 BaseDynInst<Impl>::BaseDynInst(StaticInstPtr &_staticInst)
84 : staticInst(_staticInst), traceData(NULL)
92 BaseDynInst<Impl>::initVars()
101 instResult.integer = 0;
111 // Eventually make this a parameter.
114 // Also make this a parameter, or perhaps get it from xc or cpu.
117 // Initialize the fault to be NoFault.
122 if (instcount > 1500) {
127 assert(instcount <= 1500);
130 DPRINTF(DynInst, "DynInst: [sn:%lli] Instruction created. Instcount=%i\n",
134 cpu->snList.insert(seqNum);
138 template <class Impl>
139 BaseDynInst<Impl>::~BaseDynInst()
157 DPRINTF(DynInst, "DynInst: [sn:%lli] Instruction destroyed. Instcount=%i\n",
160 cpu->snList.erase(seqNum);
165 template <class Impl>
167 BaseDynInst<Impl>::dumpSNList()
169 std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin();
172 while (sn_it != cpu->snList.end()) {
173 cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it));
180 template <class Impl>
182 BaseDynInst<Impl>::prefetch(Addr addr, unsigned flags)
184 // This is the "functional" implementation of prefetch. Not much
185 // happens here since prefetches don't affect the architectural
188 // Generate a MemReq so we can translate the effective address.
189 MemReqPtr req = new MemReq(addr, thread->getXCProxy(), 1, flags);
192 // Prefetches never cause faults.
195 // note this is a local, not BaseDynInst::fault
196 Fault trans_fault = cpu->translateDataReadReq(req);
198 if (trans_fault == NoFault && !(req->flags & UNCACHEABLE)) {
199 // It's a valid address to cacheable space. Record key MemReq
200 // parameters so we can generate another one just like it for
201 // the timing access without calling translate() again (which
202 // might mess up the TLB).
203 effAddr = req->vaddr;
204 physEffAddr = req->paddr;
205 memReqFlags = req->flags;
207 // Bogus address (invalid or uncacheable space). Mark it by
208 // setting the eff_addr to InvalidAddr.
209 effAddr = physEffAddr = MemReq::inval_addr;
213 traceData->setAddr(addr);
218 template <class Impl>
220 BaseDynInst<Impl>::writeHint(Addr addr, int size, unsigned flags)
222 // Not currently supported.
226 * @todo Need to find a way to get the cache block size here.
228 template <class Impl>
230 BaseDynInst<Impl>::copySrcTranslate(Addr src)
232 // Not currently supported.
237 * @todo Need to find a way to get the cache block size here.
239 template <class Impl>
241 BaseDynInst<Impl>::copy(Addr dest)
243 // Not currently supported.
247 template <class Impl>
249 BaseDynInst<Impl>::dump()
251 cprintf("T%d : %#08d `", threadNumber, PC);
252 cout << staticInst->disassemble(PC);
256 template <class Impl>
258 BaseDynInst<Impl>::dump(std::string &outstring)
260 std::ostringstream s;
261 s << "T" << threadNumber << " : 0x" << PC << " "
262 << staticInst->disassemble(PC);
267 template <class Impl>
269 BaseDynInst<Impl>::markSrcRegReady()
271 if (++readyRegs == numSrcRegs()) {
272 status.set(CanIssue);
276 template <class Impl>
278 BaseDynInst<Impl>::markSrcRegReady(RegIndex src_idx)
280 _readySrcRegIdx[src_idx] = true;
285 template <class Impl>
287 BaseDynInst<Impl>::eaSrcsReady()
289 // For now I am assuming that src registers 1..n-1 are the ones that the
290 // EA calc depends on. (i.e. src reg 0 is the source of the data to be
293 for (int i = 1; i < numSrcRegs(); ++i) {
294 if (!_readySrcRegIdx[i])