base_dyn_inst_impl.hh revision 3801
11060SN/A/*
22702SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
31060SN/A * All rights reserved.
41060SN/A *
51060SN/A * Redistribution and use in source and binary forms, with or without
61060SN/A * modification, are permitted provided that the following conditions are
71060SN/A * met: redistributions of source code must retain the above copyright
81060SN/A * notice, this list of conditions and the following disclaimer;
91060SN/A * redistributions in binary form must reproduce the above copyright
101060SN/A * notice, this list of conditions and the following disclaimer in the
111060SN/A * documentation and/or other materials provided with the distribution;
121060SN/A * neither the name of the copyright holders nor the names of its
131060SN/A * contributors may be used to endorse or promote products derived from
141060SN/A * this software without specific prior written permission.
151060SN/A *
161060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665SN/A *
282665SN/A * Authors: Kevin Lim
291060SN/A */
301060SN/A
311060SN/A#include <iostream>
322292SN/A#include <set>
331060SN/A#include <string>
341060SN/A#include <sstream>
351060SN/A
361060SN/A#include "base/cprintf.hh"
371061SN/A#include "base/trace.hh"
381060SN/A
392980Sgblack@eecs.umich.edu#include "sim/faults.hh"
401060SN/A#include "cpu/exetrace.hh"
412669SN/A#include "mem/request.hh"
421060SN/A
431060SN/A#include "cpu/base_dyn_inst.hh"
441060SN/A
451060SN/A#define NOHASH
461060SN/A#ifndef NOHASH
471060SN/A
481060SN/A#include "base/hashmap.hh"
491060SN/A
501060SN/Aunsigned int MyHashFunc(const BaseDynInst *addr)
511060SN/A{
522292SN/A    unsigned a = (unsigned)addr;
532292SN/A    unsigned hash = (((a >> 14) ^ ((a >> 2) & 0xffff))) & 0x7FFFFFFF;
541060SN/A
552292SN/A    return hash;
561060SN/A}
571060SN/A
582292SN/Atypedef m5::hash_map<const BaseDynInst *, const BaseDynInst *, MyHashFunc>
592292SN/Amy_hash_t;
602292SN/A
611060SN/Amy_hash_t thishash;
621060SN/A#endif
631060SN/A
641061SN/Atemplate <class Impl>
653801Sgblack@eecs.umich.eduBaseDynInst<Impl>::BaseDynInst(TheISA::ExtMachInst machInst,
663801Sgblack@eecs.umich.edu                               Addr inst_PC, Addr inst_NPC,
673794Sgblack@eecs.umich.edu                               Addr pred_PC, Addr pred_NPC,
683794Sgblack@eecs.umich.edu                               InstSeqNum seq_num, ImplCPU *cpu)
692733SN/A  : staticInst(machInst), traceData(NULL), cpu(cpu)
701060SN/A{
711464SN/A    seqNum = seq_num;
721061SN/A
731464SN/A    PC = inst_PC;
743801Sgblack@eecs.umich.edu    nextPC = inst_NPC;
752980Sgblack@eecs.umich.edu    nextNPC = nextPC + sizeof(TheISA::MachInst);
761464SN/A    predPC = pred_PC;
773794Sgblack@eecs.umich.edu    predNPC = pred_NPC;
783794Sgblack@eecs.umich.edu    predTaken = false;
791464SN/A
801464SN/A    initVars();
811464SN/A}
821464SN/A
831464SN/Atemplate <class Impl>
842107SN/ABaseDynInst<Impl>::BaseDynInst(StaticInstPtr &_staticInst)
851464SN/A    : staticInst(_staticInst), traceData(NULL)
861464SN/A{
872292SN/A    seqNum = 0;
881464SN/A    initVars();
891464SN/A}
901464SN/A
911464SN/Atemplate <class Impl>
921464SN/Avoid
931464SN/ABaseDynInst<Impl>::initVars()
941464SN/A{
952292SN/A    req = NULL;
962678SN/A    memData = NULL;
972669SN/A    effAddr = 0;
982669SN/A    physEffAddr = 0;
991060SN/A
1001060SN/A    readyRegs = 0;
1011060SN/A
1022702SN/A    instResult.integer = 0;
1033326Sktlim@umich.edu    recordResult = true;
1042702SN/A
1052731SN/A    status.reset();
1062731SN/A
1071464SN/A    eaCalcDone = false;
1082292SN/A    memOpDone = false;
1092731SN/A
1102292SN/A    lqIdx = -1;
1112292SN/A    sqIdx = -1;
1122292SN/A
1131060SN/A    // Eventually make this a parameter.
1141060SN/A    threadNumber = 0;
1151464SN/A
1161060SN/A    // Also make this a parameter, or perhaps get it from xc or cpu.
1171060SN/A    asid = 0;
1181060SN/A
1192698SN/A    // Initialize the fault to be NoFault.
1202292SN/A    fault = NoFault;
1211060SN/A
1221060SN/A    ++instcount;
1231060SN/A
1242292SN/A    if (instcount > 1500) {
1252292SN/A        cpu->dumpInsts();
1262292SN/A#ifdef DEBUG
1272292SN/A        dumpSNList();
1282292SN/A#endif
1292292SN/A        assert(instcount <= 1500);
1302292SN/A    }
1312292SN/A
1322292SN/A    DPRINTF(DynInst, "DynInst: [sn:%lli] Instruction created. Instcount=%i\n",
1332292SN/A            seqNum, instcount);
1342292SN/A
1352292SN/A#ifdef DEBUG
1362292SN/A    cpu->snList.insert(seqNum);
1372292SN/A#endif
1381060SN/A}
1391060SN/A
1401061SN/Atemplate <class Impl>
1411060SN/ABaseDynInst<Impl>::~BaseDynInst()
1421060SN/A{
1432292SN/A    if (req) {
1442678SN/A        delete req;
1452678SN/A    }
1462678SN/A
1472678SN/A    if (memData) {
1482678SN/A        delete [] memData;
1492292SN/A    }
1502292SN/A
1512292SN/A    if (traceData) {
1522292SN/A        delete traceData;
1532292SN/A    }
1542292SN/A
1552348SN/A    fault = NoFault;
1562348SN/A
1571060SN/A    --instcount;
1582292SN/A
1592292SN/A    DPRINTF(DynInst, "DynInst: [sn:%lli] Instruction destroyed. Instcount=%i\n",
1602292SN/A            seqNum, instcount);
1612292SN/A#ifdef DEBUG
1622292SN/A    cpu->snList.erase(seqNum);
1632292SN/A#endif
1641060SN/A}
1651464SN/A
1662292SN/A#ifdef DEBUG
1672292SN/Atemplate <class Impl>
1682292SN/Avoid
1692292SN/ABaseDynInst<Impl>::dumpSNList()
1702292SN/A{
1712292SN/A    std::set<InstSeqNum>::iterator sn_it = cpu->snList.begin();
1722292SN/A
1732292SN/A    int count = 0;
1742292SN/A    while (sn_it != cpu->snList.end()) {
1752292SN/A        cprintf("%i: [sn:%lli] not destroyed\n", count, (*sn_it));
1762292SN/A        count++;
1772292SN/A        sn_it++;
1782292SN/A    }
1792292SN/A}
1802292SN/A#endif
1812292SN/A
1821061SN/Atemplate <class Impl>
1831060SN/Avoid
1841060SN/ABaseDynInst<Impl>::prefetch(Addr addr, unsigned flags)
1851060SN/A{
1861060SN/A    // This is the "functional" implementation of prefetch.  Not much
1871060SN/A    // happens here since prefetches don't affect the architectural
1881060SN/A    // state.
1892669SN/A/*
1901060SN/A    // Generate a MemReq so we can translate the effective address.
1912292SN/A    MemReqPtr req = new MemReq(addr, thread->getXCProxy(), 1, flags);
1921060SN/A    req->asid = asid;
1931060SN/A
1941060SN/A    // Prefetches never cause faults.
1952090SN/A    fault = NoFault;
1961060SN/A
1971060SN/A    // note this is a local, not BaseDynInst::fault
1982292SN/A    Fault trans_fault = cpu->translateDataReadReq(req);
1991060SN/A
2003172Sstever@eecs.umich.edu    if (trans_fault == NoFault && !(req->isUncacheable())) {
2011060SN/A        // It's a valid address to cacheable space.  Record key MemReq
2021060SN/A        // parameters so we can generate another one just like it for
2031060SN/A        // the timing access without calling translate() again (which
2041060SN/A        // might mess up the TLB).
2051060SN/A        effAddr = req->vaddr;
2061060SN/A        physEffAddr = req->paddr;
2071060SN/A        memReqFlags = req->flags;
2081060SN/A    } else {
2091060SN/A        // Bogus address (invalid or uncacheable space).  Mark it by
2101060SN/A        // setting the eff_addr to InvalidAddr.
2111060SN/A        effAddr = physEffAddr = MemReq::inval_addr;
2121060SN/A    }
2131060SN/A
2141060SN/A    if (traceData) {
2151060SN/A        traceData->setAddr(addr);
2161060SN/A    }
2172669SN/A*/
2181060SN/A}
2191060SN/A
2201061SN/Atemplate <class Impl>
2211060SN/Avoid
2221060SN/ABaseDynInst<Impl>::writeHint(Addr addr, int size, unsigned flags)
2231060SN/A{
2242702SN/A    // Not currently supported.
2251060SN/A}
2261060SN/A
2271060SN/A/**
2281060SN/A * @todo Need to find a way to get the cache block size here.
2291060SN/A */
2301061SN/Atemplate <class Impl>
2312132SN/AFault
2321060SN/ABaseDynInst<Impl>::copySrcTranslate(Addr src)
2331060SN/A{
2342702SN/A    // Not currently supported.
2352669SN/A    return NoFault;
2361060SN/A}
2371060SN/A
2381060SN/A/**
2391060SN/A * @todo Need to find a way to get the cache block size here.
2401060SN/A */
2411061SN/Atemplate <class Impl>
2422132SN/AFault
2431060SN/ABaseDynInst<Impl>::copy(Addr dest)
2441060SN/A{
2452702SN/A    // Not currently supported.
2462669SN/A    return NoFault;
2471060SN/A}
2481060SN/A
2491061SN/Atemplate <class Impl>
2501060SN/Avoid
2511060SN/ABaseDynInst<Impl>::dump()
2521060SN/A{
2531060SN/A    cprintf("T%d : %#08d `", threadNumber, PC);
2542980Sgblack@eecs.umich.edu    std::cout << staticInst->disassemble(PC);
2551060SN/A    cprintf("'\n");
2561060SN/A}
2571060SN/A
2581061SN/Atemplate <class Impl>
2591060SN/Avoid
2601060SN/ABaseDynInst<Impl>::dump(std::string &outstring)
2611060SN/A{
2621060SN/A    std::ostringstream s;
2631060SN/A    s << "T" << threadNumber << " : 0x" << PC << " "
2641060SN/A      << staticInst->disassemble(PC);
2651060SN/A
2661060SN/A    outstring = s.str();
2671060SN/A}
2681060SN/A
2691464SN/Atemplate <class Impl>
2702292SN/Avoid
2712292SN/ABaseDynInst<Impl>::markSrcRegReady()
2722292SN/A{
2732292SN/A    if (++readyRegs == numSrcRegs()) {
2742731SN/A        status.set(CanIssue);
2752292SN/A    }
2762292SN/A}
2772292SN/A
2782292SN/Atemplate <class Impl>
2792292SN/Avoid
2802292SN/ABaseDynInst<Impl>::markSrcRegReady(RegIndex src_idx)
2812292SN/A{
2822292SN/A    _readySrcRegIdx[src_idx] = true;
2832292SN/A
2842731SN/A    markSrcRegReady();
2852292SN/A}
2862292SN/A
2872292SN/Atemplate <class Impl>
2881464SN/Abool
2891464SN/ABaseDynInst<Impl>::eaSrcsReady()
2901464SN/A{
2911464SN/A    // For now I am assuming that src registers 1..n-1 are the ones that the
2921464SN/A    // EA calc depends on.  (i.e. src reg 0 is the source of the data to be
2931464SN/A    // stored)
2941464SN/A
2952292SN/A    for (int i = 1; i < numSrcRegs(); ++i) {
2961464SN/A        if (!_readySrcRegIdx[i])
2971464SN/A            return false;
2981464SN/A    }
2991464SN/A
3001464SN/A    return true;
3011464SN/A}
302