base.hh revision 5358
12SN/A/*
21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292665Ssaidi@eecs.umich.edu *          Dave Greene
302665Ssaidi@eecs.umich.edu *          Nathan Binkert
312SN/A */
322SN/A
332623SN/A#ifndef __CPU_SIMPLE_BASE_HH__
342623SN/A#define __CPU_SIMPLE_BASE_HH__
352SN/A
364182Sgblack@eecs.umich.edu#include "arch/predecoder.hh"
371354SN/A#include "base/statistics.hh"
381858SN/A#include "config/full_system.hh"
391717SN/A#include "cpu/base.hh"
402683Sktlim@umich.edu#include "cpu/simple_thread.hh"
411354SN/A#include "cpu/pc_event.hh"
421354SN/A#include "cpu/static_inst.hh"
432387SN/A#include "mem/packet.hh"
442387SN/A#include "mem/port.hh"
452387SN/A#include "mem/request.hh"
4656SN/A#include "sim/eventq.hh"
475348Ssaidi@eecs.umich.edu#include "sim/system.hh"
482SN/A
492SN/A// forward declarations
501858SN/A#if FULL_SYSTEM
512SN/Aclass Processor;
523453Sgblack@eecs.umich.edunamespace TheISA
533453Sgblack@eecs.umich.edu{
543453Sgblack@eecs.umich.edu    class ITB;
553453Sgblack@eecs.umich.edu    class DTB;
563453Sgblack@eecs.umich.edu}
572462SN/Aclass MemObject;
582SN/A
59715SN/A#else
60715SN/A
61715SN/Aclass Process;
62715SN/A
632SN/A#endif // FULL_SYSTEM
642SN/A
653960Sgblack@eecs.umich.educlass RemoteGDB;
663960Sgblack@eecs.umich.educlass GDBListener;
673960Sgblack@eecs.umich.edu
684182Sgblack@eecs.umich.edunamespace TheISA
694182Sgblack@eecs.umich.edu{
704182Sgblack@eecs.umich.edu    class Predecoder;
714182Sgblack@eecs.umich.edu}
722680Sktlim@umich.educlass ThreadContext;
73237SN/Aclass Checkpoint;
742SN/A
752SN/Anamespace Trace {
762SN/A    class InstRecord;
772SN/A}
782SN/A
792420SN/A
802623SN/Aclass BaseSimpleCPU : public BaseCPU
812SN/A{
822107SN/A  protected:
832159SN/A    typedef TheISA::MiscReg MiscReg;
842455SN/A    typedef TheISA::FloatReg FloatReg;
852455SN/A    typedef TheISA::FloatRegBits FloatRegBits;
862386SN/A
872623SN/A  protected:
882SN/A    Trace::InstRecord *traceData;
891371SN/A
905348Ssaidi@eecs.umich.edu    inline void checkPcEventQueue() {
915348Ssaidi@eecs.umich.edu        Addr oldpc;
925348Ssaidi@eecs.umich.edu        do {
935348Ssaidi@eecs.umich.edu            oldpc = thread->readPC();
945348Ssaidi@eecs.umich.edu            system->pcEventQueue.service(tc);
955348Ssaidi@eecs.umich.edu        } while (oldpc != thread->readPC());
965348Ssaidi@eecs.umich.edu    }
975348Ssaidi@eecs.umich.edu
982SN/A  public:
992SN/A    void post_interrupt(int int_num, int index);
1002SN/A
1012SN/A    void zero_fill_64(Addr addr) {
1022SN/A      static int warned = 0;
1032SN/A      if (!warned) {
1042SN/A        warn ("WH64 is not implemented");
1052SN/A        warned = 1;
1062SN/A      }
1072SN/A    };
1082SN/A
1091400SN/A  public:
1101400SN/A    struct Params : public BaseCPU::Params
1111400SN/A    {
1123453Sgblack@eecs.umich.edu        TheISA::ITB *itb;
1133453Sgblack@eecs.umich.edu        TheISA::DTB *dtb;
1144997Sgblack@eecs.umich.edu#if !FULL_SYSTEM
1151400SN/A        Process *process;
1162SN/A#endif
1171400SN/A    };
1182623SN/A    BaseSimpleCPU(Params *params);
1192623SN/A    virtual ~BaseSimpleCPU();
1202SN/A
1211400SN/A  public:
1222683Sktlim@umich.edu    /** SimpleThread object, provides all the architectural state. */
1232683Sktlim@umich.edu    SimpleThread *thread;
1242190SN/A
1252683Sktlim@umich.edu    /** ThreadContext object, provides an interface for external
1262683Sktlim@umich.edu     * objects to modify this thread's state.
1272683Sktlim@umich.edu     */
1282680Sktlim@umich.edu    ThreadContext *tc;
1295169Ssaidi@eecs.umich.edu  protected:
1305169Ssaidi@eecs.umich.edu    int cpuId;
1315169Ssaidi@eecs.umich.edu
1325169Ssaidi@eecs.umich.edu  public:
1332SN/A
1341858SN/A#if FULL_SYSTEM
1352SN/A    Addr dbg_vtophys(Addr addr);
1362SN/A
1372SN/A    bool interval_stats;
1382SN/A#endif
1392SN/A
1402SN/A    // current instruction
1414181Sgblack@eecs.umich.edu    TheISA::MachInst inst;
1424181Sgblack@eecs.umich.edu
1434182Sgblack@eecs.umich.edu    // The predecoder
1444182Sgblack@eecs.umich.edu    TheISA::Predecoder predecoder;
1452SN/A
1462107SN/A    StaticInstPtr curStaticInst;
1473276Sgblack@eecs.umich.edu    StaticInstPtr curMacroStaticInst;
1481469SN/A
1494377Sgblack@eecs.umich.edu    //This is the offset from the current pc that fetch should be performed at
1504377Sgblack@eecs.umich.edu    Addr fetchOffset;
1514377Sgblack@eecs.umich.edu    //This flag says to stay at the current pc. This is useful for
1524377Sgblack@eecs.umich.edu    //instructions which go beyond MachInst boundaries.
1534377Sgblack@eecs.umich.edu    bool stayAtPC;
1544377Sgblack@eecs.umich.edu
1552623SN/A    void checkForInterrupts();
1562662Sstever@eecs.umich.edu    Fault setupFetchRequest(Request *req);
1572623SN/A    void preExecute();
1582623SN/A    void postExecute();
1592623SN/A    void advancePC(Fault fault);
160180SN/A
161393SN/A    virtual void deallocateContext(int thread_num);
162393SN/A    virtual void haltContext(int thread_num);
1632SN/A
1642SN/A    // statistics
165334SN/A    virtual void regStats();
166334SN/A    virtual void resetStats();
1672SN/A
1682SN/A    // number of simulated instructions
1692SN/A    Counter numInst;
170334SN/A    Counter startNumInst;
171729SN/A    Stats::Scalar<> numInsts;
172707SN/A
1734998Sgblack@eecs.umich.edu    void countInst()
1744998Sgblack@eecs.umich.edu    {
1754998Sgblack@eecs.umich.edu        numInst++;
1764998Sgblack@eecs.umich.edu        numInsts++;
1774998Sgblack@eecs.umich.edu
1784998Sgblack@eecs.umich.edu        thread->funcExeInst++;
1794998Sgblack@eecs.umich.edu    }
1804998Sgblack@eecs.umich.edu
181707SN/A    virtual Counter totalInstructions() const
182707SN/A    {
183707SN/A        return numInst - startNumInst;
184707SN/A    }
1852SN/A
1864564Sgblack@eecs.umich.edu    // Mask to align PCs to MachInst sized boundaries
1874564Sgblack@eecs.umich.edu    static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1);
1884564Sgblack@eecs.umich.edu
1892SN/A    // number of simulated memory references
190729SN/A    Stats::Scalar<> numMemRefs;
1912SN/A
192124SN/A    // number of simulated loads
193124SN/A    Counter numLoad;
194334SN/A    Counter startNumLoad;
195124SN/A
1962SN/A    // number of idle cycles
197729SN/A    Stats::Average<> notIdleFraction;
198729SN/A    Stats::Formula idleFraction;
1992SN/A
2002390SN/A    // number of cycles stalled for I-cache responses
201729SN/A    Stats::Scalar<> icacheStallCycles;
2022SN/A    Counter lastIcacheStall;
2032SN/A
2042390SN/A    // number of cycles stalled for I-cache retries
2052390SN/A    Stats::Scalar<> icacheRetryCycles;
2062390SN/A    Counter lastIcacheRetry;
2072390SN/A
2082390SN/A    // number of cycles stalled for D-cache responses
209729SN/A    Stats::Scalar<> dcacheStallCycles;
2102SN/A    Counter lastDcacheStall;
2112SN/A
2122390SN/A    // number of cycles stalled for D-cache retries
2132390SN/A    Stats::Scalar<> dcacheRetryCycles;
2142390SN/A    Counter lastDcacheRetry;
2152390SN/A
216217SN/A    virtual void serialize(std::ostream &os);
217237SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
2182SN/A
2191371SN/A    // These functions are only used in CPU models that split
2201371SN/A    // effective address computation from the actual memory access.
2212623SN/A    void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); }
2223918Ssaidi@eecs.umich.edu    Addr getEA() 	{ panic("BaseSimpleCPU::getEA() not implemented\n");
2233918Ssaidi@eecs.umich.edu        M5_DUMMY_RETURN}
2241371SN/A
225581SN/A    void prefetch(Addr addr, unsigned flags)
2262SN/A    {
2272SN/A        // need to do this...
2282SN/A    }
2292SN/A
230753SN/A    void writeHint(Addr addr, int size, unsigned flags)
2312SN/A    {
2322SN/A        // need to do this...
2332SN/A    }
234594SN/A
2354661Sksewell@umich.edu
236595SN/A    Fault copySrcTranslate(Addr src);
237594SN/A
238595SN/A    Fault copy(Addr dest);
239705SN/A
240726SN/A    // The register accessor methods provide the index of the
241726SN/A    // instruction's operand (e.g., 0 or 1), not the architectural
242726SN/A    // register index, to simplify the implementation of register
243726SN/A    // renaming.  We find the architectural register index by indexing
244726SN/A    // into the instruction's own operand index table.  Note that a
245726SN/A    // raw pointer to the StaticInst is provided instead of a
246726SN/A    // ref-counted StaticInstPtr to redice overhead.  This is fine as
247726SN/A    // long as these methods don't copy the pointer into any long-term
248726SN/A    // storage (which is pretty hard to imagine they would have reason
249726SN/A    // to do).
250705SN/A
2513735Sstever@eecs.umich.edu    uint64_t readIntRegOperand(const StaticInst *si, int idx)
252726SN/A    {
2532683Sktlim@umich.edu        return thread->readIntReg(si->srcRegIdx(idx));
254726SN/A    }
255705SN/A
2563735Sstever@eecs.umich.edu    FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width)
257726SN/A    {
258726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2592683Sktlim@umich.edu        return thread->readFloatReg(reg_idx, width);
260726SN/A    }
261705SN/A
2623735Sstever@eecs.umich.edu    FloatReg readFloatRegOperand(const StaticInst *si, int idx)
263726SN/A    {
264726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2652683Sktlim@umich.edu        return thread->readFloatReg(reg_idx);
266726SN/A    }
267705SN/A
2683735Sstever@eecs.umich.edu    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
2693735Sstever@eecs.umich.edu                                         int width)
270726SN/A    {
271726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2722683Sktlim@umich.edu        return thread->readFloatRegBits(reg_idx, width);
2732455SN/A    }
2742455SN/A
2753735Sstever@eecs.umich.edu    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
2762455SN/A    {
2772455SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2782683Sktlim@umich.edu        return thread->readFloatRegBits(reg_idx);
279726SN/A    }
280705SN/A
2813735Sstever@eecs.umich.edu    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
282726SN/A    {
2832683Sktlim@umich.edu        thread->setIntReg(si->destRegIdx(idx), val);
284726SN/A    }
285705SN/A
2863735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
2873735Sstever@eecs.umich.edu                            int width)
288726SN/A    {
289726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2902683Sktlim@umich.edu        thread->setFloatReg(reg_idx, val, width);
291726SN/A    }
292705SN/A
2933735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
294726SN/A    {
295726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2962683Sktlim@umich.edu        thread->setFloatReg(reg_idx, val);
297726SN/A    }
298726SN/A
2993735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx,
3003735Sstever@eecs.umich.edu                                FloatRegBits val, int width)
301726SN/A    {
302726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
3032683Sktlim@umich.edu        thread->setFloatRegBits(reg_idx, val, width);
3042455SN/A    }
3052455SN/A
3063735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx,
3073735Sstever@eecs.umich.edu                                FloatRegBits val)
3082455SN/A    {
3092455SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
3102683Sktlim@umich.edu        thread->setFloatRegBits(reg_idx, val);
311726SN/A    }
312705SN/A
3132683Sktlim@umich.edu    uint64_t readPC() { return thread->readPC(); }
3144950Sgblack@eecs.umich.edu    uint64_t readMicroPC() { return thread->readMicroPC(); }
3152683Sktlim@umich.edu    uint64_t readNextPC() { return thread->readNextPC(); }
3164950Sgblack@eecs.umich.edu    uint64_t readNextMicroPC() { return thread->readNextMicroPC(); }
3172683Sktlim@umich.edu    uint64_t readNextNPC() { return thread->readNextNPC(); }
3182447SN/A
3192683Sktlim@umich.edu    void setPC(uint64_t val) { thread->setPC(val); }
3204950Sgblack@eecs.umich.edu    void setMicroPC(uint64_t val) { thread->setMicroPC(val); }
3212683Sktlim@umich.edu    void setNextPC(uint64_t val) { thread->setNextPC(val); }
3224950Sgblack@eecs.umich.edu    void setNextMicroPC(uint64_t val) { thread->setNextMicroPC(val); }
3232683Sktlim@umich.edu    void setNextNPC(uint64_t val) { thread->setNextNPC(val); }
324705SN/A
3254172Ssaidi@eecs.umich.edu    MiscReg readMiscRegNoEffect(int misc_reg)
3264172Ssaidi@eecs.umich.edu    {
3274172Ssaidi@eecs.umich.edu        return thread->readMiscRegNoEffect(misc_reg);
3284172Ssaidi@eecs.umich.edu    }
3294172Ssaidi@eecs.umich.edu
3302159SN/A    MiscReg readMiscReg(int misc_reg)
3312159SN/A    {
3322683Sktlim@umich.edu        return thread->readMiscReg(misc_reg);
3332159SN/A    }
334705SN/A
3354172Ssaidi@eecs.umich.edu    void setMiscRegNoEffect(int misc_reg, const MiscReg &val)
3362159SN/A    {
3374172Ssaidi@eecs.umich.edu        return thread->setMiscRegNoEffect(misc_reg, val);
3382159SN/A    }
3392159SN/A
3403468Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const MiscReg &val)
3412159SN/A    {
3422683Sktlim@umich.edu        return thread->setMiscReg(misc_reg, val);
3432159SN/A    }
3442159SN/A
3454185Ssaidi@eecs.umich.edu    MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx)
3462159SN/A    {
3474172Ssaidi@eecs.umich.edu        int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3484172Ssaidi@eecs.umich.edu        return thread->readMiscRegNoEffect(reg_idx);
3492159SN/A    }
350705SN/A
3514185Ssaidi@eecs.umich.edu    MiscReg readMiscRegOperand(const StaticInst *si, int idx)
3523792Sgblack@eecs.umich.edu    {
3533792Sgblack@eecs.umich.edu        int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3543792Sgblack@eecs.umich.edu        return thread->readMiscReg(reg_idx);
3553792Sgblack@eecs.umich.edu    }
3563792Sgblack@eecs.umich.edu
3574185Ssaidi@eecs.umich.edu    void setMiscRegOperandNoEffect(const StaticInst *si, int idx, const MiscReg &val)
3583792Sgblack@eecs.umich.edu    {
3593792Sgblack@eecs.umich.edu        int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3604172Ssaidi@eecs.umich.edu        return thread->setMiscRegNoEffect(reg_idx, val);
3613792Sgblack@eecs.umich.edu    }
3623792Sgblack@eecs.umich.edu
3634185Ssaidi@eecs.umich.edu    void setMiscRegOperand(
3643792Sgblack@eecs.umich.edu            const StaticInst *si, int idx, const MiscReg &val)
3653792Sgblack@eecs.umich.edu    {
3663792Sgblack@eecs.umich.edu        int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3674172Ssaidi@eecs.umich.edu        return thread->setMiscReg(reg_idx, val);
3683792Sgblack@eecs.umich.edu    }
3693792Sgblack@eecs.umich.edu
3705358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
3715358Sgblack@eecs.umich.edu    {
3725358Sgblack@eecs.umich.edu        thread->demapPage(vaddr, asn);
3735358Sgblack@eecs.umich.edu    }
3745358Sgblack@eecs.umich.edu
3755358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
3765358Sgblack@eecs.umich.edu    {
3775358Sgblack@eecs.umich.edu        thread->demapInstPage(vaddr, asn);
3785358Sgblack@eecs.umich.edu    }
3795358Sgblack@eecs.umich.edu
3805358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
3815358Sgblack@eecs.umich.edu    {
3825358Sgblack@eecs.umich.edu        thread->demapDataPage(vaddr, asn);
3835358Sgblack@eecs.umich.edu    }
3845358Sgblack@eecs.umich.edu
3854027Sstever@eecs.umich.edu    unsigned readStCondFailures() {
3864027Sstever@eecs.umich.edu        return thread->readStCondFailures();
3874027Sstever@eecs.umich.edu    }
3884027Sstever@eecs.umich.edu
3894027Sstever@eecs.umich.edu    void setStCondFailures(unsigned sc_failures) {
3904027Sstever@eecs.umich.edu        thread->setStCondFailures(sc_failures);
3914027Sstever@eecs.umich.edu    }
3924027Sstever@eecs.umich.edu
3934661Sksewell@umich.edu     MiscReg readRegOtherThread(int regIdx, int tid = -1)
3944661Sksewell@umich.edu     {
3954661Sksewell@umich.edu        panic("Simple CPU models do not support multithreaded "
3964661Sksewell@umich.edu              "register access.\n");
3974661Sksewell@umich.edu     }
3984661Sksewell@umich.edu
3994661Sksewell@umich.edu     void setRegOtherThread(int regIdx, const MiscReg &val, int tid = -1)
4004661Sksewell@umich.edu     {
4014661Sksewell@umich.edu        panic("Simple CPU models do not support multithreaded "
4024661Sksewell@umich.edu              "register access.\n");
4034661Sksewell@umich.edu     }
4044661Sksewell@umich.edu
4055250Sksewell@umich.edu    //Fault CacheOp(uint8_t Op, Addr EA);
4065222Sksewell@umich.edu
4071858SN/A#if FULL_SYSTEM
4082683Sktlim@umich.edu    Fault hwrei() { return thread->hwrei(); }
4092680Sktlim@umich.edu    void ev5_trap(Fault fault) { fault->invoke(tc); }
4102683Sktlim@umich.edu    bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); }
411705SN/A#else
4122683Sktlim@umich.edu    void syscall(int64_t callnum) { thread->syscall(callnum); }
413705SN/A#endif
414705SN/A
4152683Sktlim@umich.edu    bool misspeculating() { return thread->misspeculating(); }
4162680Sktlim@umich.edu    ThreadContext *tcBase() { return tc; }
4172SN/A};
4182SN/A
4192623SN/A#endif // __CPU_SIMPLE_BASE_HH__
420