base.hh revision 10110
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"
659814Sandreas.hansson@arm.com#include "sim/system.hh"
662SN/A
678901Sandreas.hansson@arm.comstruct BaseCPUParams;
682315SN/Aclass CheckerCPU;
692680Sktlim@umich.educlass ThreadContext;
702SN/A
712356SN/Aclass CPUProgressEvent : public Event
722356SN/A{
732356SN/A  protected:
746144Sksewell@umich.edu    Tick _interval;
752356SN/A    Counter lastNumInst;
762356SN/A    BaseCPU *cpu;
776144Sksewell@umich.edu    bool _repeatEvent;
782356SN/A
792356SN/A  public:
806144Sksewell@umich.edu    CPUProgressEvent(BaseCPU *_cpu, Tick ival = 0);
812356SN/A
822356SN/A    void process();
832356SN/A
846144Sksewell@umich.edu    void interval(Tick ival) { _interval = ival; }
856144Sksewell@umich.edu    Tick interval() { return _interval; }
866144Sksewell@umich.edu
876144Sksewell@umich.edu    void repeatEvent(bool repeat) { _repeatEvent = repeat; }
886144Sksewell@umich.edu
895336Shines@cs.fsu.edu    virtual const char *description() const;
902356SN/A};
912356SN/A
922856Srdreslin@umich.educlass BaseCPU : public MemObject
932SN/A{
941634SN/A  protected:
959157Sandreas.hansson@arm.com
963814Ssaidi@eecs.umich.edu    // @todo remove me after debugging with legion done
973814Ssaidi@eecs.umich.edu    Tick instCnt;
985712Shsul@eecs.umich.edu    // every cpu has an id, put it in the base cpu
995712Shsul@eecs.umich.edu    // Set at initialization, only time a cpuId might change is during a
1005715Shsul@eecs.umich.edu    // takeover (which should be done from within the BaseCPU anyway,
1015712Shsul@eecs.umich.edu    // therefore no setCpuId() method is provided
1025712Shsul@eecs.umich.edu    int _cpuId;
1031634SN/A
1048832SAli.Saidi@ARM.com    /** instruction side request id that must be placed in all requests */
1058832SAli.Saidi@ARM.com    MasterID _instMasterId;
1068832SAli.Saidi@ARM.com
1078832SAli.Saidi@ARM.com    /** data side request id that must be placed in all requests */
1088832SAli.Saidi@ARM.com    MasterID _dataMasterId;
1098832SAli.Saidi@ARM.com
1109332Sdam.sunwoo@arm.com    /** An intrenal representation of a task identifier within gem5. This is
1119332Sdam.sunwoo@arm.com     * used so the CPU can add which taskId (which is an internal representation
1129332Sdam.sunwoo@arm.com     * of the OS process ID) to each request so components in the memory system
1139332Sdam.sunwoo@arm.com     * can track which process IDs are ultimately interacting with them
1149332Sdam.sunwoo@arm.com     */
1159332Sdam.sunwoo@arm.com    uint32_t _taskId;
1169332Sdam.sunwoo@arm.com
1179332Sdam.sunwoo@arm.com    /** The current OS process ID that is executing on this processor. This is
1189332Sdam.sunwoo@arm.com     * used to generate a taskId */
1199332Sdam.sunwoo@arm.com    uint32_t _pid;
1209332Sdam.sunwoo@arm.com
1219430SAndreas.Sandberg@ARM.com    /** Is the CPU switched out or active? */
1229430SAndreas.Sandberg@ARM.com    bool _switchedOut;
1239430SAndreas.Sandberg@ARM.com
1249814Sandreas.hansson@arm.com    /** Cache the cache line size that we get from the system */
1259814Sandreas.hansson@arm.com    const unsigned int _cacheLineSize;
1269814Sandreas.hansson@arm.com
1271634SN/A  public:
1288850Sandreas.hansson@arm.com
1298850Sandreas.hansson@arm.com    /**
1308850Sandreas.hansson@arm.com     * Purely virtual method that returns a reference to the data
1318850Sandreas.hansson@arm.com     * port. All subclasses must implement this method.
1328850Sandreas.hansson@arm.com     *
1338850Sandreas.hansson@arm.com     * @return a reference to the data port
1348850Sandreas.hansson@arm.com     */
1359608Sandreas.hansson@arm.com    virtual MasterPort &getDataPort() = 0;
1368850Sandreas.hansson@arm.com
1378850Sandreas.hansson@arm.com    /**
1388850Sandreas.hansson@arm.com     * Purely virtual method that returns a reference to the instruction
1398850Sandreas.hansson@arm.com     * port. All subclasses must implement this method.
1408850Sandreas.hansson@arm.com     *
1418850Sandreas.hansson@arm.com     * @return a reference to the instruction port
1428850Sandreas.hansson@arm.com     */
1439608Sandreas.hansson@arm.com    virtual MasterPort &getInstPort() = 0;
1448850Sandreas.hansson@arm.com
1455712Shsul@eecs.umich.edu    /** Reads this CPU's ID. */
14610110Sandreas.hansson@arm.com    int cpuId() const { return _cpuId; }
1475712Shsul@eecs.umich.edu
1488832SAli.Saidi@ARM.com    /** Reads this CPU's unique data requestor ID */
1498832SAli.Saidi@ARM.com    MasterID dataMasterId() { return _dataMasterId; }
1508832SAli.Saidi@ARM.com    /** Reads this CPU's unique instruction requestor ID */
1518832SAli.Saidi@ARM.com    MasterID instMasterId() { return _instMasterId; }
1528832SAli.Saidi@ARM.com
1538850Sandreas.hansson@arm.com    /**
1548926Sandreas.hansson@arm.com     * Get a master port on this CPU. All CPUs have a data and
1558926Sandreas.hansson@arm.com     * instruction port, and this method uses getDataPort and
1568926Sandreas.hansson@arm.com     * getInstPort of the subclasses to resolve the two ports.
1578850Sandreas.hansson@arm.com     *
1588850Sandreas.hansson@arm.com     * @param if_name the port name
1598850Sandreas.hansson@arm.com     * @param idx ignored index
1608850Sandreas.hansson@arm.com     *
1618922Swilliam.wang@arm.com     * @return a reference to the port with the given name
1628850Sandreas.hansson@arm.com     */
1639294Sandreas.hansson@arm.com    BaseMasterPort &getMasterPort(const std::string &if_name,
1649294Sandreas.hansson@arm.com                                  PortID idx = InvalidPortID);
1658850Sandreas.hansson@arm.com
1669332Sdam.sunwoo@arm.com    /** Get cpu task id */
1679332Sdam.sunwoo@arm.com    uint32_t taskId() const { return _taskId; }
1689332Sdam.sunwoo@arm.com    /** Set cpu task id */
1699332Sdam.sunwoo@arm.com    void taskId(uint32_t id) { _taskId = id; }
1709332Sdam.sunwoo@arm.com
1719332Sdam.sunwoo@arm.com    uint32_t getPid() const { return _pid; }
1729332Sdam.sunwoo@arm.com    void setPid(uint32_t pid) { _pid = pid; }
1739332Sdam.sunwoo@arm.com
1747914SBrad.Beckmann@amd.com    inline void workItemBegin() { numWorkItemsStarted++; }
1757914SBrad.Beckmann@amd.com    inline void workItemEnd() { numWorkItemsCompleted++; }
1763814Ssaidi@eecs.umich.edu    // @todo remove me after debugging with legion done
1773814Ssaidi@eecs.umich.edu    Tick instCount() { return instCnt; }
1781634SN/A
1795664Sgblack@eecs.umich.edu    TheISA::MicrocodeRom microcodeRom;
1805664Sgblack@eecs.umich.edu
1812SN/A  protected:
1825704Snate@binkert.org    TheISA::Interrupts *interrupts;
1832SN/A
1842SN/A  public:
1855645Sgblack@eecs.umich.edu    TheISA::Interrupts *
1865645Sgblack@eecs.umich.edu    getInterruptController()
1875645Sgblack@eecs.umich.edu    {
1885647Sgblack@eecs.umich.edu        return interrupts;
1895645Sgblack@eecs.umich.edu    }
1905645Sgblack@eecs.umich.edu
1915807Snate@binkert.org    virtual void wakeup() = 0;
1925807Snate@binkert.org
1935807Snate@binkert.org    void
1945807Snate@binkert.org    postInterrupt(int int_num, int index)
1955807Snate@binkert.org    {
1965807Snate@binkert.org        interrupts->post(int_num, index);
1978779Sgblack@eecs.umich.edu        if (FullSystem)
1988779Sgblack@eecs.umich.edu            wakeup();
1995807Snate@binkert.org    }
2005807Snate@binkert.org
2015807Snate@binkert.org    void
2025807Snate@binkert.org    clearInterrupt(int int_num, int index)
2035807Snate@binkert.org    {
2045807Snate@binkert.org        interrupts->clear(int_num, index);
2055807Snate@binkert.org    }
2065807Snate@binkert.org
2075807Snate@binkert.org    void
2085807Snate@binkert.org    clearInterrupts()
2095807Snate@binkert.org    {
2105807Snate@binkert.org        interrupts->clearAll();
2115807Snate@binkert.org    }
2122SN/A
2135704Snate@binkert.org    bool
2145704Snate@binkert.org    checkInterrupts(ThreadContext *tc) const
2155704Snate@binkert.org    {
2168793Sgblack@eecs.umich.edu        return FullSystem && interrupts->checkInterrupts(tc);
2175704Snate@binkert.org    }
2181917SN/A
2191917SN/A    class ProfileEvent : public Event
2201917SN/A    {
2211917SN/A      private:
2221917SN/A        BaseCPU *cpu;
2235536Srstrong@hp.com        Tick interval;
2241917SN/A
2251917SN/A      public:
2265536Srstrong@hp.com        ProfileEvent(BaseCPU *cpu, Tick interval);
2271917SN/A        void process();
2281917SN/A    };
2291917SN/A    ProfileEvent *profileEvent;
2302SN/A
2312SN/A  protected:
2322680Sktlim@umich.edu    std::vector<ThreadContext *> threadContexts;
2332SN/A
2344776Sgblack@eecs.umich.edu    Trace::InstTracer * tracer;
2354776Sgblack@eecs.umich.edu
2362SN/A  public:
237393SN/A
2387764Sgblack@eecs.umich.edu    // Mask to align PCs to MachInst sized boundaries
2397764Sgblack@eecs.umich.edu    static const Addr PCMask = ~((Addr)sizeof(TheISA::MachInst) - 1);
2407764Sgblack@eecs.umich.edu
2414776Sgblack@eecs.umich.edu    /// Provide access to the tracer pointer
2424776Sgblack@eecs.umich.edu    Trace::InstTracer * getTracer() { return tracer; }
2434776Sgblack@eecs.umich.edu
244393SN/A    /// Notify the CPU that the indicated context is now active.  The
245393SN/A    /// delay parameter indicates the number of ticks to wait before
246393SN/A    /// executing (typically 0 or 1).
2479180Sandreas.hansson@arm.com    virtual void activateContext(ThreadID thread_num, Cycles delay) {}
248393SN/A
249393SN/A    /// Notify the CPU that the indicated context is now suspended.
2508737Skoansin.tan@gmail.com    virtual void suspendContext(ThreadID thread_num) {}
251393SN/A
252393SN/A    /// Notify the CPU that the indicated context is now deallocated.
2538737Skoansin.tan@gmail.com    virtual void deallocateContext(ThreadID thread_num) {}
254393SN/A
255393SN/A    /// Notify the CPU that the indicated context is now halted.
2568737Skoansin.tan@gmail.com    virtual void haltContext(ThreadID thread_num) {}
2572SN/A
2584000Ssaidi@eecs.umich.edu   /// Given a Thread Context pointer return the thread num
2594000Ssaidi@eecs.umich.edu   int findContext(ThreadContext *tc);
2604000Ssaidi@eecs.umich.edu
2614000Ssaidi@eecs.umich.edu   /// Given a thread num get tho thread context for it
2629652SAndreas.Sandberg@ARM.com   virtual ThreadContext *getContext(int tn) { return threadContexts[tn]; }
2634000Ssaidi@eecs.umich.edu
26410030SAli.Saidi@ARM.com   /// Get the number of thread contexts available
26510030SAli.Saidi@ARM.com   unsigned numContexts() { return threadContexts.size(); }
26610030SAli.Saidi@ARM.com
2672SN/A  public:
2685529Snate@binkert.org    typedef BaseCPUParams Params;
2695529Snate@binkert.org    const Params *params() const
2705529Snate@binkert.org    { return reinterpret_cast<const Params *>(_params); }
2718876Sandreas.hansson@arm.com    BaseCPU(Params *params, bool is_checker = false);
2721191SN/A    virtual ~BaseCPU();
2732SN/A
2741129SN/A    virtual void init();
2751917SN/A    virtual void startup();
2762SN/A    virtual void regStats();
2772SN/A
2786221Snate@binkert.org    virtual void activateWhenReady(ThreadID tid) {};
2792103SN/A
2802680Sktlim@umich.edu    void registerThreadContexts();
281180SN/A
2829254SAndreas.Sandberg@arm.com    /**
2839254SAndreas.Sandberg@arm.com     * Prepare for another CPU to take over execution.
2849254SAndreas.Sandberg@arm.com     *
2859254SAndreas.Sandberg@arm.com     * When this method exits, all internal state should have been
2869254SAndreas.Sandberg@arm.com     * flushed. After the method returns, the simulator calls
2879254SAndreas.Sandberg@arm.com     * takeOverFrom() on the new CPU with this CPU as its parameter.
2889254SAndreas.Sandberg@arm.com     */
2892798Sktlim@umich.edu    virtual void switchOut();
290180SN/A
2919254SAndreas.Sandberg@arm.com    /**
2929254SAndreas.Sandberg@arm.com     * Load the state of a CPU from the previous CPU object, invoked
2939254SAndreas.Sandberg@arm.com     * on all new CPUs that are about to be switched in.
2949254SAndreas.Sandberg@arm.com     *
2959254SAndreas.Sandberg@arm.com     * A CPU model implementing this method is expected to initialize
2969254SAndreas.Sandberg@arm.com     * its state from the old CPU and connect its memory (unless they
2979254SAndreas.Sandberg@arm.com     * are already connected) to the memories connected to the old
2989254SAndreas.Sandberg@arm.com     * CPU.
2999254SAndreas.Sandberg@arm.com     *
3009254SAndreas.Sandberg@arm.com     * @param cpu CPU to initialize read state from.
3019254SAndreas.Sandberg@arm.com     */
3029254SAndreas.Sandberg@arm.com    virtual void takeOverFrom(BaseCPU *cpu);
303180SN/A
304124SN/A    /**
3059446SAndreas.Sandberg@ARM.com     * Flush all TLBs in the CPU.
3069446SAndreas.Sandberg@ARM.com     *
3079446SAndreas.Sandberg@ARM.com     * This method is mainly used to flush stale translations when
3089446SAndreas.Sandberg@ARM.com     * switching CPUs. It is also exported to the Python world to
3099446SAndreas.Sandberg@ARM.com     * allow it to request a TLB flush after draining the CPU to make
3109446SAndreas.Sandberg@ARM.com     * it easier to compare traces when debugging
3119446SAndreas.Sandberg@ARM.com     * handover/checkpointing.
3129446SAndreas.Sandberg@ARM.com     */
3139446SAndreas.Sandberg@ARM.com    void flushTLBs();
3149446SAndreas.Sandberg@ARM.com
3159446SAndreas.Sandberg@ARM.com    /**
3169430SAndreas.Sandberg@ARM.com     * Determine if the CPU is switched out.
3179430SAndreas.Sandberg@ARM.com     *
3189430SAndreas.Sandberg@ARM.com     * @return True if the CPU is switched out, false otherwise.
3199430SAndreas.Sandberg@ARM.com     */
3209430SAndreas.Sandberg@ARM.com    bool switchedOut() const { return _switchedOut; }
3219430SAndreas.Sandberg@ARM.com
3229430SAndreas.Sandberg@ARM.com    /**
3239523SAndreas.Sandberg@ARM.com     * Verify that the system is in a memory mode supported by the
3249523SAndreas.Sandberg@ARM.com     * CPU.
3259523SAndreas.Sandberg@ARM.com     *
3269523SAndreas.Sandberg@ARM.com     * Implementations are expected to query the system for the
3279523SAndreas.Sandberg@ARM.com     * current memory mode and ensure that it is what the CPU model
3289523SAndreas.Sandberg@ARM.com     * expects. If the check fails, the implementation should
3299523SAndreas.Sandberg@ARM.com     * terminate the simulation using fatal().
3309523SAndreas.Sandberg@ARM.com     */
3319523SAndreas.Sandberg@ARM.com    virtual void verifyMemoryMode() const { };
3329523SAndreas.Sandberg@ARM.com
3339523SAndreas.Sandberg@ARM.com    /**
334124SN/A     *  Number of threads we're actually simulating (<= SMT_MAX_THREADS).
335124SN/A     * This is a constant for the duration of the simulation.
336124SN/A     */
3376221Snate@binkert.org    ThreadID numThreads;
3382SN/A
339124SN/A    /**
340124SN/A     * Vector of per-thread instruction-based event queues.  Used for
341124SN/A     * scheduling events based on number of instructions committed by
342124SN/A     * a particular thread.
343124SN/A     */
344503SN/A    EventQueue **comInstEventQueue;
3452SN/A
346124SN/A    /**
347124SN/A     * Vector of per-thread load-based event queues.  Used for
348124SN/A     * scheduling events based on number of loads committed by
349124SN/A     *a particular thread.
350124SN/A     */
351124SN/A    EventQueue **comLoadEventQueue;
352124SN/A
3532SN/A    System *system;
354921SN/A
355921SN/A    /**
3569814Sandreas.hansson@arm.com     * Get the cache line size of the system.
3579814Sandreas.hansson@arm.com     */
3589814Sandreas.hansson@arm.com    inline unsigned int cacheLineSize() const { return _cacheLineSize; }
3599814Sandreas.hansson@arm.com
3609814Sandreas.hansson@arm.com    /**
361921SN/A     * Serialize this object to the given output stream.
3629448SAndreas.Sandberg@ARM.com     *
3639448SAndreas.Sandberg@ARM.com     * @note CPU models should normally overload the serializeThread()
3649448SAndreas.Sandberg@ARM.com     * method instead of the serialize() method as this provides a
3659448SAndreas.Sandberg@ARM.com     * uniform data format for all CPU models and promotes better code
3669448SAndreas.Sandberg@ARM.com     * reuse.
3679448SAndreas.Sandberg@ARM.com     *
368921SN/A     * @param os The stream to serialize to.
369921SN/A     */
370921SN/A    virtual void serialize(std::ostream &os);
371921SN/A
372921SN/A    /**
373921SN/A     * Reconstruct the state of this object from a checkpoint.
3749448SAndreas.Sandberg@ARM.com     *
3759448SAndreas.Sandberg@ARM.com     * @note CPU models should normally overload the
3769448SAndreas.Sandberg@ARM.com     * unserializeThread() method instead of the unserialize() method
3779448SAndreas.Sandberg@ARM.com     * as this provides a uniform data format for all CPU models and
3789448SAndreas.Sandberg@ARM.com     * promotes better code reuse.
3799448SAndreas.Sandberg@ARM.com
380921SN/A     * @param cp The checkpoint use.
3819448SAndreas.Sandberg@ARM.com     * @param section The section name of this object.
382921SN/A     */
383921SN/A    virtual void unserialize(Checkpoint *cp, const std::string &section);
384921SN/A
385124SN/A    /**
3869448SAndreas.Sandberg@ARM.com     * Serialize a single thread.
3879448SAndreas.Sandberg@ARM.com     *
3889448SAndreas.Sandberg@ARM.com     * @param os The stream to serialize to.
3899448SAndreas.Sandberg@ARM.com     * @param tid ID of the current thread.
3909448SAndreas.Sandberg@ARM.com     */
3919448SAndreas.Sandberg@ARM.com    virtual void serializeThread(std::ostream &os, ThreadID tid) {};
3929448SAndreas.Sandberg@ARM.com
3939448SAndreas.Sandberg@ARM.com    /**
3949448SAndreas.Sandberg@ARM.com     * Unserialize one thread.
3959448SAndreas.Sandberg@ARM.com     *
3969448SAndreas.Sandberg@ARM.com     * @param cp The checkpoint use.
3979448SAndreas.Sandberg@ARM.com     * @param section The section name of this thread.
3989448SAndreas.Sandberg@ARM.com     * @param tid ID of the current thread.
3999448SAndreas.Sandberg@ARM.com     */
4009448SAndreas.Sandberg@ARM.com    virtual void unserializeThread(Checkpoint *cp, const std::string &section,
4019448SAndreas.Sandberg@ARM.com                                   ThreadID tid) {};
4029448SAndreas.Sandberg@ARM.com
4038834Satgutier@umich.edu    virtual Counter totalInsts() const = 0;
4048834Satgutier@umich.edu
4058834Satgutier@umich.edu    virtual Counter totalOps() const = 0;
406707SN/A
4079749Sandreas@sandberg.pp.se    /**
4089749Sandreas@sandberg.pp.se     * Schedule an event that exits the simulation loops after a
4099749Sandreas@sandberg.pp.se     * predefined number of instructions.
4109749Sandreas@sandberg.pp.se     *
4119749Sandreas@sandberg.pp.se     * This method is usually called from the configuration script to
4129749Sandreas@sandberg.pp.se     * get an exit event some time in the future. It is typically used
4139749Sandreas@sandberg.pp.se     * when the script wants to simulate for a specific number of
4149749Sandreas@sandberg.pp.se     * instructions rather than ticks.
4159749Sandreas@sandberg.pp.se     *
4169749Sandreas@sandberg.pp.se     * @param tid Thread monitor.
4179749Sandreas@sandberg.pp.se     * @param insts Number of instructions into the future.
4189749Sandreas@sandberg.pp.se     * @param cause Cause to signal in the exit event.
4199749Sandreas@sandberg.pp.se     */
4209749Sandreas@sandberg.pp.se    void scheduleInstStop(ThreadID tid, Counter insts, const char *cause);
4219749Sandreas@sandberg.pp.se
4229749Sandreas@sandberg.pp.se    /**
4239749Sandreas@sandberg.pp.se     * Schedule an event that exits the simulation loops after a
4249749Sandreas@sandberg.pp.se     * predefined number of load operations.
4259749Sandreas@sandberg.pp.se     *
4269749Sandreas@sandberg.pp.se     * This method is usually called from the configuration script to
4279749Sandreas@sandberg.pp.se     * get an exit event some time in the future. It is typically used
4289749Sandreas@sandberg.pp.se     * when the script wants to simulate for a specific number of
4299749Sandreas@sandberg.pp.se     * loads rather than ticks.
4309749Sandreas@sandberg.pp.se     *
4319749Sandreas@sandberg.pp.se     * @param tid Thread monitor.
4329749Sandreas@sandberg.pp.se     * @param loads Number of load instructions into the future.
4339749Sandreas@sandberg.pp.se     * @param cause Cause to signal in the exit event.
4349749Sandreas@sandberg.pp.se     */
4359749Sandreas@sandberg.pp.se    void scheduleLoadStop(ThreadID tid, Counter loads, const char *cause);
4369749Sandreas@sandberg.pp.se
4371191SN/A    // Function tracing
4381191SN/A  private:
4391191SN/A    bool functionTracingEnabled;
4401191SN/A    std::ostream *functionTraceStream;
4411191SN/A    Addr currentFunctionStart;
4421191SN/A    Addr currentFunctionEnd;
4431191SN/A    Tick functionEntryTick;
4441191SN/A    void enableFunctionTrace();
4451191SN/A    void traceFunctionsInternal(Addr pc);
4461191SN/A
4478662SAli.Saidi@ARM.com  private:
4488662SAli.Saidi@ARM.com    static std::vector<BaseCPU *> cpuList;   //!< Static global cpu list
4498662SAli.Saidi@ARM.com
4508662SAli.Saidi@ARM.com  public:
4511191SN/A    void traceFunctions(Addr pc)
4521191SN/A    {
4531191SN/A        if (functionTracingEnabled)
4541191SN/A            traceFunctionsInternal(pc);
4551191SN/A    }
4561191SN/A
4572SN/A    static int numSimulatedCPUs() { return cpuList.size(); }
4588834Satgutier@umich.edu    static Counter numSimulatedInsts()
459707SN/A    {
460707SN/A        Counter total = 0;
461707SN/A
462707SN/A        int size = cpuList.size();
463707SN/A        for (int i = 0; i < size; ++i)
4648834Satgutier@umich.edu            total += cpuList[i]->totalInsts();
4658834Satgutier@umich.edu
4668834Satgutier@umich.edu        return total;
4678834Satgutier@umich.edu    }
4688834Satgutier@umich.edu
4698834Satgutier@umich.edu    static Counter numSimulatedOps()
4708834Satgutier@umich.edu    {
4718834Satgutier@umich.edu        Counter total = 0;
4728834Satgutier@umich.edu
4738834Satgutier@umich.edu        int size = cpuList.size();
4748834Satgutier@umich.edu        for (int i = 0; i < size; ++i)
4758834Satgutier@umich.edu            total += cpuList[i]->totalOps();
476707SN/A
477707SN/A        return total;
478707SN/A    }
479707SN/A
480707SN/A  public:
481707SN/A    // Number of CPU cycles simulated
4825999Snate@binkert.org    Stats::Scalar numCycles;
4837914SBrad.Beckmann@amd.com    Stats::Scalar numWorkItemsStarted;
4847914SBrad.Beckmann@amd.com    Stats::Scalar numWorkItemsCompleted;
4852SN/A};
4862SN/A
4879850Sandreas.hansson@arm.com#endif // THE_ISA == NULL_ISA
4889850Sandreas.hansson@arm.com
4891717SN/A#endif // __CPU_BASE_HH__
490