cpu.hh revision 10259
110259SAndrew.Bardsley@arm.com/*
210259SAndrew.Bardsley@arm.com * Copyright (c) 2012-2014 ARM Limited
310259SAndrew.Bardsley@arm.com * All rights reserved
410259SAndrew.Bardsley@arm.com *
510259SAndrew.Bardsley@arm.com * The license below extends only to copyright in the software and shall
610259SAndrew.Bardsley@arm.com * not be construed as granting a license to any other intellectual
710259SAndrew.Bardsley@arm.com * property including but not limited to intellectual property relating
810259SAndrew.Bardsley@arm.com * to a hardware implementation of the functionality of the software
910259SAndrew.Bardsley@arm.com * licensed hereunder.  You may use the software subject to the license
1010259SAndrew.Bardsley@arm.com * terms below provided that you ensure that this notice is replicated
1110259SAndrew.Bardsley@arm.com * unmodified and in its entirety in all distributions of the software,
1210259SAndrew.Bardsley@arm.com * modified or unmodified, in source code or in binary form.
1310259SAndrew.Bardsley@arm.com *
1410259SAndrew.Bardsley@arm.com * Redistribution and use in source and binary forms, with or without
1510259SAndrew.Bardsley@arm.com * modification, are permitted provided that the following conditions are
1610259SAndrew.Bardsley@arm.com * met: redistributions of source code must retain the above copyright
1710259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer;
1810259SAndrew.Bardsley@arm.com * redistributions in binary form must reproduce the above copyright
1910259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer in the
2010259SAndrew.Bardsley@arm.com * documentation and/or other materials provided with the distribution;
2110259SAndrew.Bardsley@arm.com * neither the name of the copyright holders nor the names of its
2210259SAndrew.Bardsley@arm.com * contributors may be used to endorse or promote products derived from
2310259SAndrew.Bardsley@arm.com * this software without specific prior written permission.
2410259SAndrew.Bardsley@arm.com *
2510259SAndrew.Bardsley@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2610259SAndrew.Bardsley@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2710259SAndrew.Bardsley@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2810259SAndrew.Bardsley@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2910259SAndrew.Bardsley@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3010259SAndrew.Bardsley@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3110259SAndrew.Bardsley@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3210259SAndrew.Bardsley@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3310259SAndrew.Bardsley@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3410259SAndrew.Bardsley@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3510259SAndrew.Bardsley@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3610259SAndrew.Bardsley@arm.com *
3710259SAndrew.Bardsley@arm.com * Authors: Andrew Bardsley
3810259SAndrew.Bardsley@arm.com */
3910259SAndrew.Bardsley@arm.com
4010259SAndrew.Bardsley@arm.com/**
4110259SAndrew.Bardsley@arm.com * @file
4210259SAndrew.Bardsley@arm.com *
4310259SAndrew.Bardsley@arm.com *  Top level definition of the Minor in-order CPU model
4410259SAndrew.Bardsley@arm.com */
4510259SAndrew.Bardsley@arm.com
4610259SAndrew.Bardsley@arm.com#ifndef __CPU_MINOR_CPU_HH__
4710259SAndrew.Bardsley@arm.com#define __CPU_MINOR_CPU_HH__
4810259SAndrew.Bardsley@arm.com
4910259SAndrew.Bardsley@arm.com#include "cpu/minor/activity.hh"
5010259SAndrew.Bardsley@arm.com#include "cpu/minor/stats.hh"
5110259SAndrew.Bardsley@arm.com#include "cpu/base.hh"
5210259SAndrew.Bardsley@arm.com#include "cpu/simple_thread.hh"
5310259SAndrew.Bardsley@arm.com#include "params/MinorCPU.hh"
5410259SAndrew.Bardsley@arm.com
5510259SAndrew.Bardsley@arm.comnamespace Minor
5610259SAndrew.Bardsley@arm.com{
5710259SAndrew.Bardsley@arm.com/** Forward declared to break the cyclic inclusion dependencies between
5810259SAndrew.Bardsley@arm.com *  pipeline and cpu */
5910259SAndrew.Bardsley@arm.comclass Pipeline;
6010259SAndrew.Bardsley@arm.com
6110259SAndrew.Bardsley@arm.com/** Minor will use the SimpleThread state for now */
6210259SAndrew.Bardsley@arm.comtypedef SimpleThread MinorThread;
6310259SAndrew.Bardsley@arm.com};
6410259SAndrew.Bardsley@arm.com
6510259SAndrew.Bardsley@arm.com/**
6610259SAndrew.Bardsley@arm.com *  MinorCPU is an in-order CPU model with four fixed pipeline stages:
6710259SAndrew.Bardsley@arm.com *
6810259SAndrew.Bardsley@arm.com *  Fetch1 - fetches lines from memory
6910259SAndrew.Bardsley@arm.com *  Fetch2 - decomposes lines into macro-op instructions
7010259SAndrew.Bardsley@arm.com *  Decode - decomposes macro-ops into micro-ops
7110259SAndrew.Bardsley@arm.com *  Execute - executes those micro-ops
7210259SAndrew.Bardsley@arm.com *
7310259SAndrew.Bardsley@arm.com *  This pipeline is carried in the MinorCPU::pipeline object.
7410259SAndrew.Bardsley@arm.com *  The exec_context interface is not carried by MinorCPU but by
7510259SAndrew.Bardsley@arm.com *      Minor::ExecContext objects
7610259SAndrew.Bardsley@arm.com *  created by Minor::Execute.
7710259SAndrew.Bardsley@arm.com */
7810259SAndrew.Bardsley@arm.comclass MinorCPU : public BaseCPU
7910259SAndrew.Bardsley@arm.com{
8010259SAndrew.Bardsley@arm.com  protected:
8110259SAndrew.Bardsley@arm.com    /** Event for delayed wakeup of a thread */
8210259SAndrew.Bardsley@arm.com    class ThreadActivateEvent : public Event
8310259SAndrew.Bardsley@arm.com    {
8410259SAndrew.Bardsley@arm.com      public:
8510259SAndrew.Bardsley@arm.com        MinorCPU &cpu;
8610259SAndrew.Bardsley@arm.com        ThreadID thread_id;
8710259SAndrew.Bardsley@arm.com
8810259SAndrew.Bardsley@arm.com        ThreadActivateEvent(MinorCPU &cpu_, ThreadID thread_id_) :
8910259SAndrew.Bardsley@arm.com            cpu(cpu_), thread_id(thread_id_)
9010259SAndrew.Bardsley@arm.com        { }
9110259SAndrew.Bardsley@arm.com
9210259SAndrew.Bardsley@arm.com        void process();
9310259SAndrew.Bardsley@arm.com    };
9410259SAndrew.Bardsley@arm.com
9510259SAndrew.Bardsley@arm.com    /** Events to wakeup each thread */
9610259SAndrew.Bardsley@arm.com    std::vector<ThreadActivateEvent *> threadActivateEvents;
9710259SAndrew.Bardsley@arm.com
9810259SAndrew.Bardsley@arm.com    /** pipeline is a container for the clockable pipeline stage objects.
9910259SAndrew.Bardsley@arm.com     *  Elements of pipeline call TheISA to implement the model. */
10010259SAndrew.Bardsley@arm.com    Minor::Pipeline *pipeline;
10110259SAndrew.Bardsley@arm.com
10210259SAndrew.Bardsley@arm.com  public:
10310259SAndrew.Bardsley@arm.com    /** Activity recording for pipeline.  This belongs to Pipeline but
10410259SAndrew.Bardsley@arm.com     *  stages will access it through the CPU as the MinorCPU object
10510259SAndrew.Bardsley@arm.com     *  actually mediates idling behaviour */
10610259SAndrew.Bardsley@arm.com    Minor::MinorActivityRecorder *activityRecorder;
10710259SAndrew.Bardsley@arm.com
10810259SAndrew.Bardsley@arm.com    /** These are thread state-representing objects for this CPU.  If
10910259SAndrew.Bardsley@arm.com     *  you need a ThreadContext for *any* reason, use
11010259SAndrew.Bardsley@arm.com     *  threads[threadId]->getTC() */
11110259SAndrew.Bardsley@arm.com    std::vector<Minor::MinorThread *> threads;
11210259SAndrew.Bardsley@arm.com
11310259SAndrew.Bardsley@arm.com  public:
11410259SAndrew.Bardsley@arm.com    /** Provide a non-protected base class for Minor's Ports as derived
11510259SAndrew.Bardsley@arm.com     *  classes are created by Fetch1 and Execute */
11610259SAndrew.Bardsley@arm.com    class MinorCPUPort : public MasterPort
11710259SAndrew.Bardsley@arm.com    {
11810259SAndrew.Bardsley@arm.com      public:
11910259SAndrew.Bardsley@arm.com        /** The enclosing cpu */
12010259SAndrew.Bardsley@arm.com        MinorCPU &cpu;
12110259SAndrew.Bardsley@arm.com
12210259SAndrew.Bardsley@arm.com      public:
12310259SAndrew.Bardsley@arm.com        MinorCPUPort(const std::string& name_, MinorCPU &cpu_)
12410259SAndrew.Bardsley@arm.com            : MasterPort(name_, &cpu_), cpu(cpu_)
12510259SAndrew.Bardsley@arm.com        { }
12610259SAndrew.Bardsley@arm.com
12710259SAndrew.Bardsley@arm.com      protected:
12810259SAndrew.Bardsley@arm.com        /** Snooping a coherence request, do nothing.  */
12910259SAndrew.Bardsley@arm.com        virtual void recvTimingSnoopReq(PacketPtr pkt) { }
13010259SAndrew.Bardsley@arm.com    };
13110259SAndrew.Bardsley@arm.com
13210259SAndrew.Bardsley@arm.com    /** The DrainManager passed into drain that needs be signalled when
13310259SAndrew.Bardsley@arm.com     *  draining is complete */
13410259SAndrew.Bardsley@arm.com    DrainManager *drainManager;
13510259SAndrew.Bardsley@arm.com
13610259SAndrew.Bardsley@arm.com  protected:
13710259SAndrew.Bardsley@arm.com     /** Return a reference to the data port. */
13810259SAndrew.Bardsley@arm.com    MasterPort &getDataPort();
13910259SAndrew.Bardsley@arm.com
14010259SAndrew.Bardsley@arm.com    /** Return a reference to the instruction port. */
14110259SAndrew.Bardsley@arm.com    MasterPort &getInstPort();
14210259SAndrew.Bardsley@arm.com
14310259SAndrew.Bardsley@arm.com  public:
14410259SAndrew.Bardsley@arm.com    MinorCPU(MinorCPUParams *params);
14510259SAndrew.Bardsley@arm.com
14610259SAndrew.Bardsley@arm.com    ~MinorCPU();
14710259SAndrew.Bardsley@arm.com
14810259SAndrew.Bardsley@arm.com  public:
14910259SAndrew.Bardsley@arm.com    /** Starting, waking and initialisation */
15010259SAndrew.Bardsley@arm.com    void init();
15110259SAndrew.Bardsley@arm.com    void startup();
15210259SAndrew.Bardsley@arm.com    void wakeup();
15310259SAndrew.Bardsley@arm.com
15410259SAndrew.Bardsley@arm.com    Addr dbg_vtophys(Addr addr);
15510259SAndrew.Bardsley@arm.com
15610259SAndrew.Bardsley@arm.com    /** Processor-specific statistics */
15710259SAndrew.Bardsley@arm.com    Minor::MinorStats stats;
15810259SAndrew.Bardsley@arm.com
15910259SAndrew.Bardsley@arm.com    /** Stats interface from SimObject (by way of BaseCPU) */
16010259SAndrew.Bardsley@arm.com    void regStats();
16110259SAndrew.Bardsley@arm.com
16210259SAndrew.Bardsley@arm.com    /** Simple inst count interface from BaseCPU */
16310259SAndrew.Bardsley@arm.com    Counter totalInsts() const;
16410259SAndrew.Bardsley@arm.com    Counter totalOps() const;
16510259SAndrew.Bardsley@arm.com
16610259SAndrew.Bardsley@arm.com    void serializeThread(std::ostream &os, ThreadID thread_id);
16710259SAndrew.Bardsley@arm.com    void unserializeThread(Checkpoint *cp, const std::string &section,
16810259SAndrew.Bardsley@arm.com        ThreadID thread_id);
16910259SAndrew.Bardsley@arm.com
17010259SAndrew.Bardsley@arm.com    /** Serialize pipeline data */
17110259SAndrew.Bardsley@arm.com    void serialize(std::ostream &os);
17210259SAndrew.Bardsley@arm.com    void unserialize(Checkpoint *cp, const std::string &section);
17310259SAndrew.Bardsley@arm.com
17410259SAndrew.Bardsley@arm.com    /** Drain interface */
17510259SAndrew.Bardsley@arm.com    unsigned int drain(DrainManager *drain_manager);
17610259SAndrew.Bardsley@arm.com    void drainResume();
17710259SAndrew.Bardsley@arm.com    /** Signal from Pipeline that MinorCPU should signal the DrainManager
17810259SAndrew.Bardsley@arm.com     *  that a drain is complete and set its drainState */
17910259SAndrew.Bardsley@arm.com    void signalDrainDone();
18010259SAndrew.Bardsley@arm.com    void memWriteback();
18110259SAndrew.Bardsley@arm.com
18210259SAndrew.Bardsley@arm.com    /** Switching interface from BaseCPU */
18310259SAndrew.Bardsley@arm.com    void switchOut();
18410259SAndrew.Bardsley@arm.com    void takeOverFrom(BaseCPU *old_cpu);
18510259SAndrew.Bardsley@arm.com
18610259SAndrew.Bardsley@arm.com    /** Thread activation interface from BaseCPU. */
18710259SAndrew.Bardsley@arm.com    void activateContext(ThreadID thread_id, Cycles delay);
18810259SAndrew.Bardsley@arm.com    void suspendContext(ThreadID thread_id);
18910259SAndrew.Bardsley@arm.com
19010259SAndrew.Bardsley@arm.com    /** Interface for stages to signal that they have become active after
19110259SAndrew.Bardsley@arm.com     *  a callback or eventq event where the pipeline itself may have
19210259SAndrew.Bardsley@arm.com     *  already been idled.  The stage argument should be from the
19310259SAndrew.Bardsley@arm.com     *  enumeration Pipeline::StageId */
19410259SAndrew.Bardsley@arm.com    void wakeupOnEvent(unsigned int stage_id);
19510259SAndrew.Bardsley@arm.com};
19610259SAndrew.Bardsley@arm.com
19710259SAndrew.Bardsley@arm.com#endif /* __CPU_MINOR_CPU_HH__ */
198