timing.hh revision 2623
19651SAndreas.Sandberg@ARM.com/*
29651SAndreas.Sandberg@ARM.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
39651SAndreas.Sandberg@ARM.com * All rights reserved.
49651SAndreas.Sandberg@ARM.com *
59651SAndreas.Sandberg@ARM.com * Redistribution and use in source and binary forms, with or without
69651SAndreas.Sandberg@ARM.com * modification, are permitted provided that the following conditions are
79651SAndreas.Sandberg@ARM.com * met: redistributions of source code must retain the above copyright
89651SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer;
99651SAndreas.Sandberg@ARM.com * redistributions in binary form must reproduce the above copyright
109651SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer in the
119651SAndreas.Sandberg@ARM.com * documentation and/or other materials provided with the distribution;
129651SAndreas.Sandberg@ARM.com * neither the name of the copyright holders nor the names of its
139651SAndreas.Sandberg@ARM.com * contributors may be used to endorse or promote products derived from
149651SAndreas.Sandberg@ARM.com * this software without specific prior written permission.
159651SAndreas.Sandberg@ARM.com *
169651SAndreas.Sandberg@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179651SAndreas.Sandberg@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189651SAndreas.Sandberg@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199651SAndreas.Sandberg@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209651SAndreas.Sandberg@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219651SAndreas.Sandberg@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229651SAndreas.Sandberg@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239651SAndreas.Sandberg@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249651SAndreas.Sandberg@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259651SAndreas.Sandberg@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269651SAndreas.Sandberg@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279651SAndreas.Sandberg@ARM.com */
289651SAndreas.Sandberg@ARM.com
299651SAndreas.Sandberg@ARM.com#ifndef __CPU_SIMPLE_TIMING_HH__
309651SAndreas.Sandberg@ARM.com#define __CPU_SIMPLE_TIMING_HH__
319651SAndreas.Sandberg@ARM.com
329651SAndreas.Sandberg@ARM.com#include "cpu/simple/base.hh"
339651SAndreas.Sandberg@ARM.com
349651SAndreas.Sandberg@ARM.comclass TimingSimpleCPU : public BaseSimpleCPU
359651SAndreas.Sandberg@ARM.com{
369651SAndreas.Sandberg@ARM.com  public:
379651SAndreas.Sandberg@ARM.com
389651SAndreas.Sandberg@ARM.com    struct Params : public BaseSimpleCPU::Params {
399651SAndreas.Sandberg@ARM.com    };
409651SAndreas.Sandberg@ARM.com
419651SAndreas.Sandberg@ARM.com    TimingSimpleCPU(Params *params);
429651SAndreas.Sandberg@ARM.com    virtual ~TimingSimpleCPU();
439651SAndreas.Sandberg@ARM.com
449651SAndreas.Sandberg@ARM.com    virtual void init();
459651SAndreas.Sandberg@ARM.com
469651SAndreas.Sandberg@ARM.com  public:
479651SAndreas.Sandberg@ARM.com    //
489651SAndreas.Sandberg@ARM.com    enum Status {
499651SAndreas.Sandberg@ARM.com        Idle,
509651SAndreas.Sandberg@ARM.com        Running,
519651SAndreas.Sandberg@ARM.com        IcacheRetry,
529651SAndreas.Sandberg@ARM.com        IcacheWaitResponse,
539651SAndreas.Sandberg@ARM.com        IcacheWaitSwitch,
549651SAndreas.Sandberg@ARM.com        DcacheRetry,
559651SAndreas.Sandberg@ARM.com        DcacheWaitResponse,
569651SAndreas.Sandberg@ARM.com        DcacheWaitSwitch,
579651SAndreas.Sandberg@ARM.com        SwitchedOut
589651SAndreas.Sandberg@ARM.com    };
599651SAndreas.Sandberg@ARM.com
609651SAndreas.Sandberg@ARM.com  protected:
619651SAndreas.Sandberg@ARM.com    Status _status;
629651SAndreas.Sandberg@ARM.com
639651SAndreas.Sandberg@ARM.com    Status status() const { return _status; }
649651SAndreas.Sandberg@ARM.com
659651SAndreas.Sandberg@ARM.com  private:
669651SAndreas.Sandberg@ARM.com
679651SAndreas.Sandberg@ARM.com    class CpuPort : public Port
689651SAndreas.Sandberg@ARM.com    {
699651SAndreas.Sandberg@ARM.com      protected:
709651SAndreas.Sandberg@ARM.com        TimingSimpleCPU *cpu;
719651SAndreas.Sandberg@ARM.com
729655SAndreas.Sandberg@ARM.com      public:
739651SAndreas.Sandberg@ARM.com
74        CpuPort(TimingSimpleCPU *_cpu)
75            : cpu(_cpu)
76        { }
77
78      protected:
79
80        virtual Tick recvAtomic(Packet &pkt);
81
82        virtual void recvFunctional(Packet &pkt);
83
84        virtual void recvStatusChange(Status status);
85
86        virtual void getDeviceAddressRanges(AddrRangeList &resp,
87            AddrRangeList &snoop)
88        { resp.clear(); snoop.clear(); }
89    };
90
91    class IcachePort : public CpuPort
92    {
93      public:
94
95        IcachePort(TimingSimpleCPU *_cpu)
96            : CpuPort(_cpu)
97        { }
98
99      protected:
100
101        virtual bool recvTiming(Packet &pkt);
102
103        virtual Packet *recvRetry();
104    };
105
106    class DcachePort : public CpuPort
107    {
108      public:
109
110        DcachePort(TimingSimpleCPU *_cpu)
111            : CpuPort(_cpu)
112        { }
113
114      protected:
115
116        virtual bool recvTiming(Packet &pkt);
117
118        virtual Packet *recvRetry();
119    };
120
121    IcachePort icachePort;
122    DcachePort dcachePort;
123
124    Packet *ifetch_pkt;
125    Packet *dcache_pkt;
126
127  public:
128
129    virtual void serialize(std::ostream &os);
130    virtual void unserialize(Checkpoint *cp, const std::string &section);
131
132    void switchOut(Sampler *s);
133    void takeOverFrom(BaseCPU *oldCPU);
134
135    virtual void activateContext(int thread_num, int delay);
136    virtual void suspendContext(int thread_num);
137
138    template <class T>
139    Fault read(Addr addr, T &data, unsigned flags);
140
141    template <class T>
142    Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
143
144    void fetch();
145    void completeInst(Fault fault);
146    void completeIfetch();
147    void completeDataAccess(Packet *);
148};
149
150#endif // __CPU_SIMPLE_TIMING_HH__
151