atomic.hh revision 10381
12623SN/A/*
29608Sandreas.hansson@arm.com * Copyright (c) 2012-2013 ARM Limited
38926Sandreas.hansson@arm.com * All rights reserved.
48926Sandreas.hansson@arm.com *
58926Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68926Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78926Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88926Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98926Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108926Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118926Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128926Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138926Sandreas.hansson@arm.com *
142623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
152623SN/A * All rights reserved.
162623SN/A *
172623SN/A * Redistribution and use in source and binary forms, with or without
182623SN/A * modification, are permitted provided that the following conditions are
192623SN/A * met: redistributions of source code must retain the above copyright
202623SN/A * notice, this list of conditions and the following disclaimer;
212623SN/A * redistributions in binary form must reproduce the above copyright
222623SN/A * notice, this list of conditions and the following disclaimer in the
232623SN/A * documentation and/or other materials provided with the distribution;
242623SN/A * neither the name of the copyright holders nor the names of its
252623SN/A * contributors may be used to endorse or promote products derived from
262623SN/A * this software without specific prior written permission.
272623SN/A *
282623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
412623SN/A */
422623SN/A
432623SN/A#ifndef __CPU_SIMPLE_ATOMIC_HH__
442623SN/A#define __CPU_SIMPLE_ATOMIC_HH__
452623SN/A
462623SN/A#include "cpu/simple/base.hh"
475529Snate@binkert.org#include "params/AtomicSimpleCPU.hh"
4810381Sdam.sunwoo@arm.com#include "sim/probe/probe.hh"
499647Sdam.sunwoo@arm.com
502623SN/Aclass AtomicSimpleCPU : public BaseSimpleCPU
512623SN/A{
522623SN/A  public:
532623SN/A
545529Snate@binkert.org    AtomicSimpleCPU(AtomicSimpleCPUParams *params);
552623SN/A    virtual ~AtomicSimpleCPU();
562623SN/A
572623SN/A    virtual void init();
582623SN/A
592623SN/A  private:
602623SN/A
612623SN/A    struct TickEvent : public Event
622623SN/A    {
632623SN/A        AtomicSimpleCPU *cpu;
642623SN/A
652623SN/A        TickEvent(AtomicSimpleCPU *c);
662623SN/A        void process();
675336Shines@cs.fsu.edu        const char *description() const;
682623SN/A    };
692623SN/A
702623SN/A    TickEvent tickEvent;
712623SN/A
722623SN/A    const int width;
736078Sgblack@eecs.umich.edu    bool locked;
745487Snate@binkert.org    const bool simulate_data_stalls;
755487Snate@binkert.org    const bool simulate_inst_stalls;
762623SN/A
779443SAndreas.Sandberg@ARM.com    /**
789443SAndreas.Sandberg@ARM.com     * Drain manager to use when signaling drain completion
799443SAndreas.Sandberg@ARM.com     *
809443SAndreas.Sandberg@ARM.com     * This pointer is non-NULL when draining and NULL otherwise.
819443SAndreas.Sandberg@ARM.com     */
829443SAndreas.Sandberg@ARM.com    DrainManager *drain_manager;
839443SAndreas.Sandberg@ARM.com
842623SN/A    // main simulation loop (one cycle)
852623SN/A    void tick();
862623SN/A
878707Sandreas.hansson@arm.com    /**
889443SAndreas.Sandberg@ARM.com     * Check if a system is in a drained state.
899443SAndreas.Sandberg@ARM.com     *
909443SAndreas.Sandberg@ARM.com     * We need to drain if:
919443SAndreas.Sandberg@ARM.com     * <ul>
929443SAndreas.Sandberg@ARM.com     * <li>We are in the middle of a microcode sequence as some CPUs
939443SAndreas.Sandberg@ARM.com     *     (e.g., HW accelerated CPUs) can't be started in the middle
949443SAndreas.Sandberg@ARM.com     *     of a gem5 microcode sequence.
959443SAndreas.Sandberg@ARM.com     *
969443SAndreas.Sandberg@ARM.com     * <li>The CPU is in a LLSC region. This shouldn't normally happen
979443SAndreas.Sandberg@ARM.com     *     as these are executed atomically within a single tick()
989443SAndreas.Sandberg@ARM.com     *     call. The only way this can happen at the moment is if
999443SAndreas.Sandberg@ARM.com     *     there is an event in the PC event queue that affects the
1009443SAndreas.Sandberg@ARM.com     *     CPU state while it is in an LLSC region.
1019443SAndreas.Sandberg@ARM.com     *
1029443SAndreas.Sandberg@ARM.com     * <li>Stay at PC is true.
1039443SAndreas.Sandberg@ARM.com     * </ul>
1049443SAndreas.Sandberg@ARM.com     */
1059443SAndreas.Sandberg@ARM.com    bool isDrained() {
1069443SAndreas.Sandberg@ARM.com        return microPC() == 0 &&
1079443SAndreas.Sandberg@ARM.com            !locked &&
1089443SAndreas.Sandberg@ARM.com            !stayAtPC;
1099443SAndreas.Sandberg@ARM.com    }
1109443SAndreas.Sandberg@ARM.com
1119443SAndreas.Sandberg@ARM.com    /**
1129443SAndreas.Sandberg@ARM.com     * Try to complete a drain request.
1139443SAndreas.Sandberg@ARM.com     *
1149443SAndreas.Sandberg@ARM.com     * @returns true if the CPU is drained, false otherwise.
1159443SAndreas.Sandberg@ARM.com     */
1169443SAndreas.Sandberg@ARM.com    bool tryCompleteDrain();
1179443SAndreas.Sandberg@ARM.com
1189443SAndreas.Sandberg@ARM.com    /**
1198707Sandreas.hansson@arm.com     * An AtomicCPUPort overrides the default behaviour of the
1209608Sandreas.hansson@arm.com     * recvAtomicSnoop and ignores the packet instead of panicking. It
1219608Sandreas.hansson@arm.com     * also provides an implementation for the purely virtual timing
1229608Sandreas.hansson@arm.com     * functions and panics on either of these.
1238707Sandreas.hansson@arm.com     */
1249608Sandreas.hansson@arm.com    class AtomicCPUPort : public MasterPort
1252623SN/A    {
1268707Sandreas.hansson@arm.com
1272623SN/A      public:
1282623SN/A
12910030SAli.Saidi@ARM.com        AtomicCPUPort(const std::string &_name, BaseSimpleCPU* _cpu)
1309608Sandreas.hansson@arm.com            : MasterPort(_name, _cpu)
1312623SN/A        { }
1322623SN/A
1332623SN/A      protected:
13410030SAli.Saidi@ARM.com        virtual Tick recvAtomicSnoop(PacketPtr pkt) { return 0; }
1353192Srdreslin@umich.edu
1369608Sandreas.hansson@arm.com        bool recvTimingResp(PacketPtr pkt)
1379608Sandreas.hansson@arm.com        {
1389608Sandreas.hansson@arm.com            panic("Atomic CPU doesn't expect recvTimingResp!\n");
1399608Sandreas.hansson@arm.com            return true;
1409608Sandreas.hansson@arm.com        }
1419608Sandreas.hansson@arm.com
1429608Sandreas.hansson@arm.com        void recvRetry()
1439608Sandreas.hansson@arm.com        {
1449608Sandreas.hansson@arm.com            panic("Atomic CPU doesn't expect recvRetry!\n");
1459608Sandreas.hansson@arm.com        }
1469608Sandreas.hansson@arm.com
1472623SN/A    };
1484192Sktlim@umich.edu
14910030SAli.Saidi@ARM.com    class AtomicCPUDPort : public AtomicCPUPort
15010030SAli.Saidi@ARM.com    {
15110030SAli.Saidi@ARM.com
15210030SAli.Saidi@ARM.com      public:
15310030SAli.Saidi@ARM.com
15410030SAli.Saidi@ARM.com        AtomicCPUDPort(const std::string &_name, BaseSimpleCPU* _cpu)
15510030SAli.Saidi@ARM.com            : AtomicCPUPort(_name, _cpu), cpu(_cpu)
15610030SAli.Saidi@ARM.com        {
15710030SAli.Saidi@ARM.com            cacheBlockMask = ~(cpu->cacheLineSize() - 1);
15810030SAli.Saidi@ARM.com        }
15910030SAli.Saidi@ARM.com
16010030SAli.Saidi@ARM.com        bool isSnooping() const { return true; }
16110030SAli.Saidi@ARM.com
16210030SAli.Saidi@ARM.com        Addr cacheBlockMask;
16310030SAli.Saidi@ARM.com      protected:
16410030SAli.Saidi@ARM.com        BaseSimpleCPU *cpu;
16510030SAli.Saidi@ARM.com
16610030SAli.Saidi@ARM.com        virtual Tick recvAtomicSnoop(PacketPtr pkt);
16710030SAli.Saidi@ARM.com        virtual void recvFunctionalSnoop(PacketPtr pkt);
16810030SAli.Saidi@ARM.com    };
16910030SAli.Saidi@ARM.com
17010030SAli.Saidi@ARM.com
1718707Sandreas.hansson@arm.com    AtomicCPUPort icachePort;
17210030SAli.Saidi@ARM.com    AtomicCPUDPort dcachePort;
1732623SN/A
1748926Sandreas.hansson@arm.com    bool fastmem;
1754870Sstever@eecs.umich.edu    Request ifetch_req;
1764870Sstever@eecs.umich.edu    Request data_read_req;
1774870Sstever@eecs.umich.edu    Request data_write_req;
1782623SN/A
1792623SN/A    bool dcache_access;
1802662Sstever@eecs.umich.edu    Tick dcache_latency;
1812623SN/A
18210381Sdam.sunwoo@arm.com    /** Probe Points. */
18310381Sdam.sunwoo@arm.com    ProbePointArg<std::pair<SimpleThread*, const StaticInstPtr>> *ppCommit;
1849647Sdam.sunwoo@arm.com
1858850Sandreas.hansson@arm.com  protected:
1868850Sandreas.hansson@arm.com
1878850Sandreas.hansson@arm.com    /** Return a reference to the data port. */
1889608Sandreas.hansson@arm.com    virtual MasterPort &getDataPort() { return dcachePort; }
1898850Sandreas.hansson@arm.com
1908850Sandreas.hansson@arm.com    /** Return a reference to the instruction port. */
1919608Sandreas.hansson@arm.com    virtual MasterPort &getInstPort() { return icachePort; }
1928850Sandreas.hansson@arm.com
1932623SN/A  public:
1942623SN/A
1959342SAndreas.Sandberg@arm.com    unsigned int drain(DrainManager *drain_manager);
1969342SAndreas.Sandberg@arm.com    void drainResume();
1972623SN/A
1982798Sktlim@umich.edu    void switchOut();
1992623SN/A    void takeOverFrom(BaseCPU *oldCPU);
2002623SN/A
2019523SAndreas.Sandberg@ARM.com    void verifyMemoryMode() const;
2029523SAndreas.Sandberg@ARM.com
2039180Sandreas.hansson@arm.com    virtual void activateContext(ThreadID thread_num, Cycles delay);
2048737Skoansin.tan@gmail.com    virtual void suspendContext(ThreadID thread_num);
2052623SN/A
2068444Sgblack@eecs.umich.edu    Fault readMem(Addr addr, uint8_t *data, unsigned size, unsigned flags);
2077520Sgblack@eecs.umich.edu
2088444Sgblack@eecs.umich.edu    Fault writeMem(uint8_t *data, unsigned size,
2098444Sgblack@eecs.umich.edu                   Addr addr, unsigned flags, uint64_t *res);
2107520Sgblack@eecs.umich.edu
21110381Sdam.sunwoo@arm.com    virtual void regProbePoints();
21210381Sdam.sunwoo@arm.com
2135315Sstever@gmail.com    /**
2145315Sstever@gmail.com     * Print state of address in memory system via PrintReq (for
2155315Sstever@gmail.com     * debugging).
2165315Sstever@gmail.com     */
2175315Sstever@gmail.com    void printAddr(Addr a);
2182623SN/A};
2192623SN/A
2202623SN/A#endif // __CPU_SIMPLE_ATOMIC_HH__
221