base.hh revision 11608
19544Sandreas.hansson@arm.com/*
28839Sandreas.hansson@arm.com * Copyright (c) 2011-2012,2015 ARM Limited
38839Sandreas.hansson@arm.com * Copyright (c) 2013 Advanced Micro Devices, Inc.
48839Sandreas.hansson@arm.com * All rights reserved
58839Sandreas.hansson@arm.com *
68839Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
78839Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
88839Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
98839Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
108839Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
118839Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
128839Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
133101Sstever@eecs.umich.edu * modified or unmodified, in source code or in binary form.
148579Ssteve.reinhardt@amd.com *
153101Sstever@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan
163101Sstever@eecs.umich.edu * All rights reserved.
173101Sstever@eecs.umich.edu *
183101Sstever@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
193101Sstever@eecs.umich.edu * modification, are permitted provided that the following conditions are
203101Sstever@eecs.umich.edu * met: redistributions of source code must retain the above copyright
213101Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
223101Sstever@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
233101Sstever@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
243101Sstever@eecs.umich.edu * documentation and/or other materials provided with the distribution;
253101Sstever@eecs.umich.edu * neither the name of the copyright holders nor the names of its
263101Sstever@eecs.umich.edu * contributors may be used to endorse or promote products derived from
273101Sstever@eecs.umich.edu * this software without specific prior written permission.
283101Sstever@eecs.umich.edu *
293101Sstever@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
303101Sstever@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
313101Sstever@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
323101Sstever@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
333101Sstever@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
343101Sstever@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
353101Sstever@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
363101Sstever@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
373101Sstever@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
383101Sstever@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
393101Sstever@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
403101Sstever@eecs.umich.edu *
413101Sstever@eecs.umich.edu * Authors: Steve Reinhardt
427778Sgblack@eecs.umich.edu *          Dave Greene
438839Sandreas.hansson@arm.com *          Nathan Binkert
443101Sstever@eecs.umich.edu */
453101Sstever@eecs.umich.edu
463101Sstever@eecs.umich.edu#ifndef __CPU_SIMPLE_BASE_HH__
473101Sstever@eecs.umich.edu#define __CPU_SIMPLE_BASE_HH__
483101Sstever@eecs.umich.edu
493101Sstever@eecs.umich.edu#include "base/statistics.hh"
503101Sstever@eecs.umich.edu#include "config/the_isa.hh"
513101Sstever@eecs.umich.edu#include "cpu/base.hh"
523101Sstever@eecs.umich.edu#include "cpu/checker/cpu.hh"
533101Sstever@eecs.umich.edu#include "cpu/exec_context.hh"
543101Sstever@eecs.umich.edu#include "cpu/pc_event.hh"
553101Sstever@eecs.umich.edu#include "cpu/simple_thread.hh"
563101Sstever@eecs.umich.edu#include "cpu/static_inst.hh"
573101Sstever@eecs.umich.edu#include "mem/packet.hh"
583101Sstever@eecs.umich.edu#include "mem/port.hh"
593101Sstever@eecs.umich.edu#include "mem/request.hh"
603101Sstever@eecs.umich.edu#include "sim/eventq.hh"
613101Sstever@eecs.umich.edu#include "sim/full_system.hh"
623885Sbinkertn@umich.edu#include "sim/system.hh"
633885Sbinkertn@umich.edu
644762Snate@binkert.org// forward declarations
653885Sbinkertn@umich.educlass Checkpoint;
663885Sbinkertn@umich.educlass Process;
677528Ssteve.reinhardt@amd.comclass Processor;
683885Sbinkertn@umich.educlass ThreadContext;
694380Sbinkertn@umich.edu
704167Sbinkertn@umich.edunamespace TheISA
713102Sstever@eecs.umich.edu{
723101Sstever@eecs.umich.edu    class DTB;
734762Snate@binkert.org    class ITB;
744762Snate@binkert.org}
754762Snate@binkert.org
764762Snate@binkert.orgnamespace Trace {
774762Snate@binkert.org    class InstRecord;
784762Snate@binkert.org}
794762Snate@binkert.org
804762Snate@binkert.orgstruct BaseSimpleCPUParams;
814762Snate@binkert.orgclass BPredUnit;
825033Smilesck@eecs.umich.educlass SimpleExecContext;
835033Smilesck@eecs.umich.edu
845033Smilesck@eecs.umich.educlass BaseSimpleCPU : public BaseCPU
855033Smilesck@eecs.umich.edu{
865033Smilesck@eecs.umich.edu  protected:
875033Smilesck@eecs.umich.edu    ThreadID curThread;
885033Smilesck@eecs.umich.edu    BPredUnit *branchPred;
895033Smilesck@eecs.umich.edu
905033Smilesck@eecs.umich.edu    void checkPcEventQueue();
915033Smilesck@eecs.umich.edu    void swapActiveThread();
923101Sstever@eecs.umich.edu
933101Sstever@eecs.umich.edu  public:
943101Sstever@eecs.umich.edu    BaseSimpleCPU(BaseSimpleCPUParams *params);
955033Smilesck@eecs.umich.edu    virtual ~BaseSimpleCPU();
963101Sstever@eecs.umich.edu    void wakeup(ThreadID tid) override;
978596Ssteve.reinhardt@amd.com    void init() override;
988596Ssteve.reinhardt@amd.com  public:
998596Ssteve.reinhardt@amd.com    Trace::InstRecord *traceData;
1008596Ssteve.reinhardt@amd.com    CheckerCPU *checker;
1017673Snate@binkert.org
1027673Snate@binkert.org    std::vector<SimpleExecContext*> threadInfo;
1037673Snate@binkert.org    std::list<ThreadID> activeThreads;
1047673Snate@binkert.org
1058596Ssteve.reinhardt@amd.com    /** Current instruction */
1068596Ssteve.reinhardt@amd.com    TheISA::MachInst inst;
1078596Ssteve.reinhardt@amd.com    StaticInstPtr curStaticInst;
1087673Snate@binkert.org    StaticInstPtr curMacroStaticInst;
1097673Snate@binkert.org
1107673Snate@binkert.org  protected:
1113101Sstever@eecs.umich.edu    enum Status {
1123101Sstever@eecs.umich.edu        Idle,
1133101Sstever@eecs.umich.edu        Running,
1143101Sstever@eecs.umich.edu        Faulting,
1153101Sstever@eecs.umich.edu        ITBWaitResponse,
1163101Sstever@eecs.umich.edu        IcacheRetry,
1173101Sstever@eecs.umich.edu        IcacheWaitResponse,
1183101Sstever@eecs.umich.edu        IcacheWaitSwitch,
1193101Sstever@eecs.umich.edu        DTBWaitResponse,
1203101Sstever@eecs.umich.edu        DcacheRetry,
1213101Sstever@eecs.umich.edu        DcacheWaitResponse,
1223101Sstever@eecs.umich.edu        DcacheWaitSwitch,
1233101Sstever@eecs.umich.edu    };
1243101Sstever@eecs.umich.edu
1253101Sstever@eecs.umich.edu    Status _status;
1263101Sstever@eecs.umich.edu
1273101Sstever@eecs.umich.edu  public:
1283101Sstever@eecs.umich.edu    Addr dbg_vtophys(Addr addr);
1293101Sstever@eecs.umich.edu
1303101Sstever@eecs.umich.edu
1313101Sstever@eecs.umich.edu    void checkForInterrupts();
1323101Sstever@eecs.umich.edu    void setupFetchRequest(Request *req);
1333101Sstever@eecs.umich.edu    void preExecute();
1343101Sstever@eecs.umich.edu    void postExecute();
1353101Sstever@eecs.umich.edu    void advancePC(const Fault &fault);
1363101Sstever@eecs.umich.edu
1373101Sstever@eecs.umich.edu    void haltContext(ThreadID thread_num) override;
1383101Sstever@eecs.umich.edu
1393101Sstever@eecs.umich.edu    // statistics
1403101Sstever@eecs.umich.edu    void regStats() override;
1413101Sstever@eecs.umich.edu    void resetStats() override;
1423101Sstever@eecs.umich.edu
1433101Sstever@eecs.umich.edu    void startup() override;
1443101Sstever@eecs.umich.edu
1453101Sstever@eecs.umich.edu    virtual Fault readMem(Addr addr, uint8_t* data, unsigned size,
1463101Sstever@eecs.umich.edu                          Request::Flags flags) = 0;
1473101Sstever@eecs.umich.edu
1483101Sstever@eecs.umich.edu    virtual Fault initiateMemRead(Addr addr, unsigned size,
1493101Sstever@eecs.umich.edu                                  Request::Flags flags) = 0;
1503101Sstever@eecs.umich.edu
1513101Sstever@eecs.umich.edu    virtual Fault writeMem(uint8_t* data, unsigned size, Addr addr,
1523101Sstever@eecs.umich.edu                           Request::Flags flags, uint64_t* res) = 0;
1533101Sstever@eecs.umich.edu
1543101Sstever@eecs.umich.edu    void countInst();
1553101Sstever@eecs.umich.edu    Counter totalInsts() const override;
1563101Sstever@eecs.umich.edu    Counter totalOps() const override;
1575033Smilesck@eecs.umich.edu
1586656Snate@binkert.org    void serializeThread(CheckpointOut &cp, ThreadID tid) const override;
1595033Smilesck@eecs.umich.edu    void unserializeThread(CheckpointIn &cp, ThreadID tid) override;
1605033Smilesck@eecs.umich.edu
1615033Smilesck@eecs.umich.edu};
1623101Sstever@eecs.umich.edu
1633101Sstever@eecs.umich.edu#endif // __CPU_SIMPLE_BASE_HH__
1643101Sstever@eecs.umich.edu