cpu.hh revision 10913
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    /** pipeline is a container for the clockable pipeline stage objects.
8210259SAndrew.Bardsley@arm.com     *  Elements of pipeline call TheISA to implement the model. */
8310259SAndrew.Bardsley@arm.com    Minor::Pipeline *pipeline;
8410259SAndrew.Bardsley@arm.com
8510259SAndrew.Bardsley@arm.com  public:
8610259SAndrew.Bardsley@arm.com    /** Activity recording for pipeline.  This belongs to Pipeline but
8710259SAndrew.Bardsley@arm.com     *  stages will access it through the CPU as the MinorCPU object
8810259SAndrew.Bardsley@arm.com     *  actually mediates idling behaviour */
8910259SAndrew.Bardsley@arm.com    Minor::MinorActivityRecorder *activityRecorder;
9010259SAndrew.Bardsley@arm.com
9110259SAndrew.Bardsley@arm.com    /** These are thread state-representing objects for this CPU.  If
9210259SAndrew.Bardsley@arm.com     *  you need a ThreadContext for *any* reason, use
9310259SAndrew.Bardsley@arm.com     *  threads[threadId]->getTC() */
9410259SAndrew.Bardsley@arm.com    std::vector<Minor::MinorThread *> threads;
9510259SAndrew.Bardsley@arm.com
9610259SAndrew.Bardsley@arm.com  public:
9710259SAndrew.Bardsley@arm.com    /** Provide a non-protected base class for Minor's Ports as derived
9810259SAndrew.Bardsley@arm.com     *  classes are created by Fetch1 and Execute */
9910259SAndrew.Bardsley@arm.com    class MinorCPUPort : public MasterPort
10010259SAndrew.Bardsley@arm.com    {
10110259SAndrew.Bardsley@arm.com      public:
10210259SAndrew.Bardsley@arm.com        /** The enclosing cpu */
10310259SAndrew.Bardsley@arm.com        MinorCPU &cpu;
10410259SAndrew.Bardsley@arm.com
10510259SAndrew.Bardsley@arm.com      public:
10610259SAndrew.Bardsley@arm.com        MinorCPUPort(const std::string& name_, MinorCPU &cpu_)
10710259SAndrew.Bardsley@arm.com            : MasterPort(name_, &cpu_), cpu(cpu_)
10810259SAndrew.Bardsley@arm.com        { }
10910259SAndrew.Bardsley@arm.com
11010259SAndrew.Bardsley@arm.com      protected:
11110259SAndrew.Bardsley@arm.com        /** Snooping a coherence request, do nothing.  */
11210259SAndrew.Bardsley@arm.com        virtual void recvTimingSnoopReq(PacketPtr pkt) { }
11310259SAndrew.Bardsley@arm.com    };
11410259SAndrew.Bardsley@arm.com
11510259SAndrew.Bardsley@arm.com  protected:
11610259SAndrew.Bardsley@arm.com     /** Return a reference to the data port. */
11710259SAndrew.Bardsley@arm.com    MasterPort &getDataPort();
11810259SAndrew.Bardsley@arm.com
11910259SAndrew.Bardsley@arm.com    /** Return a reference to the instruction port. */
12010259SAndrew.Bardsley@arm.com    MasterPort &getInstPort();
12110259SAndrew.Bardsley@arm.com
12210259SAndrew.Bardsley@arm.com  public:
12310259SAndrew.Bardsley@arm.com    MinorCPU(MinorCPUParams *params);
12410259SAndrew.Bardsley@arm.com
12510259SAndrew.Bardsley@arm.com    ~MinorCPU();
12610259SAndrew.Bardsley@arm.com
12710259SAndrew.Bardsley@arm.com  public:
12810259SAndrew.Bardsley@arm.com    /** Starting, waking and initialisation */
12910259SAndrew.Bardsley@arm.com    void init();
13010259SAndrew.Bardsley@arm.com    void startup();
13110259SAndrew.Bardsley@arm.com    void wakeup();
13210259SAndrew.Bardsley@arm.com
13310259SAndrew.Bardsley@arm.com    Addr dbg_vtophys(Addr addr);
13410259SAndrew.Bardsley@arm.com
13510259SAndrew.Bardsley@arm.com    /** Processor-specific statistics */
13610259SAndrew.Bardsley@arm.com    Minor::MinorStats stats;
13710259SAndrew.Bardsley@arm.com
13810259SAndrew.Bardsley@arm.com    /** Stats interface from SimObject (by way of BaseCPU) */
13910259SAndrew.Bardsley@arm.com    void regStats();
14010259SAndrew.Bardsley@arm.com
14110259SAndrew.Bardsley@arm.com    /** Simple inst count interface from BaseCPU */
14210259SAndrew.Bardsley@arm.com    Counter totalInsts() const;
14310259SAndrew.Bardsley@arm.com    Counter totalOps() const;
14410259SAndrew.Bardsley@arm.com
14510905Sandreas.sandberg@arm.com    void serializeThread(CheckpointOut &cp,
14610905Sandreas.sandberg@arm.com                         ThreadID tid) const M5_ATTR_OVERRIDE;
14710905Sandreas.sandberg@arm.com    void unserializeThread(CheckpointIn &cp, ThreadID tid) M5_ATTR_OVERRIDE;
14810259SAndrew.Bardsley@arm.com
14910259SAndrew.Bardsley@arm.com    /** Serialize pipeline data */
15010905Sandreas.sandberg@arm.com    void serialize(CheckpointOut &cp) const;
15110905Sandreas.sandberg@arm.com    void unserialize(CheckpointIn &cp);
15210259SAndrew.Bardsley@arm.com
15310259SAndrew.Bardsley@arm.com    /** Drain interface */
15410913Sandreas.sandberg@arm.com    DrainState drain() M5_ATTR_OVERRIDE;
15510913Sandreas.sandberg@arm.com    void drainResume() M5_ATTR_OVERRIDE;
15610913Sandreas.sandberg@arm.com    /** Signal from Pipeline that MinorCPU should signal that a drain
15710913Sandreas.sandberg@arm.com     *  is complete and set its drainState */
15810259SAndrew.Bardsley@arm.com    void signalDrainDone();
15910259SAndrew.Bardsley@arm.com    void memWriteback();
16010259SAndrew.Bardsley@arm.com
16110259SAndrew.Bardsley@arm.com    /** Switching interface from BaseCPU */
16210259SAndrew.Bardsley@arm.com    void switchOut();
16310259SAndrew.Bardsley@arm.com    void takeOverFrom(BaseCPU *old_cpu);
16410259SAndrew.Bardsley@arm.com
16510259SAndrew.Bardsley@arm.com    /** Thread activation interface from BaseCPU. */
16610407Smitch.hayenga@arm.com    void activateContext(ThreadID thread_id);
16710259SAndrew.Bardsley@arm.com    void suspendContext(ThreadID thread_id);
16810259SAndrew.Bardsley@arm.com
16910259SAndrew.Bardsley@arm.com    /** Interface for stages to signal that they have become active after
17010259SAndrew.Bardsley@arm.com     *  a callback or eventq event where the pipeline itself may have
17110259SAndrew.Bardsley@arm.com     *  already been idled.  The stage argument should be from the
17210259SAndrew.Bardsley@arm.com     *  enumeration Pipeline::StageId */
17310259SAndrew.Bardsley@arm.com    void wakeupOnEvent(unsigned int stage_id);
17410259SAndrew.Bardsley@arm.com};
17510259SAndrew.Bardsley@arm.com
17610259SAndrew.Bardsley@arm.com#endif /* __CPU_MINOR_CPU_HH__ */
177