timing.hh revision 2901
12623SN/A/*
22623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32623SN/A * All rights reserved.
42623SN/A *
52623SN/A * Redistribution and use in source and binary forms, with or without
62623SN/A * modification, are permitted provided that the following conditions are
72623SN/A * met: redistributions of source code must retain the above copyright
82623SN/A * notice, this list of conditions and the following disclaimer;
92623SN/A * redistributions in binary form must reproduce the above copyright
102623SN/A * notice, this list of conditions and the following disclaimer in the
112623SN/A * documentation and/or other materials provided with the distribution;
122623SN/A * neither the name of the copyright holders nor the names of its
132623SN/A * contributors may be used to endorse or promote products derived from
142623SN/A * this software without specific prior written permission.
152623SN/A *
162623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292623SN/A */
302623SN/A
312623SN/A#ifndef __CPU_SIMPLE_TIMING_HH__
322623SN/A#define __CPU_SIMPLE_TIMING_HH__
332623SN/A
342623SN/A#include "cpu/simple/base.hh"
352623SN/A
362623SN/Aclass TimingSimpleCPU : public BaseSimpleCPU
372623SN/A{
382623SN/A  public:
392623SN/A
402623SN/A    struct Params : public BaseSimpleCPU::Params {
412623SN/A    };
422623SN/A
432623SN/A    TimingSimpleCPU(Params *params);
442623SN/A    virtual ~TimingSimpleCPU();
452623SN/A
462623SN/A    virtual void init();
472623SN/A
482623SN/A  public:
492623SN/A    //
502623SN/A    enum Status {
512623SN/A        Idle,
522623SN/A        Running,
532623SN/A        IcacheRetry,
542623SN/A        IcacheWaitResponse,
552623SN/A        IcacheWaitSwitch,
562623SN/A        DcacheRetry,
572623SN/A        DcacheWaitResponse,
582623SN/A        DcacheWaitSwitch,
592623SN/A        SwitchedOut
602623SN/A    };
612623SN/A
622623SN/A  protected:
632623SN/A    Status _status;
642623SN/A
652623SN/A    Status status() const { return _status; }
662623SN/A
672839Sktlim@umich.edu    Event *drainEvent;
682798Sktlim@umich.edu
692867Sktlim@umich.edu    Event *fetchEvent;
702867Sktlim@umich.edu
712623SN/A  private:
722623SN/A
732623SN/A    class CpuPort : public Port
742623SN/A    {
752623SN/A      protected:
762623SN/A        TimingSimpleCPU *cpu;
772623SN/A
782623SN/A      public:
792623SN/A
802640Sstever@eecs.umich.edu        CpuPort(const std::string &_name, TimingSimpleCPU *_cpu)
812640Sstever@eecs.umich.edu            : Port(_name), cpu(_cpu)
822623SN/A        { }
832623SN/A
842623SN/A      protected:
852623SN/A
862630SN/A        virtual Tick recvAtomic(Packet *pkt);
872623SN/A
882630SN/A        virtual void recvFunctional(Packet *pkt);
892623SN/A
902623SN/A        virtual void recvStatusChange(Status status);
912623SN/A
922623SN/A        virtual void getDeviceAddressRanges(AddrRangeList &resp,
932623SN/A            AddrRangeList &snoop)
942623SN/A        { resp.clear(); snoop.clear(); }
952623SN/A    };
962623SN/A
972623SN/A    class IcachePort : public CpuPort
982623SN/A    {
992623SN/A      public:
1002623SN/A
1012623SN/A        IcachePort(TimingSimpleCPU *_cpu)
1022640Sstever@eecs.umich.edu            : CpuPort(_cpu->name() + "-iport", _cpu)
1032623SN/A        { }
1042623SN/A
1052623SN/A      protected:
1062623SN/A
1072630SN/A        virtual bool recvTiming(Packet *pkt);
1082623SN/A
1092657Ssaidi@eecs.umich.edu        virtual void recvRetry();
1102623SN/A    };
1112623SN/A
1122623SN/A    class DcachePort : public CpuPort
1132623SN/A    {
1142623SN/A      public:
1152623SN/A
1162623SN/A        DcachePort(TimingSimpleCPU *_cpu)
1172640Sstever@eecs.umich.edu            : CpuPort(_cpu->name() + "-dport", _cpu)
1182623SN/A        { }
1192623SN/A
1202623SN/A      protected:
1212623SN/A
1222630SN/A        virtual bool recvTiming(Packet *pkt);
1232623SN/A
1242657Ssaidi@eecs.umich.edu        virtual void recvRetry();
1252623SN/A    };
1262623SN/A
1272623SN/A    IcachePort icachePort;
1282623SN/A    DcachePort dcachePort;
1292623SN/A
1302623SN/A    Packet *ifetch_pkt;
1312623SN/A    Packet *dcache_pkt;
1322623SN/A
1332623SN/A  public:
1342623SN/A
1352856Srdreslin@umich.edu    virtual Port *getPort(const std::string &if_name, int idx = -1);
1362856Srdreslin@umich.edu
1372623SN/A    virtual void serialize(std::ostream &os);
1382623SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
1392623SN/A
1402901Ssaidi@eecs.umich.edu    virtual unsigned int drain(Event *drain_event);
1412798Sktlim@umich.edu    virtual void resume();
1422798Sktlim@umich.edu
1432798Sktlim@umich.edu    void switchOut();
1442623SN/A    void takeOverFrom(BaseCPU *oldCPU);
1452623SN/A
1462623SN/A    virtual void activateContext(int thread_num, int delay);
1472623SN/A    virtual void suspendContext(int thread_num);
1482623SN/A
1492623SN/A    template <class T>
1502623SN/A    Fault read(Addr addr, T &data, unsigned flags);
1512623SN/A
1522623SN/A    template <class T>
1532623SN/A    Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
1542623SN/A
1552623SN/A    void fetch();
1562644Sstever@eecs.umich.edu    void completeIfetch(Packet *);
1572623SN/A    void completeDataAccess(Packet *);
1582644Sstever@eecs.umich.edu    void advanceInst(Fault fault);
1592798Sktlim@umich.edu  private:
1602839Sktlim@umich.edu    void completeDrain();
1612623SN/A};
1622623SN/A
1632623SN/A#endif // __CPU_SIMPLE_TIMING_HH__
164