base.hh revision 12122
12SN/A/*
29608Sandreas.hansson@arm.com * Copyright (c) 2011-2013 ARM Limited
38707Sandreas.hansson@arm.com * All rights reserved
48707Sandreas.hansson@arm.com *
58707Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68707Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78707Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88707Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98707Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108707Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118707Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128707Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138707Sandreas.hansson@arm.com *
141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
157897Shestness@cs.utexas.edu * Copyright (c) 2011 Regents of the University of California
162SN/A * All rights reserved.
172SN/A *
182SN/A * Redistribution and use in source and binary forms, with or without
192SN/A * modification, are permitted provided that the following conditions are
202SN/A * met: redistributions of source code must retain the above copyright
212SN/A * notice, this list of conditions and the following disclaimer;
222SN/A * redistributions in binary form must reproduce the above copyright
232SN/A * notice, this list of conditions and the following disclaimer in the
242SN/A * documentation and/or other materials provided with the distribution;
252SN/A * neither the name of the copyright holders nor the names of its
262SN/A * contributors may be used to endorse or promote products derived from
272SN/A * this software without specific prior written permission.
282SN/A *
292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
422665Ssaidi@eecs.umich.edu *          Nathan Binkert
437897Shestness@cs.utexas.edu *          Rick Strong
442SN/A */
452SN/A
461717SN/A#ifndef __CPU_BASE_HH__
471717SN/A#define __CPU_BASE_HH__
482SN/A
492SN/A#include <vector>
502SN/A
519850Sandreas.hansson@arm.com// Before we do anything else, check if this build is the NULL ISA,
529850Sandreas.hansson@arm.com// and if so stop here
539850Sandreas.hansson@arm.com#include "config/the_isa.hh"
549850Sandreas.hansson@arm.com#if THE_ISA == NULL_ISA
559850Sandreas.hansson@arm.com#include "arch/null/cpu_dummy.hh"
569850Sandreas.hansson@arm.com#else
578745Sgblack@eecs.umich.edu#include "arch/interrupts.hh"
584182Sgblack@eecs.umich.edu#include "arch/isa_traits.hh"
595664Sgblack@eecs.umich.edu#include "arch/microcode_rom.hh"
60707SN/A#include "base/statistics.hh"
618229Snate@binkert.org#include "mem/mem_object.hh"
6256SN/A#include "sim/eventq.hh"
638779Sgblack@eecs.umich.edu#include "sim/full_system.hh"
644776Sgblack@eecs.umich.edu#include "sim/insttracer.hh"
6510464SAndreas.Sandberg@ARM.com#include "sim/probe/pmu.hh"
669814Sandreas.hansson@arm.com#include "sim/system.hh"
6710529Smorr@cs.wisc.edu#include "debug/Mwait.hh"
682SN/A
6910529Smorr@cs.wisc.educlass BaseCPU;
708901Sandreas.hansson@arm.comstruct BaseCPUParams;
712315SN/Aclass CheckerCPU;
722680Sktlim@umich.educlass ThreadContext;
732SN/A
7410529Smorr@cs.wisc.edustruct AddressMonitor
7510529Smorr@cs.wisc.edu{
7610529Smorr@cs.wisc.edu    AddressMonitor();
7710529Smorr@cs.wisc.edu    bool doMonitor(PacketPtr pkt);
7810529Smorr@cs.wisc.edu
7910529Smorr@cs.wisc.edu    bool armed;
8010529Smorr@cs.wisc.edu    Addr vAddr;
8110529Smorr@cs.wisc.edu    Addr pAddr;
8210529Smorr@cs.wisc.edu    uint64_t val;
8310529Smorr@cs.wisc.edu    bool waiting;   // 0=normal, 1=mwaiting
8410529Smorr@cs.wisc.edu    bool gotWakeup;
8510529Smorr@cs.wisc.edu};
8610529Smorr@cs.wisc.edu
872356SN/Aclass CPUProgressEvent : public Event
882356SN/A{
892356SN/A  protected:
906144Sksewell@umich.edu    Tick _interval;
912356SN/A    Counter lastNumInst;
922356SN/A    BaseCPU *cpu;
936144Sksewell@umich.edu    bool _repeatEvent;
942356SN/A
952356SN/A  public:
966144Sksewell@umich.edu    CPUProgressEvent(BaseCPU *_cpu, Tick ival = 0);
972356SN/A
982356SN/A    void process();
992356SN/A
1006144Sksewell@umich.edu    void interval(Tick ival) { _interval = ival; }
1016144Sksewell@umich.edu    Tick interval() { return _interval; }
1026144Sksewell@umich.edu
1036144Sksewell@umich.edu    void repeatEvent(bool repeat) { _repeatEvent = repeat; }
1046144Sksewell@umich.edu
1055336Shines@cs.fsu.edu    virtual const char *description() const;
1062356SN/A};
1072356SN/A
1082856Srdreslin@umich.educlass BaseCPU : public MemObject
1092SN/A{
1101634SN/A  protected:
1119157Sandreas.hansson@arm.com
11210662SAli.Saidi@ARM.com    /// Instruction count used for SPARC misc register
11310662SAli.Saidi@ARM.com    /// @todo unify this with the counters that cpus individually keep
1143814Ssaidi@eecs.umich.edu    Tick instCnt;
11510662SAli.Saidi@ARM.com
1165712Shsul@eecs.umich.edu    // every cpu has an id, put it in the base cpu
1175712Shsul@eecs.umich.edu    // Set at initialization, only time a cpuId might change is during a
1185715Shsul@eecs.umich.edu    // takeover (which should be done from within the BaseCPU anyway,
1195712Shsul@eecs.umich.edu    // therefore no setCpuId() method is provided
1205712Shsul@eecs.umich.edu    int _cpuId;
1211634SN/A
12210190Sakash.bagdia@arm.com    /** Each cpu will have a socket ID that corresponds to its physical location
12310190Sakash.bagdia@arm.com     * in the system. This is usually used to bucket cpu cores under single DVFS
12410190Sakash.bagdia@arm.com     * domain. This information may also be required by the OS to identify the
12510190Sakash.bagdia@arm.com     * cpu core grouping (as in the case of ARM via MPIDR register)
12610190Sakash.bagdia@arm.com     */
12710190Sakash.bagdia@arm.com    const uint32_t _socketId;
12810190Sakash.bagdia@arm.com
1298832SAli.Saidi@ARM.com    /** instruction side request id that must be placed in all requests */
1308832SAli.Saidi@ARM.com    MasterID _instMasterId;
1318832SAli.Saidi@ARM.com
1328832SAli.Saidi@ARM.com    /** data side request id that must be placed in all requests */
1338832SAli.Saidi@ARM.com    MasterID _dataMasterId;
1348832SAli.Saidi@ARM.com
1359332Sdam.sunwoo@arm.com    /** An intrenal representation of a task identifier within gem5. This is
1369332Sdam.sunwoo@arm.com     * used so the CPU can add which taskId (which is an internal representation
1379332Sdam.sunwoo@arm.com     * of the OS process ID) to each request so components in the memory system
1389332Sdam.sunwoo@arm.com     * can track which process IDs are ultimately interacting with them
1399332Sdam.sunwoo@arm.com     */
1409332Sdam.sunwoo@arm.com    uint32_t _taskId;
1419332Sdam.sunwoo@arm.com
1429332Sdam.sunwoo@arm.com    /** The current OS process ID that is executing on this processor. This is
1439332Sdam.sunwoo@arm.com     * used to generate a taskId */
1449332Sdam.sunwoo@arm.com    uint32_t _pid;
1459332Sdam.sunwoo@arm.com
1469430SAndreas.Sandberg@ARM.com    /** Is the CPU switched out or active? */
1479430SAndreas.Sandberg@ARM.com    bool _switchedOut;
1489430SAndreas.Sandberg@ARM.com
1499814Sandreas.hansson@arm.com    /** Cache the cache line size that we get from the system */
1509814Sandreas.hansson@arm.com    const unsigned int _cacheLineSize;
1519814Sandreas.hansson@arm.com
1521634SN/A  public:
1538850Sandreas.hansson@arm.com
1548850Sandreas.hansson@arm.com    /**
1558850Sandreas.hansson@arm.com     * Purely virtual method that returns a reference to the data
1568850Sandreas.hansson@arm.com     * port. All subclasses must implement this method.
1578850Sandreas.hansson@arm.com     *
1588850Sandreas.hansson@arm.com     * @return a reference to the data port
1598850Sandreas.hansson@arm.com     */
1609608Sandreas.hansson@arm.com    virtual MasterPort &getDataPort() = 0;
1618850Sandreas.hansson@arm.com
1628850Sandreas.hansson@arm.com    /**
1638850Sandreas.hansson@arm.com     * Purely virtual method that returns a reference to the instruction
1648850Sandreas.hansson@arm.com     * port. All subclasses must implement this method.
1658850Sandreas.hansson@arm.com     *
1668850Sandreas.hansson@arm.com     * @return a reference to the instruction port
1678850Sandreas.hansson@arm.com     */
1689608Sandreas.hansson@arm.com    virtual MasterPort &getInstPort() = 0;
1698850Sandreas.hansson@arm.com
1705712Shsul@eecs.umich.edu    /** Reads this CPU's ID. */
17110110Sandreas.hansson@arm.com    int cpuId() const { return _cpuId; }
1725712Shsul@eecs.umich.edu
17310190Sakash.bagdia@arm.com    /** Reads this CPU's Socket ID. */
17410190Sakash.bagdia@arm.com    uint32_t socketId() const { return _socketId; }
17510190Sakash.bagdia@arm.com
1768832SAli.Saidi@ARM.com    /** Reads this CPU's unique data requestor ID */
1778832SAli.Saidi@ARM.com    MasterID dataMasterId() { return _dataMasterId; }
1788832SAli.Saidi@ARM.com    /** Reads this CPU's unique instruction requestor ID */
1798832SAli.Saidi@ARM.com    MasterID instMasterId() { return _instMasterId; }
1808832SAli.Saidi@ARM.com
1818850Sandreas.hansson@arm.com    /**
1828926Sandreas.hansson@arm.com     * Get a master port on this CPU. All CPUs have a data and
1838926Sandreas.hansson@arm.com     * instruction port, and this method uses getDataPort and
1848926Sandreas.hansson@arm.com     * getInstPort of the subclasses to resolve the two ports.
1858850Sandreas.hansson@arm.com     *
1868850Sandreas.hansson@arm.com     * @param if_name the port name
1878850Sandreas.hansson@arm.com     * @param idx ignored index
1888850Sandreas.hansson@arm.com     *
1898922Swilliam.wang@arm.com     * @return a reference to the port with the given name
1908850Sandreas.hansson@arm.com     */
1919294Sandreas.hansson@arm.com    BaseMasterPort &getMasterPort(const std::string &if_name,
19211169Sandreas.hansson@arm.com                                  PortID idx = InvalidPortID) override;
1938850Sandreas.hansson@arm.com
1949332Sdam.sunwoo@arm.com    /** Get cpu task id */
1959332Sdam.sunwoo@arm.com    uint32_t taskId() const { return _taskId; }
1969332Sdam.sunwoo@arm.com    /** Set cpu task id */
1979332Sdam.sunwoo@arm.com    void taskId(uint32_t id) { _taskId = id; }
1989332Sdam.sunwoo@arm.com
1999332Sdam.sunwoo@arm.com    uint32_t getPid() const { return _pid; }
2009332Sdam.sunwoo@arm.com    void setPid(uint32_t pid) { _pid = pid; }
2019332Sdam.sunwoo@arm.com
2027914SBrad.Beckmann@amd.com    inline void workItemBegin() { numWorkItemsStarted++; }
2037914SBrad.Beckmann@amd.com    inline void workItemEnd() { numWorkItemsCompleted++; }
2043814Ssaidi@eecs.umich.edu    // @todo remove me after debugging with legion done
2053814Ssaidi@eecs.umich.edu    Tick instCount() { return instCnt; }
2061634SN/A
2075664Sgblack@eecs.umich.edu    TheISA::MicrocodeRom microcodeRom;
2085664Sgblack@eecs.umich.edu
2092SN/A  protected:
21011150Smitch.hayenga@arm.com    std::vector<TheISA::Interrupts*> interrupts;
2112SN/A
2122SN/A  public:
2135645Sgblack@eecs.umich.edu    TheISA::Interrupts *
21411150Smitch.hayenga@arm.com    getInterruptController(ThreadID tid)
2155645Sgblack@eecs.umich.edu    {
21611150Smitch.hayenga@arm.com        if (interrupts.empty())
21711150Smitch.hayenga@arm.com            return NULL;
21811150Smitch.hayenga@arm.com
21911150Smitch.hayenga@arm.com        assert(interrupts.size() > tid);
22011150Smitch.hayenga@arm.com        return interrupts[tid];
2215645Sgblack@eecs.umich.edu    }
2225645Sgblack@eecs.umich.edu
22311151Smitch.hayenga@arm.com    virtual void wakeup(ThreadID tid) = 0;
2245807Snate@binkert.org
2255807Snate@binkert.org    void
22611150Smitch.hayenga@arm.com    postInterrupt(ThreadID tid, int int_num, int index)
2275807Snate@binkert.org    {
22811150Smitch.hayenga@arm.com        interrupts[tid]->post(int_num, index);
2298779Sgblack@eecs.umich.edu        if (FullSystem)
23011151Smitch.hayenga@arm.com            wakeup(tid);
2315807Snate@binkert.org    }
2325807Snate@binkert.org
2335807Snate@binkert.org    void
23411150Smitch.hayenga@arm.com    clearInterrupt(ThreadID tid, int int_num, int index)
2355807Snate@binkert.org    {
23611150Smitch.hayenga@arm.com        interrupts[tid]->clear(int_num, index);
2375807Snate@binkert.org    }
2385807Snate@binkert.org
2395807Snate@binkert.org    void
24011150Smitch.hayenga@arm.com    clearInterrupts(ThreadID tid)
2415807Snate@binkert.org    {
24211150Smitch.hayenga@arm.com        interrupts[tid]->clearAll();
2435807Snate@binkert.org    }
2442SN/A
2455704Snate@binkert.org    bool
2465704Snate@binkert.org    checkInterrupts(ThreadContext *tc) const
2475704Snate@binkert.org    {
24811150Smitch.hayenga@arm.com        return FullSystem && interrupts[tc->threadId()]->checkInterrupts(tc);
2495704Snate@binkert.org    }
2501917SN/A
2511917SN/A    class ProfileEvent : public Event
2521917SN/A    {
2531917SN/A      private:
2541917SN/A        BaseCPU *cpu;
2555536Srstrong@hp.com        Tick interval;
2561917SN/A
2571917SN/A      public:
2585536Srstrong@hp.com        ProfileEvent(BaseCPU *cpu, Tick interval);
2591917SN/A        void process();
2601917SN/A    };
2611917SN/A    ProfileEvent *profileEvent;
2622SN/A
2632SN/A  protected:
2642680Sktlim@umich.edu    std::vector<ThreadContext *> threadContexts;
2652SN/A
2664776Sgblack@eecs.umich.edu    Trace::InstTracer * tracer;
2674776Sgblack@eecs.umich.edu
2682SN/A  public:
269393SN/A
27011050Sandreas.hansson@arm.com
27111050Sandreas.hansson@arm.com    /** Invalid or unknown Pid. Possible when operating system is not present
27211050Sandreas.hansson@arm.com     *  or has not assigned a pid yet */
27311050Sandreas.hansson@arm.com    static const uint32_t invldPid = std::numeric_limits<uint32_t>::max();
27411050Sandreas.hansson@arm.com
2757764Sgblack@eecs.umich.edu    // Mask to align PCs to MachInst sized boundaries
2767764Sgblack@eecs.umich.edu    static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1);
2777764Sgblack@eecs.umich.edu
2784776Sgblack@eecs.umich.edu    /// Provide access to the tracer pointer
2794776Sgblack@eecs.umich.edu    Trace::InstTracer * getTracer() { return tracer; }
2804776Sgblack@eecs.umich.edu
28110407Smitch.hayenga@arm.com    /// Notify the CPU that the indicated context is now active.
28211526Sdavid.guillen@arm.com    virtual void activateContext(ThreadID thread_num);
283393SN/A
284393SN/A    /// Notify the CPU that the indicated context is now suspended.
28511526Sdavid.guillen@arm.com    /// Check if possible to enter a lower power state
28611526Sdavid.guillen@arm.com    virtual void suspendContext(ThreadID thread_num);
287393SN/A
288393SN/A    /// Notify the CPU that the indicated context is now halted.
2898737Skoansin.tan@gmail.com    virtual void haltContext(ThreadID thread_num) {}
2902SN/A
2914000Ssaidi@eecs.umich.edu   /// Given a Thread Context pointer return the thread num
2924000Ssaidi@eecs.umich.edu   int findContext(ThreadContext *tc);
2934000Ssaidi@eecs.umich.edu
2944000Ssaidi@eecs.umich.edu   /// Given a thread num get tho thread context for it
2959652SAndreas.Sandberg@ARM.com   virtual ThreadContext *getContext(int tn) { return threadContexts[tn]; }
2964000Ssaidi@eecs.umich.edu
29710030SAli.Saidi@ARM.com   /// Get the number of thread contexts available
29810030SAli.Saidi@ARM.com   unsigned numContexts() { return threadContexts.size(); }
29910030SAli.Saidi@ARM.com
30011435Smitch.hayenga@arm.com    /// Convert ContextID to threadID
30111435Smitch.hayenga@arm.com    ThreadID contextToThread(ContextID cid)
30211435Smitch.hayenga@arm.com    { return static_cast<ThreadID>(cid - threadContexts[0]->contextId()); }
30311435Smitch.hayenga@arm.com
3042SN/A  public:
3055529Snate@binkert.org    typedef BaseCPUParams Params;
3065529Snate@binkert.org    const Params *params() const
3075529Snate@binkert.org    { return reinterpret_cast<const Params *>(_params); }
3088876Sandreas.hansson@arm.com    BaseCPU(Params *params, bool is_checker = false);
3091191SN/A    virtual ~BaseCPU();
3102SN/A
31111169Sandreas.hansson@arm.com    void init() override;
31211169Sandreas.hansson@arm.com    void startup() override;
31311169Sandreas.hansson@arm.com    void regStats() override;
3142SN/A
31511168Sandreas.hansson@arm.com    void regProbePoints() override;
31610464SAndreas.Sandberg@ARM.com
3172680Sktlim@umich.edu    void registerThreadContexts();
318180SN/A
3199254SAndreas.Sandberg@arm.com    /**
3209254SAndreas.Sandberg@arm.com     * Prepare for another CPU to take over execution.
3219254SAndreas.Sandberg@arm.com     *
3229254SAndreas.Sandberg@arm.com     * When this method exits, all internal state should have been
3239254SAndreas.Sandberg@arm.com     * flushed. After the method returns, the simulator calls
3249254SAndreas.Sandberg@arm.com     * takeOverFrom() on the new CPU with this CPU as its parameter.
3259254SAndreas.Sandberg@arm.com     */
3262798Sktlim@umich.edu    virtual void switchOut();
327180SN/A
3289254SAndreas.Sandberg@arm.com    /**
3299254SAndreas.Sandberg@arm.com     * Load the state of a CPU from the previous CPU object, invoked
3309254SAndreas.Sandberg@arm.com     * on all new CPUs that are about to be switched in.
3319254SAndreas.Sandberg@arm.com     *
3329254SAndreas.Sandberg@arm.com     * A CPU model implementing this method is expected to initialize
3339254SAndreas.Sandberg@arm.com     * its state from the old CPU and connect its memory (unless they
3349254SAndreas.Sandberg@arm.com     * are already connected) to the memories connected to the old
3359254SAndreas.Sandberg@arm.com     * CPU.
3369254SAndreas.Sandberg@arm.com     *
3379254SAndreas.Sandberg@arm.com     * @param cpu CPU to initialize read state from.
3389254SAndreas.Sandberg@arm.com     */
3399254SAndreas.Sandberg@arm.com    virtual void takeOverFrom(BaseCPU *cpu);
340180SN/A
341124SN/A    /**
3429446SAndreas.Sandberg@ARM.com     * Flush all TLBs in the CPU.
3439446SAndreas.Sandberg@ARM.com     *
3449446SAndreas.Sandberg@ARM.com     * This method is mainly used to flush stale translations when
3459446SAndreas.Sandberg@ARM.com     * switching CPUs. It is also exported to the Python world to
3469446SAndreas.Sandberg@ARM.com     * allow it to request a TLB flush after draining the CPU to make
3479446SAndreas.Sandberg@ARM.com     * it easier to compare traces when debugging
3489446SAndreas.Sandberg@ARM.com     * handover/checkpointing.
3499446SAndreas.Sandberg@ARM.com     */
3509446SAndreas.Sandberg@ARM.com    void flushTLBs();
3519446SAndreas.Sandberg@ARM.com
3529446SAndreas.Sandberg@ARM.com    /**
3539430SAndreas.Sandberg@ARM.com     * Determine if the CPU is switched out.
3549430SAndreas.Sandberg@ARM.com     *
3559430SAndreas.Sandberg@ARM.com     * @return True if the CPU is switched out, false otherwise.
3569430SAndreas.Sandberg@ARM.com     */
3579430SAndreas.Sandberg@ARM.com    bool switchedOut() const { return _switchedOut; }
3589430SAndreas.Sandberg@ARM.com
3599430SAndreas.Sandberg@ARM.com    /**
3609523SAndreas.Sandberg@ARM.com     * Verify that the system is in a memory mode supported by the
3619523SAndreas.Sandberg@ARM.com     * CPU.
3629523SAndreas.Sandberg@ARM.com     *
3639523SAndreas.Sandberg@ARM.com     * Implementations are expected to query the system for the
3649523SAndreas.Sandberg@ARM.com     * current memory mode and ensure that it is what the CPU model
3659523SAndreas.Sandberg@ARM.com     * expects. If the check fails, the implementation should
3669523SAndreas.Sandberg@ARM.com     * terminate the simulation using fatal().
3679523SAndreas.Sandberg@ARM.com     */
3689523SAndreas.Sandberg@ARM.com    virtual void verifyMemoryMode() const { };
3699523SAndreas.Sandberg@ARM.com
3709523SAndreas.Sandberg@ARM.com    /**
371124SN/A     *  Number of threads we're actually simulating (<= SMT_MAX_THREADS).
372124SN/A     * This is a constant for the duration of the simulation.
373124SN/A     */
3746221Snate@binkert.org    ThreadID numThreads;
3752SN/A
376124SN/A    /**
377124SN/A     * Vector of per-thread instruction-based event queues.  Used for
378124SN/A     * scheduling events based on number of instructions committed by
379124SN/A     * a particular thread.
380124SN/A     */
381503SN/A    EventQueue **comInstEventQueue;
3822SN/A
383124SN/A    /**
384124SN/A     * Vector of per-thread load-based event queues.  Used for
385124SN/A     * scheduling events based on number of loads committed by
386124SN/A     *a particular thread.
387124SN/A     */
388124SN/A    EventQueue **comLoadEventQueue;
389124SN/A
3902SN/A    System *system;
391921SN/A
392921SN/A    /**
3939814Sandreas.hansson@arm.com     * Get the cache line size of the system.
3949814Sandreas.hansson@arm.com     */
3959814Sandreas.hansson@arm.com    inline unsigned int cacheLineSize() const { return _cacheLineSize; }
3969814Sandreas.hansson@arm.com
3979814Sandreas.hansson@arm.com    /**
398921SN/A     * Serialize this object to the given output stream.
3999448SAndreas.Sandberg@ARM.com     *
4009448SAndreas.Sandberg@ARM.com     * @note CPU models should normally overload the serializeThread()
4019448SAndreas.Sandberg@ARM.com     * method instead of the serialize() method as this provides a
4029448SAndreas.Sandberg@ARM.com     * uniform data format for all CPU models and promotes better code
4039448SAndreas.Sandberg@ARM.com     * reuse.
4049448SAndreas.Sandberg@ARM.com     *
405921SN/A     * @param os The stream to serialize to.
406921SN/A     */
40711168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
408921SN/A
409921SN/A    /**
410921SN/A     * Reconstruct the state of this object from a checkpoint.
4119448SAndreas.Sandberg@ARM.com     *
4129448SAndreas.Sandberg@ARM.com     * @note CPU models should normally overload the
4139448SAndreas.Sandberg@ARM.com     * unserializeThread() method instead of the unserialize() method
4149448SAndreas.Sandberg@ARM.com     * as this provides a uniform data format for all CPU models and
4159448SAndreas.Sandberg@ARM.com     * promotes better code reuse.
4169448SAndreas.Sandberg@ARM.com
417921SN/A     * @param cp The checkpoint use.
4189448SAndreas.Sandberg@ARM.com     * @param section The section name of this object.
419921SN/A     */
42011168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
421921SN/A
422124SN/A    /**
4239448SAndreas.Sandberg@ARM.com     * Serialize a single thread.
4249448SAndreas.Sandberg@ARM.com     *
4259448SAndreas.Sandberg@ARM.com     * @param os The stream to serialize to.
4269448SAndreas.Sandberg@ARM.com     * @param tid ID of the current thread.
4279448SAndreas.Sandberg@ARM.com     */
42810905Sandreas.sandberg@arm.com    virtual void serializeThread(CheckpointOut &cp, ThreadID tid) const {};
4299448SAndreas.Sandberg@ARM.com
4309448SAndreas.Sandberg@ARM.com    /**
4319448SAndreas.Sandberg@ARM.com     * Unserialize one thread.
4329448SAndreas.Sandberg@ARM.com     *
4339448SAndreas.Sandberg@ARM.com     * @param cp The checkpoint use.
4349448SAndreas.Sandberg@ARM.com     * @param section The section name of this thread.
4359448SAndreas.Sandberg@ARM.com     * @param tid ID of the current thread.
4369448SAndreas.Sandberg@ARM.com     */
43710905Sandreas.sandberg@arm.com    virtual void unserializeThread(CheckpointIn &cp, ThreadID tid) {};
4389448SAndreas.Sandberg@ARM.com
4398834Satgutier@umich.edu    virtual Counter totalInsts() const = 0;
4408834Satgutier@umich.edu
4418834Satgutier@umich.edu    virtual Counter totalOps() const = 0;
442707SN/A
4439749Sandreas@sandberg.pp.se    /**
4449749Sandreas@sandberg.pp.se     * Schedule an event that exits the simulation loops after a
4459749Sandreas@sandberg.pp.se     * predefined number of instructions.
4469749Sandreas@sandberg.pp.se     *
4479749Sandreas@sandberg.pp.se     * This method is usually called from the configuration script to
4489749Sandreas@sandberg.pp.se     * get an exit event some time in the future. It is typically used
4499749Sandreas@sandberg.pp.se     * when the script wants to simulate for a specific number of
4509749Sandreas@sandberg.pp.se     * instructions rather than ticks.
4519749Sandreas@sandberg.pp.se     *
4529749Sandreas@sandberg.pp.se     * @param tid Thread monitor.
4539749Sandreas@sandberg.pp.se     * @param insts Number of instructions into the future.
4549749Sandreas@sandberg.pp.se     * @param cause Cause to signal in the exit event.
4559749Sandreas@sandberg.pp.se     */
4569749Sandreas@sandberg.pp.se    void scheduleInstStop(ThreadID tid, Counter insts, const char *cause);
4579749Sandreas@sandberg.pp.se
4589749Sandreas@sandberg.pp.se    /**
4599749Sandreas@sandberg.pp.se     * Schedule an event that exits the simulation loops after a
4609749Sandreas@sandberg.pp.se     * predefined number of load operations.
4619749Sandreas@sandberg.pp.se     *
4629749Sandreas@sandberg.pp.se     * This method is usually called from the configuration script to
4639749Sandreas@sandberg.pp.se     * get an exit event some time in the future. It is typically used
4649749Sandreas@sandberg.pp.se     * when the script wants to simulate for a specific number of
4659749Sandreas@sandberg.pp.se     * loads rather than ticks.
4669749Sandreas@sandberg.pp.se     *
4679749Sandreas@sandberg.pp.se     * @param tid Thread monitor.
4689749Sandreas@sandberg.pp.se     * @param loads Number of load instructions into the future.
4699749Sandreas@sandberg.pp.se     * @param cause Cause to signal in the exit event.
4709749Sandreas@sandberg.pp.se     */
4719749Sandreas@sandberg.pp.se    void scheduleLoadStop(ThreadID tid, Counter loads, const char *cause);
4729749Sandreas@sandberg.pp.se
47311415SGeoffrey.Blake@arm.com    /**
47411415SGeoffrey.Blake@arm.com     * Get the number of instructions executed by the specified thread
47511415SGeoffrey.Blake@arm.com     * on this CPU. Used by Python to control simulation.
47611415SGeoffrey.Blake@arm.com     *
47711415SGeoffrey.Blake@arm.com     * @param tid Thread monitor
47811415SGeoffrey.Blake@arm.com     * @return Number of instructions executed
47911415SGeoffrey.Blake@arm.com     */
48011415SGeoffrey.Blake@arm.com    uint64_t getCurrentInstCount(ThreadID tid);
48111415SGeoffrey.Blake@arm.com
48210464SAndreas.Sandberg@ARM.com  public:
48310464SAndreas.Sandberg@ARM.com    /**
48410464SAndreas.Sandberg@ARM.com     * @{
48510464SAndreas.Sandberg@ARM.com     * @name PMU Probe points.
48610464SAndreas.Sandberg@ARM.com     */
48710464SAndreas.Sandberg@ARM.com
48810464SAndreas.Sandberg@ARM.com    /**
48910464SAndreas.Sandberg@ARM.com     * Helper method to trigger PMU probes for a committed
49010464SAndreas.Sandberg@ARM.com     * instruction.
49110464SAndreas.Sandberg@ARM.com     *
49210464SAndreas.Sandberg@ARM.com     * @param inst Instruction that just committed
49310464SAndreas.Sandberg@ARM.com     */
49410464SAndreas.Sandberg@ARM.com    virtual void probeInstCommit(const StaticInstPtr &inst);
49510464SAndreas.Sandberg@ARM.com
49610464SAndreas.Sandberg@ARM.com    /**
49710464SAndreas.Sandberg@ARM.com     * Helper method to instantiate probe points belonging to this
49810464SAndreas.Sandberg@ARM.com     * object.
49910464SAndreas.Sandberg@ARM.com     *
50010464SAndreas.Sandberg@ARM.com     * @param name Name of the probe point.
50110464SAndreas.Sandberg@ARM.com     * @return A unique_ptr to the new probe point.
50210464SAndreas.Sandberg@ARM.com     */
50310464SAndreas.Sandberg@ARM.com    ProbePoints::PMUUPtr pmuProbePoint(const char *name);
50410464SAndreas.Sandberg@ARM.com
50510464SAndreas.Sandberg@ARM.com    /** CPU cycle counter */
50610464SAndreas.Sandberg@ARM.com    ProbePoints::PMUUPtr ppCycles;
50710464SAndreas.Sandberg@ARM.com
50810464SAndreas.Sandberg@ARM.com    /**
50910464SAndreas.Sandberg@ARM.com     * Instruction commit probe point.
51010464SAndreas.Sandberg@ARM.com     *
51110464SAndreas.Sandberg@ARM.com     * This probe point is triggered whenever one or more instructions
51210464SAndreas.Sandberg@ARM.com     * are committed. It is normally triggered once for every
51310464SAndreas.Sandberg@ARM.com     * instruction. However, CPU models committing bundles of
51410464SAndreas.Sandberg@ARM.com     * instructions may call notify once for the entire bundle.
51510464SAndreas.Sandberg@ARM.com     */
51610464SAndreas.Sandberg@ARM.com    ProbePoints::PMUUPtr ppRetiredInsts;
51710464SAndreas.Sandberg@ARM.com
51810464SAndreas.Sandberg@ARM.com    /** Retired load instructions */
51910464SAndreas.Sandberg@ARM.com    ProbePoints::PMUUPtr ppRetiredLoads;
52010464SAndreas.Sandberg@ARM.com    /** Retired store instructions */
52110464SAndreas.Sandberg@ARM.com    ProbePoints::PMUUPtr ppRetiredStores;
52210464SAndreas.Sandberg@ARM.com
52310464SAndreas.Sandberg@ARM.com    /** Retired branches (any type) */
52410464SAndreas.Sandberg@ARM.com    ProbePoints::PMUUPtr ppRetiredBranches;
52510464SAndreas.Sandberg@ARM.com
52610464SAndreas.Sandberg@ARM.com    /** @} */
52710464SAndreas.Sandberg@ARM.com
52810464SAndreas.Sandberg@ARM.com
52910464SAndreas.Sandberg@ARM.com
5301191SN/A    // Function tracing
5311191SN/A  private:
5321191SN/A    bool functionTracingEnabled;
5331191SN/A    std::ostream *functionTraceStream;
5341191SN/A    Addr currentFunctionStart;
5351191SN/A    Addr currentFunctionEnd;
5361191SN/A    Tick functionEntryTick;
5371191SN/A    void enableFunctionTrace();
5381191SN/A    void traceFunctionsInternal(Addr pc);
5391191SN/A
5408662SAli.Saidi@ARM.com  private:
5418662SAli.Saidi@ARM.com    static std::vector<BaseCPU *> cpuList;   //!< Static global cpu list
5428662SAli.Saidi@ARM.com
5438662SAli.Saidi@ARM.com  public:
5441191SN/A    void traceFunctions(Addr pc)
5451191SN/A    {
5461191SN/A        if (functionTracingEnabled)
5471191SN/A            traceFunctionsInternal(pc);
5481191SN/A    }
5491191SN/A
5502SN/A    static int numSimulatedCPUs() { return cpuList.size(); }
5518834Satgutier@umich.edu    static Counter numSimulatedInsts()
552707SN/A    {
553707SN/A        Counter total = 0;
554707SN/A
555707SN/A        int size = cpuList.size();
556707SN/A        for (int i = 0; i < size; ++i)
5578834Satgutier@umich.edu            total += cpuList[i]->totalInsts();
5588834Satgutier@umich.edu
5598834Satgutier@umich.edu        return total;
5608834Satgutier@umich.edu    }
5618834Satgutier@umich.edu
5628834Satgutier@umich.edu    static Counter numSimulatedOps()
5638834Satgutier@umich.edu    {
5648834Satgutier@umich.edu        Counter total = 0;
5658834Satgutier@umich.edu
5668834Satgutier@umich.edu        int size = cpuList.size();
5678834Satgutier@umich.edu        for (int i = 0; i < size; ++i)
5688834Satgutier@umich.edu            total += cpuList[i]->totalOps();
569707SN/A
570707SN/A        return total;
571707SN/A    }
572707SN/A
573707SN/A  public:
574707SN/A    // Number of CPU cycles simulated
5755999Snate@binkert.org    Stats::Scalar numCycles;
5767914SBrad.Beckmann@amd.com    Stats::Scalar numWorkItemsStarted;
5777914SBrad.Beckmann@amd.com    Stats::Scalar numWorkItemsCompleted;
57810529Smorr@cs.wisc.edu
57910529Smorr@cs.wisc.edu  private:
58011148Smitch.hayenga@arm.com    std::vector<AddressMonitor> addressMonitor;
58110529Smorr@cs.wisc.edu
58210529Smorr@cs.wisc.edu  public:
58311148Smitch.hayenga@arm.com    void armMonitor(ThreadID tid, Addr address);
58411148Smitch.hayenga@arm.com    bool mwait(ThreadID tid, PacketPtr pkt);
58511148Smitch.hayenga@arm.com    void mwaitAtomic(ThreadID tid, ThreadContext *tc, TheISA::TLB *dtb);
58611148Smitch.hayenga@arm.com    AddressMonitor *getCpuAddrMonitor(ThreadID tid)
58711148Smitch.hayenga@arm.com    {
58811148Smitch.hayenga@arm.com        assert(tid < numThreads);
58911148Smitch.hayenga@arm.com        return &addressMonitor[tid];
59011148Smitch.hayenga@arm.com    }
59111877Sbrandon.potter@amd.com
59212122Sjose.marinho@arm.com    bool waitForRemoteGDB() const;
59312122Sjose.marinho@arm.com
59411877Sbrandon.potter@amd.com    Cycles syscallRetryLatency;
5952SN/A};
5962SN/A
5979850Sandreas.hansson@arm.com#endif // THE_ISA == NULL_ISA
5989850Sandreas.hansson@arm.com
5991717SN/A#endif // __CPU_BASE_HH__
600