base.hh revision 5222
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"
472SN/A
482SN/A// forward declarations
491858SN/A#if FULL_SYSTEM
502SN/Aclass Processor;
513453Sgblack@eecs.umich.edunamespace TheISA
523453Sgblack@eecs.umich.edu{
533453Sgblack@eecs.umich.edu    class ITB;
543453Sgblack@eecs.umich.edu    class DTB;
553453Sgblack@eecs.umich.edu}
562462SN/Aclass MemObject;
572SN/A
58715SN/A#else
59715SN/A
60715SN/Aclass Process;
61715SN/A
622SN/A#endif // FULL_SYSTEM
632SN/A
643960Sgblack@eecs.umich.educlass RemoteGDB;
653960Sgblack@eecs.umich.educlass GDBListener;
663960Sgblack@eecs.umich.edu
674182Sgblack@eecs.umich.edunamespace TheISA
684182Sgblack@eecs.umich.edu{
694182Sgblack@eecs.umich.edu    class Predecoder;
704182Sgblack@eecs.umich.edu}
712680Sktlim@umich.educlass ThreadContext;
72237SN/Aclass Checkpoint;
732SN/A
742SN/Anamespace Trace {
752SN/A    class InstRecord;
762SN/A}
772SN/A
782420SN/A
792623SN/Aclass BaseSimpleCPU : public BaseCPU
802SN/A{
812107SN/A  protected:
822159SN/A    typedef TheISA::MiscReg MiscReg;
832455SN/A    typedef TheISA::FloatReg FloatReg;
842455SN/A    typedef TheISA::FloatRegBits FloatRegBits;
852386SN/A
862623SN/A  protected:
872SN/A    Trace::InstRecord *traceData;
881371SN/A
892SN/A  public:
902SN/A    void post_interrupt(int int_num, int index);
912SN/A
922SN/A    void zero_fill_64(Addr addr) {
932SN/A      static int warned = 0;
942SN/A      if (!warned) {
952SN/A        warn ("WH64 is not implemented");
962SN/A        warned = 1;
972SN/A      }
982SN/A    };
992SN/A
1001400SN/A  public:
1011400SN/A    struct Params : public BaseCPU::Params
1021400SN/A    {
1033453Sgblack@eecs.umich.edu        TheISA::ITB *itb;
1043453Sgblack@eecs.umich.edu        TheISA::DTB *dtb;
1054997Sgblack@eecs.umich.edu#if !FULL_SYSTEM
1061400SN/A        Process *process;
1072SN/A#endif
1081400SN/A    };
1092623SN/A    BaseSimpleCPU(Params *params);
1102623SN/A    virtual ~BaseSimpleCPU();
1112SN/A
1121400SN/A  public:
1132683Sktlim@umich.edu    /** SimpleThread object, provides all the architectural state. */
1142683Sktlim@umich.edu    SimpleThread *thread;
1152190SN/A
1162683Sktlim@umich.edu    /** ThreadContext object, provides an interface for external
1172683Sktlim@umich.edu     * objects to modify this thread's state.
1182683Sktlim@umich.edu     */
1192680Sktlim@umich.edu    ThreadContext *tc;
1205169Ssaidi@eecs.umich.edu  protected:
1215169Ssaidi@eecs.umich.edu    int cpuId;
1225169Ssaidi@eecs.umich.edu
1235169Ssaidi@eecs.umich.edu  public:
1242SN/A
1251858SN/A#if FULL_SYSTEM
1262SN/A    Addr dbg_vtophys(Addr addr);
1272SN/A
1282SN/A    bool interval_stats;
1292SN/A#endif
1302SN/A
1312SN/A    // current instruction
1324181Sgblack@eecs.umich.edu    TheISA::MachInst inst;
1334181Sgblack@eecs.umich.edu
1344182Sgblack@eecs.umich.edu    // The predecoder
1354182Sgblack@eecs.umich.edu    TheISA::Predecoder predecoder;
1362SN/A
1372107SN/A    StaticInstPtr curStaticInst;
1383276Sgblack@eecs.umich.edu    StaticInstPtr curMacroStaticInst;
1391469SN/A
1404377Sgblack@eecs.umich.edu    //This is the offset from the current pc that fetch should be performed at
1414377Sgblack@eecs.umich.edu    Addr fetchOffset;
1424377Sgblack@eecs.umich.edu    //This flag says to stay at the current pc. This is useful for
1434377Sgblack@eecs.umich.edu    //instructions which go beyond MachInst boundaries.
1444377Sgblack@eecs.umich.edu    bool stayAtPC;
1454377Sgblack@eecs.umich.edu
1462623SN/A    void checkForInterrupts();
1472662Sstever@eecs.umich.edu    Fault setupFetchRequest(Request *req);
1482623SN/A    void preExecute();
1492623SN/A    void postExecute();
1502623SN/A    void advancePC(Fault fault);
151180SN/A
152393SN/A    virtual void deallocateContext(int thread_num);
153393SN/A    virtual void haltContext(int thread_num);
1542SN/A
1552SN/A    // statistics
156334SN/A    virtual void regStats();
157334SN/A    virtual void resetStats();
1582SN/A
1592SN/A    // number of simulated instructions
1602SN/A    Counter numInst;
161334SN/A    Counter startNumInst;
162729SN/A    Stats::Scalar<> numInsts;
163707SN/A
1644998Sgblack@eecs.umich.edu    void countInst()
1654998Sgblack@eecs.umich.edu    {
1664998Sgblack@eecs.umich.edu        numInst++;
1674998Sgblack@eecs.umich.edu        numInsts++;
1684998Sgblack@eecs.umich.edu
1694998Sgblack@eecs.umich.edu        thread->funcExeInst++;
1704998Sgblack@eecs.umich.edu    }
1714998Sgblack@eecs.umich.edu
172707SN/A    virtual Counter totalInstructions() const
173707SN/A    {
174707SN/A        return numInst - startNumInst;
175707SN/A    }
1762SN/A
1774564Sgblack@eecs.umich.edu    // Mask to align PCs to MachInst sized boundaries
1784564Sgblack@eecs.umich.edu    static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1);
1794564Sgblack@eecs.umich.edu
1802SN/A    // number of simulated memory references
181729SN/A    Stats::Scalar<> numMemRefs;
1822SN/A
183124SN/A    // number of simulated loads
184124SN/A    Counter numLoad;
185334SN/A    Counter startNumLoad;
186124SN/A
1872SN/A    // number of idle cycles
188729SN/A    Stats::Average<> notIdleFraction;
189729SN/A    Stats::Formula idleFraction;
1902SN/A
1912390SN/A    // number of cycles stalled for I-cache responses
192729SN/A    Stats::Scalar<> icacheStallCycles;
1932SN/A    Counter lastIcacheStall;
1942SN/A
1952390SN/A    // number of cycles stalled for I-cache retries
1962390SN/A    Stats::Scalar<> icacheRetryCycles;
1972390SN/A    Counter lastIcacheRetry;
1982390SN/A
1992390SN/A    // number of cycles stalled for D-cache responses
200729SN/A    Stats::Scalar<> dcacheStallCycles;
2012SN/A    Counter lastDcacheStall;
2022SN/A
2032390SN/A    // number of cycles stalled for D-cache retries
2042390SN/A    Stats::Scalar<> dcacheRetryCycles;
2052390SN/A    Counter lastDcacheRetry;
2062390SN/A
207217SN/A    virtual void serialize(std::ostream &os);
208237SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
2092SN/A
2101371SN/A    // These functions are only used in CPU models that split
2111371SN/A    // effective address computation from the actual memory access.
2122623SN/A    void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); }
2133918Ssaidi@eecs.umich.edu    Addr getEA() 	{ panic("BaseSimpleCPU::getEA() not implemented\n");
2143918Ssaidi@eecs.umich.edu        M5_DUMMY_RETURN}
2151371SN/A
216581SN/A    void prefetch(Addr addr, unsigned flags)
2172SN/A    {
2182SN/A        // need to do this...
2192SN/A    }
2202SN/A
221753SN/A    void writeHint(Addr addr, int size, unsigned flags)
2222SN/A    {
2232SN/A        // need to do this...
2242SN/A    }
225594SN/A
2264661Sksewell@umich.edu
227595SN/A    Fault copySrcTranslate(Addr src);
228594SN/A
229595SN/A    Fault copy(Addr dest);
230705SN/A
231726SN/A    // The register accessor methods provide the index of the
232726SN/A    // instruction's operand (e.g., 0 or 1), not the architectural
233726SN/A    // register index, to simplify the implementation of register
234726SN/A    // renaming.  We find the architectural register index by indexing
235726SN/A    // into the instruction's own operand index table.  Note that a
236726SN/A    // raw pointer to the StaticInst is provided instead of a
237726SN/A    // ref-counted StaticInstPtr to redice overhead.  This is fine as
238726SN/A    // long as these methods don't copy the pointer into any long-term
239726SN/A    // storage (which is pretty hard to imagine they would have reason
240726SN/A    // to do).
241705SN/A
2423735Sstever@eecs.umich.edu    uint64_t readIntRegOperand(const StaticInst *si, int idx)
243726SN/A    {
2442683Sktlim@umich.edu        return thread->readIntReg(si->srcRegIdx(idx));
245726SN/A    }
246705SN/A
2473735Sstever@eecs.umich.edu    FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width)
248726SN/A    {
249726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2502683Sktlim@umich.edu        return thread->readFloatReg(reg_idx, width);
251726SN/A    }
252705SN/A
2533735Sstever@eecs.umich.edu    FloatReg readFloatRegOperand(const StaticInst *si, int idx)
254726SN/A    {
255726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2562683Sktlim@umich.edu        return thread->readFloatReg(reg_idx);
257726SN/A    }
258705SN/A
2593735Sstever@eecs.umich.edu    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
2603735Sstever@eecs.umich.edu                                         int width)
261726SN/A    {
262726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2632683Sktlim@umich.edu        return thread->readFloatRegBits(reg_idx, width);
2642455SN/A    }
2652455SN/A
2663735Sstever@eecs.umich.edu    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
2672455SN/A    {
2682455SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2692683Sktlim@umich.edu        return thread->readFloatRegBits(reg_idx);
270726SN/A    }
271705SN/A
2723735Sstever@eecs.umich.edu    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
273726SN/A    {
2742683Sktlim@umich.edu        thread->setIntReg(si->destRegIdx(idx), val);
275726SN/A    }
276705SN/A
2773735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
2783735Sstever@eecs.umich.edu                            int width)
279726SN/A    {
280726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2812683Sktlim@umich.edu        thread->setFloatReg(reg_idx, val, width);
282726SN/A    }
283705SN/A
2843735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
285726SN/A    {
286726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2872683Sktlim@umich.edu        thread->setFloatReg(reg_idx, val);
288726SN/A    }
289726SN/A
2903735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx,
2913735Sstever@eecs.umich.edu                                FloatRegBits val, int width)
292726SN/A    {
293726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2942683Sktlim@umich.edu        thread->setFloatRegBits(reg_idx, val, width);
2952455SN/A    }
2962455SN/A
2973735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx,
2983735Sstever@eecs.umich.edu                                FloatRegBits val)
2992455SN/A    {
3002455SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
3012683Sktlim@umich.edu        thread->setFloatRegBits(reg_idx, val);
302726SN/A    }
303705SN/A
3042683Sktlim@umich.edu    uint64_t readPC() { return thread->readPC(); }
3054950Sgblack@eecs.umich.edu    uint64_t readMicroPC() { return thread->readMicroPC(); }
3062683Sktlim@umich.edu    uint64_t readNextPC() { return thread->readNextPC(); }
3074950Sgblack@eecs.umich.edu    uint64_t readNextMicroPC() { return thread->readNextMicroPC(); }
3082683Sktlim@umich.edu    uint64_t readNextNPC() { return thread->readNextNPC(); }
3092447SN/A
3102683Sktlim@umich.edu    void setPC(uint64_t val) { thread->setPC(val); }
3114950Sgblack@eecs.umich.edu    void setMicroPC(uint64_t val) { thread->setMicroPC(val); }
3122683Sktlim@umich.edu    void setNextPC(uint64_t val) { thread->setNextPC(val); }
3134950Sgblack@eecs.umich.edu    void setNextMicroPC(uint64_t val) { thread->setNextMicroPC(val); }
3142683Sktlim@umich.edu    void setNextNPC(uint64_t val) { thread->setNextNPC(val); }
315705SN/A
3164172Ssaidi@eecs.umich.edu    MiscReg readMiscRegNoEffect(int misc_reg)
3174172Ssaidi@eecs.umich.edu    {
3184172Ssaidi@eecs.umich.edu        return thread->readMiscRegNoEffect(misc_reg);
3194172Ssaidi@eecs.umich.edu    }
3204172Ssaidi@eecs.umich.edu
3212159SN/A    MiscReg readMiscReg(int misc_reg)
3222159SN/A    {
3232683Sktlim@umich.edu        return thread->readMiscReg(misc_reg);
3242159SN/A    }
325705SN/A
3264172Ssaidi@eecs.umich.edu    void setMiscRegNoEffect(int misc_reg, const MiscReg &val)
3272159SN/A    {
3284172Ssaidi@eecs.umich.edu        return thread->setMiscRegNoEffect(misc_reg, val);
3292159SN/A    }
3302159SN/A
3313468Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const MiscReg &val)
3322159SN/A    {
3332683Sktlim@umich.edu        return thread->setMiscReg(misc_reg, val);
3342159SN/A    }
3352159SN/A
3364185Ssaidi@eecs.umich.edu    MiscReg readMiscRegOperandNoEffect(const StaticInst *si, int idx)
3372159SN/A    {
3384172Ssaidi@eecs.umich.edu        int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3394172Ssaidi@eecs.umich.edu        return thread->readMiscRegNoEffect(reg_idx);
3402159SN/A    }
341705SN/A
3424185Ssaidi@eecs.umich.edu    MiscReg readMiscRegOperand(const StaticInst *si, int idx)
3433792Sgblack@eecs.umich.edu    {
3443792Sgblack@eecs.umich.edu        int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3453792Sgblack@eecs.umich.edu        return thread->readMiscReg(reg_idx);
3463792Sgblack@eecs.umich.edu    }
3473792Sgblack@eecs.umich.edu
3484185Ssaidi@eecs.umich.edu    void setMiscRegOperandNoEffect(const StaticInst *si, int idx, const MiscReg &val)
3493792Sgblack@eecs.umich.edu    {
3503792Sgblack@eecs.umich.edu        int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3514172Ssaidi@eecs.umich.edu        return thread->setMiscRegNoEffect(reg_idx, val);
3523792Sgblack@eecs.umich.edu    }
3533792Sgblack@eecs.umich.edu
3544185Ssaidi@eecs.umich.edu    void setMiscRegOperand(
3553792Sgblack@eecs.umich.edu            const StaticInst *si, int idx, const MiscReg &val)
3563792Sgblack@eecs.umich.edu    {
3573792Sgblack@eecs.umich.edu        int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3584172Ssaidi@eecs.umich.edu        return thread->setMiscReg(reg_idx, val);
3593792Sgblack@eecs.umich.edu    }
3603792Sgblack@eecs.umich.edu
3614027Sstever@eecs.umich.edu    unsigned readStCondFailures() {
3624027Sstever@eecs.umich.edu        return thread->readStCondFailures();
3634027Sstever@eecs.umich.edu    }
3644027Sstever@eecs.umich.edu
3654027Sstever@eecs.umich.edu    void setStCondFailures(unsigned sc_failures) {
3664027Sstever@eecs.umich.edu        thread->setStCondFailures(sc_failures);
3674027Sstever@eecs.umich.edu    }
3684027Sstever@eecs.umich.edu
3694661Sksewell@umich.edu     MiscReg readRegOtherThread(int regIdx, int tid = -1)
3704661Sksewell@umich.edu     {
3714661Sksewell@umich.edu        panic("Simple CPU models do not support multithreaded "
3724661Sksewell@umich.edu              "register access.\n");
3734661Sksewell@umich.edu     }
3744661Sksewell@umich.edu
3754661Sksewell@umich.edu     void setRegOtherThread(int regIdx, const MiscReg &val, int tid = -1)
3764661Sksewell@umich.edu     {
3774661Sksewell@umich.edu        panic("Simple CPU models do not support multithreaded "
3784661Sksewell@umich.edu              "register access.\n");
3794661Sksewell@umich.edu     }
3804661Sksewell@umich.edu
3815222Sksewell@umich.edu    void setShadowSet(int css) {
3825222Sksewell@umich.edu        panic("Simple CPU models do not support Shadow Sets");
3835222Sksewell@umich.edu        //tc->setShadowSet(css);
3845222Sksewell@umich.edu    }
3855222Sksewell@umich.edu
3865222Sksewell@umich.edu    Fault CacheOp(uint8_t Op, Addr EA);
3871858SN/A#if FULL_SYSTEM
3882683Sktlim@umich.edu    Fault hwrei() { return thread->hwrei(); }
3892680Sktlim@umich.edu    void ev5_trap(Fault fault) { fault->invoke(tc); }
3902683Sktlim@umich.edu    bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); }
391705SN/A#else
3922683Sktlim@umich.edu    void syscall(int64_t callnum) { thread->syscall(callnum); }
393705SN/A#endif
394705SN/A
3952683Sktlim@umich.edu    bool misspeculating() { return thread->misspeculating(); }
3962680Sktlim@umich.edu    ThreadContext *tcBase() { return tc; }
3972SN/A};
3982SN/A
3992623SN/A#endif // __CPU_SIMPLE_BASE_HH__
400