base.hh revision 4182
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    {
1031858SN/A#if FULL_SYSTEM
1043453Sgblack@eecs.umich.edu        TheISA::ITB *itb;
1053453Sgblack@eecs.umich.edu        TheISA::DTB *dtb;
1062SN/A#else
1071400SN/A        Process *process;
1082SN/A#endif
1091400SN/A    };
1102623SN/A    BaseSimpleCPU(Params *params);
1112623SN/A    virtual ~BaseSimpleCPU();
1122SN/A
1131400SN/A  public:
1142683Sktlim@umich.edu    /** SimpleThread object, provides all the architectural state. */
1152683Sktlim@umich.edu    SimpleThread *thread;
1162190SN/A
1172683Sktlim@umich.edu    /** ThreadContext object, provides an interface for external
1182683Sktlim@umich.edu     * objects to modify this thread's state.
1192683Sktlim@umich.edu     */
1202680Sktlim@umich.edu    ThreadContext *tc;
1212SN/A
1221858SN/A#if FULL_SYSTEM
1232SN/A    Addr dbg_vtophys(Addr addr);
1242SN/A
1252SN/A    bool interval_stats;
1262SN/A#endif
1272SN/A
1282SN/A    // current instruction
1294181Sgblack@eecs.umich.edu    TheISA::MachInst inst;
1304181Sgblack@eecs.umich.edu
1314182Sgblack@eecs.umich.edu    // The predecoder
1324182Sgblack@eecs.umich.edu    TheISA::Predecoder predecoder;
1332SN/A
1342566SN/A    // Static data storage
1354040Ssaidi@eecs.umich.edu    TheISA::LargestRead dataReg;
1362566SN/A
1372107SN/A    StaticInstPtr curStaticInst;
1383276Sgblack@eecs.umich.edu    StaticInstPtr curMacroStaticInst;
1391469SN/A
1402623SN/A    void checkForInterrupts();
1412662Sstever@eecs.umich.edu    Fault setupFetchRequest(Request *req);
1422623SN/A    void preExecute();
1432623SN/A    void postExecute();
1442623SN/A    void advancePC(Fault fault);
145180SN/A
146393SN/A    virtual void deallocateContext(int thread_num);
147393SN/A    virtual void haltContext(int thread_num);
1482SN/A
1492SN/A    // statistics
150334SN/A    virtual void regStats();
151334SN/A    virtual void resetStats();
1522SN/A
1532SN/A    // number of simulated instructions
1542SN/A    Counter numInst;
155334SN/A    Counter startNumInst;
156729SN/A    Stats::Scalar<> numInsts;
157707SN/A
158707SN/A    virtual Counter totalInstructions() const
159707SN/A    {
160707SN/A        return numInst - startNumInst;
161707SN/A    }
1622SN/A
1632SN/A    // number of simulated memory references
164729SN/A    Stats::Scalar<> numMemRefs;
1652SN/A
166124SN/A    // number of simulated loads
167124SN/A    Counter numLoad;
168334SN/A    Counter startNumLoad;
169124SN/A
1702SN/A    // number of idle cycles
171729SN/A    Stats::Average<> notIdleFraction;
172729SN/A    Stats::Formula idleFraction;
1732SN/A
1742390SN/A    // number of cycles stalled for I-cache responses
175729SN/A    Stats::Scalar<> icacheStallCycles;
1762SN/A    Counter lastIcacheStall;
1772SN/A
1782390SN/A    // number of cycles stalled for I-cache retries
1792390SN/A    Stats::Scalar<> icacheRetryCycles;
1802390SN/A    Counter lastIcacheRetry;
1812390SN/A
1822390SN/A    // number of cycles stalled for D-cache responses
183729SN/A    Stats::Scalar<> dcacheStallCycles;
1842SN/A    Counter lastDcacheStall;
1852SN/A
1862390SN/A    // number of cycles stalled for D-cache retries
1872390SN/A    Stats::Scalar<> dcacheRetryCycles;
1882390SN/A    Counter lastDcacheRetry;
1892390SN/A
190217SN/A    virtual void serialize(std::ostream &os);
191237SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
1922SN/A
1931371SN/A    // These functions are only used in CPU models that split
1941371SN/A    // effective address computation from the actual memory access.
1952623SN/A    void setEA(Addr EA) { panic("BaseSimpleCPU::setEA() not implemented\n"); }
1963918Ssaidi@eecs.umich.edu    Addr getEA() 	{ panic("BaseSimpleCPU::getEA() not implemented\n");
1973918Ssaidi@eecs.umich.edu        M5_DUMMY_RETURN}
1981371SN/A
199581SN/A    void prefetch(Addr addr, unsigned flags)
2002SN/A    {
2012SN/A        // need to do this...
2022SN/A    }
2032SN/A
204753SN/A    void writeHint(Addr addr, int size, unsigned flags)
2052SN/A    {
2062SN/A        // need to do this...
2072SN/A    }
208594SN/A
209595SN/A    Fault copySrcTranslate(Addr src);
210594SN/A
211595SN/A    Fault copy(Addr dest);
212705SN/A
213726SN/A    // The register accessor methods provide the index of the
214726SN/A    // instruction's operand (e.g., 0 or 1), not the architectural
215726SN/A    // register index, to simplify the implementation of register
216726SN/A    // renaming.  We find the architectural register index by indexing
217726SN/A    // into the instruction's own operand index table.  Note that a
218726SN/A    // raw pointer to the StaticInst is provided instead of a
219726SN/A    // ref-counted StaticInstPtr to redice overhead.  This is fine as
220726SN/A    // long as these methods don't copy the pointer into any long-term
221726SN/A    // storage (which is pretty hard to imagine they would have reason
222726SN/A    // to do).
223705SN/A
2243735Sstever@eecs.umich.edu    uint64_t readIntRegOperand(const StaticInst *si, int idx)
225726SN/A    {
2262683Sktlim@umich.edu        return thread->readIntReg(si->srcRegIdx(idx));
227726SN/A    }
228705SN/A
2293735Sstever@eecs.umich.edu    FloatReg readFloatRegOperand(const StaticInst *si, int idx, int width)
230726SN/A    {
231726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2322683Sktlim@umich.edu        return thread->readFloatReg(reg_idx, width);
233726SN/A    }
234705SN/A
2353735Sstever@eecs.umich.edu    FloatReg readFloatRegOperand(const StaticInst *si, int idx)
236726SN/A    {
237726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2382683Sktlim@umich.edu        return thread->readFloatReg(reg_idx);
239726SN/A    }
240705SN/A
2413735Sstever@eecs.umich.edu    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx,
2423735Sstever@eecs.umich.edu                                         int width)
243726SN/A    {
244726SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2452683Sktlim@umich.edu        return thread->readFloatRegBits(reg_idx, width);
2462455SN/A    }
2472455SN/A
2483735Sstever@eecs.umich.edu    FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
2492455SN/A    {
2502455SN/A        int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
2512683Sktlim@umich.edu        return thread->readFloatRegBits(reg_idx);
252726SN/A    }
253705SN/A
2543735Sstever@eecs.umich.edu    void setIntRegOperand(const StaticInst *si, int idx, uint64_t val)
255726SN/A    {
2562683Sktlim@umich.edu        thread->setIntReg(si->destRegIdx(idx), val);
257726SN/A    }
258705SN/A
2593735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val,
2603735Sstever@eecs.umich.edu                            int width)
261726SN/A    {
262726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2632683Sktlim@umich.edu        thread->setFloatReg(reg_idx, val, width);
264726SN/A    }
265705SN/A
2663735Sstever@eecs.umich.edu    void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
267726SN/A    {
268726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2692683Sktlim@umich.edu        thread->setFloatReg(reg_idx, val);
270726SN/A    }
271726SN/A
2723735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx,
2733735Sstever@eecs.umich.edu                                FloatRegBits val, int width)
274726SN/A    {
275726SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2762683Sktlim@umich.edu        thread->setFloatRegBits(reg_idx, val, width);
2772455SN/A    }
2782455SN/A
2793735Sstever@eecs.umich.edu    void setFloatRegOperandBits(const StaticInst *si, int idx,
2803735Sstever@eecs.umich.edu                                FloatRegBits val)
2812455SN/A    {
2822455SN/A        int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
2832683Sktlim@umich.edu        thread->setFloatRegBits(reg_idx, val);
284726SN/A    }
285705SN/A
2862683Sktlim@umich.edu    uint64_t readPC() { return thread->readPC(); }
2872683Sktlim@umich.edu    uint64_t readNextPC() { return thread->readNextPC(); }
2882683Sktlim@umich.edu    uint64_t readNextNPC() { return thread->readNextNPC(); }
2892447SN/A
2902683Sktlim@umich.edu    void setPC(uint64_t val) { thread->setPC(val); }
2912683Sktlim@umich.edu    void setNextPC(uint64_t val) { thread->setNextPC(val); }
2922683Sktlim@umich.edu    void setNextNPC(uint64_t val) { thread->setNextNPC(val); }
293705SN/A
2944172Ssaidi@eecs.umich.edu    MiscReg readMiscRegNoEffect(int misc_reg)
2954172Ssaidi@eecs.umich.edu    {
2964172Ssaidi@eecs.umich.edu        return thread->readMiscRegNoEffect(misc_reg);
2974172Ssaidi@eecs.umich.edu    }
2984172Ssaidi@eecs.umich.edu
2992159SN/A    MiscReg readMiscReg(int misc_reg)
3002159SN/A    {
3012683Sktlim@umich.edu        return thread->readMiscReg(misc_reg);
3022159SN/A    }
303705SN/A
3044172Ssaidi@eecs.umich.edu    void setMiscRegNoEffect(int misc_reg, const MiscReg &val)
3052159SN/A    {
3064172Ssaidi@eecs.umich.edu        return thread->setMiscRegNoEffect(misc_reg, val);
3072159SN/A    }
3082159SN/A
3093468Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const MiscReg &val)
3102159SN/A    {
3112683Sktlim@umich.edu        return thread->setMiscReg(misc_reg, val);
3122159SN/A    }
3132159SN/A
3144172Ssaidi@eecs.umich.edu    MiscReg readMiscRegOperand(const StaticInst *si, int idx)
3152159SN/A    {
3164172Ssaidi@eecs.umich.edu        int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3174172Ssaidi@eecs.umich.edu        return thread->readMiscRegNoEffect(reg_idx);
3182159SN/A    }
319705SN/A
3204172Ssaidi@eecs.umich.edu    MiscReg readMiscRegOperandWithEffect(const StaticInst *si, int idx)
3213792Sgblack@eecs.umich.edu    {
3223792Sgblack@eecs.umich.edu        int reg_idx = si->srcRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3233792Sgblack@eecs.umich.edu        return thread->readMiscReg(reg_idx);
3243792Sgblack@eecs.umich.edu    }
3253792Sgblack@eecs.umich.edu
3263792Sgblack@eecs.umich.edu    void setMiscRegOperand(const StaticInst *si, int idx, const MiscReg &val)
3273792Sgblack@eecs.umich.edu    {
3283792Sgblack@eecs.umich.edu        int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3294172Ssaidi@eecs.umich.edu        return thread->setMiscRegNoEffect(reg_idx, val);
3303792Sgblack@eecs.umich.edu    }
3313792Sgblack@eecs.umich.edu
3323792Sgblack@eecs.umich.edu    void setMiscRegOperandWithEffect(
3333792Sgblack@eecs.umich.edu            const StaticInst *si, int idx, const MiscReg &val)
3343792Sgblack@eecs.umich.edu    {
3353792Sgblack@eecs.umich.edu        int reg_idx = si->destRegIdx(idx) - TheISA::Ctrl_Base_DepTag;
3364172Ssaidi@eecs.umich.edu        return thread->setMiscReg(reg_idx, val);
3373792Sgblack@eecs.umich.edu    }
3383792Sgblack@eecs.umich.edu
3394027Sstever@eecs.umich.edu    unsigned readStCondFailures() {
3404027Sstever@eecs.umich.edu        return thread->readStCondFailures();
3414027Sstever@eecs.umich.edu    }
3424027Sstever@eecs.umich.edu
3434027Sstever@eecs.umich.edu    void setStCondFailures(unsigned sc_failures) {
3444027Sstever@eecs.umich.edu        thread->setStCondFailures(sc_failures);
3454027Sstever@eecs.umich.edu    }
3464027Sstever@eecs.umich.edu
3471858SN/A#if FULL_SYSTEM
3482683Sktlim@umich.edu    Fault hwrei() { return thread->hwrei(); }
3492680Sktlim@umich.edu    void ev5_trap(Fault fault) { fault->invoke(tc); }
3502683Sktlim@umich.edu    bool simPalCheck(int palFunc) { return thread->simPalCheck(palFunc); }
351705SN/A#else
3522683Sktlim@umich.edu    void syscall(int64_t callnum) { thread->syscall(callnum); }
353705SN/A#endif
354705SN/A
3552683Sktlim@umich.edu    bool misspeculating() { return thread->misspeculating(); }
3562680Sktlim@umich.edu    ThreadContext *tcBase() { return tc; }
3572SN/A};
3582SN/A
3592623SN/A#endif // __CPU_SIMPLE_BASE_HH__
360