isa.hh revision 12714
16313Sgblack@eecs.umich.edu/*
26313Sgblack@eecs.umich.edu * Copyright (c) 2009 The Regents of The University of Michigan
36313Sgblack@eecs.umich.edu * All rights reserved.
46313Sgblack@eecs.umich.edu *
56313Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
66313Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
76313Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
86313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
96313Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
106313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
116313Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
126313Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
136313Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
146313Sgblack@eecs.umich.edu * this software without specific prior written permission.
156313Sgblack@eecs.umich.edu *
166313Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176313Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186313Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196313Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206313Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216313Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226313Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236313Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246313Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256313Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266313Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276313Sgblack@eecs.umich.edu *
286313Sgblack@eecs.umich.edu * Authors: Gabe Black
296313Sgblack@eecs.umich.edu */
306313Sgblack@eecs.umich.edu
316313Sgblack@eecs.umich.edu#ifndef __ARCH_SPARC_ISA_HH__
326313Sgblack@eecs.umich.edu#define __ARCH_SPARC_ISA_HH__
336313Sgblack@eecs.umich.edu
348229Snate@binkert.org#include <ostream>
358229Snate@binkert.org#include <string>
368229Snate@binkert.org
376335Sgblack@eecs.umich.edu#include "arch/sparc/registers.hh"
386313Sgblack@eecs.umich.edu#include "arch/sparc/types.hh"
396335Sgblack@eecs.umich.edu#include "cpu/cpuevent.hh"
4012106SRekai.GonzalezAlberquilla@arm.com#include "cpu/reg_class.hh"
419384SAndreas.Sandberg@arm.com#include "sim/sim_object.hh"
426335Sgblack@eecs.umich.edu
436313Sgblack@eecs.umich.educlass Checkpoint;
446313Sgblack@eecs.umich.educlass EventManager;
459384SAndreas.Sandberg@arm.comstruct SparcISAParams;
466335Sgblack@eecs.umich.educlass ThreadContext;
476313Sgblack@eecs.umich.edu
486313Sgblack@eecs.umich.edunamespace SparcISA
496313Sgblack@eecs.umich.edu{
509384SAndreas.Sandberg@arm.comclass ISA : public SimObject
517741Sgblack@eecs.umich.edu{
527741Sgblack@eecs.umich.edu  private:
536335Sgblack@eecs.umich.edu
547741Sgblack@eecs.umich.edu    /* ASR Registers */
557741Sgblack@eecs.umich.edu    // uint64_t y;          // Y (used in obsolete multiplication)
567741Sgblack@eecs.umich.edu    // uint8_t ccr;         // Condition Code Register
577741Sgblack@eecs.umich.edu    uint8_t asi;            // Address Space Identifier
587741Sgblack@eecs.umich.edu    uint64_t tick;          // Hardware clock-tick counter
597741Sgblack@eecs.umich.edu    uint8_t fprs;           // Floating-Point Register State
607741Sgblack@eecs.umich.edu    uint64_t gsr;           // General Status Register
617741Sgblack@eecs.umich.edu    uint64_t softint;
627741Sgblack@eecs.umich.edu    uint64_t tick_cmpr;     // Hardware tick compare registers
637741Sgblack@eecs.umich.edu    uint64_t stick;         // Hardware clock-tick counter
647741Sgblack@eecs.umich.edu    uint64_t stick_cmpr;    // Hardware tick compare registers
656335Sgblack@eecs.umich.edu
666335Sgblack@eecs.umich.edu
677741Sgblack@eecs.umich.edu    /* Privileged Registers */
687741Sgblack@eecs.umich.edu    uint64_t tpc[MaxTL];    // Trap Program Counter (value from
697741Sgblack@eecs.umich.edu                            // previous trap level)
707741Sgblack@eecs.umich.edu    uint64_t tnpc[MaxTL];   // Trap Next Program Counter (value from
717741Sgblack@eecs.umich.edu                            // previous trap level)
727741Sgblack@eecs.umich.edu    uint64_t tstate[MaxTL]; // Trap State
737741Sgblack@eecs.umich.edu    uint16_t tt[MaxTL];     // Trap Type (Type of trap which occured
747741Sgblack@eecs.umich.edu                            // on the previous level)
757741Sgblack@eecs.umich.edu    uint64_t tba;           // Trap Base Address
766335Sgblack@eecs.umich.edu
778829Sgblack@eecs.umich.edu    PSTATE pstate;        // Process State Register
787741Sgblack@eecs.umich.edu    uint8_t tl;             // Trap Level
797741Sgblack@eecs.umich.edu    uint8_t pil;            // Process Interrupt Register
807741Sgblack@eecs.umich.edu    uint8_t cwp;            // Current Window Pointer
817741Sgblack@eecs.umich.edu    // uint8_t cansave;     // Savable windows
827741Sgblack@eecs.umich.edu    // uint8_t canrestore;  // Restorable windows
837741Sgblack@eecs.umich.edu    // uint8_t cleanwin;    // Clean windows
847741Sgblack@eecs.umich.edu    // uint8_t otherwin;    // Other windows
857741Sgblack@eecs.umich.edu    // uint8_t wstate;      // Window State
867741Sgblack@eecs.umich.edu    uint8_t gl;             // Global level register
876335Sgblack@eecs.umich.edu
887741Sgblack@eecs.umich.edu    /** Hyperprivileged Registers */
898829Sgblack@eecs.umich.edu    HPSTATE hpstate;       // Hyperprivileged State Register
907741Sgblack@eecs.umich.edu    uint64_t htstate[MaxTL];// Hyperprivileged Trap State Register
917741Sgblack@eecs.umich.edu    uint64_t hintp;
927741Sgblack@eecs.umich.edu    uint64_t htba;          // Hyperprivileged Trap Base Address register
937741Sgblack@eecs.umich.edu    uint64_t hstick_cmpr;   // Hardware tick compare registers
946335Sgblack@eecs.umich.edu
957741Sgblack@eecs.umich.edu    uint64_t strandStatusReg;// Per strand status register
966335Sgblack@eecs.umich.edu
977741Sgblack@eecs.umich.edu    /** Floating point misc registers. */
987741Sgblack@eecs.umich.edu    uint64_t fsr;           // Floating-Point State Register
996335Sgblack@eecs.umich.edu
1007741Sgblack@eecs.umich.edu    /** MMU Internal Registers */
1017741Sgblack@eecs.umich.edu    uint16_t priContext;
1027741Sgblack@eecs.umich.edu    uint16_t secContext;
1037741Sgblack@eecs.umich.edu    uint16_t partId;
1047741Sgblack@eecs.umich.edu    uint64_t lsuCtrlReg;
1056335Sgblack@eecs.umich.edu
1067741Sgblack@eecs.umich.edu    uint64_t scratchPad[8];
1076335Sgblack@eecs.umich.edu
1087741Sgblack@eecs.umich.edu    uint64_t cpu_mondo_head;
1097741Sgblack@eecs.umich.edu    uint64_t cpu_mondo_tail;
1107741Sgblack@eecs.umich.edu    uint64_t dev_mondo_head;
1117741Sgblack@eecs.umich.edu    uint64_t dev_mondo_tail;
1127741Sgblack@eecs.umich.edu    uint64_t res_error_head;
1137741Sgblack@eecs.umich.edu    uint64_t res_error_tail;
1147741Sgblack@eecs.umich.edu    uint64_t nres_error_head;
1157741Sgblack@eecs.umich.edu    uint64_t nres_error_tail;
1166335Sgblack@eecs.umich.edu
1177741Sgblack@eecs.umich.edu    // These need to check the int_dis field and if 0 then
1187741Sgblack@eecs.umich.edu    // set appropriate bit in softint and checkinterrutps on the cpu
1197741Sgblack@eecs.umich.edu    void  setFSReg(int miscReg, const MiscReg &val, ThreadContext *tc);
1207741Sgblack@eecs.umich.edu    MiscReg readFSReg(int miscReg, ThreadContext * tc);
1216335Sgblack@eecs.umich.edu
1227741Sgblack@eecs.umich.edu    // Update interrupt state on softint or pil change
1237741Sgblack@eecs.umich.edu    void checkSoftInt(ThreadContext *tc);
1246335Sgblack@eecs.umich.edu
1257741Sgblack@eecs.umich.edu    /** Process a tick compare event and generate an interrupt on the cpu if
1267741Sgblack@eecs.umich.edu     * appropriate. */
1277741Sgblack@eecs.umich.edu    void processTickCompare(ThreadContext *tc);
1287741Sgblack@eecs.umich.edu    void processSTickCompare(ThreadContext *tc);
1297741Sgblack@eecs.umich.edu    void processHSTickCompare(ThreadContext *tc);
1306335Sgblack@eecs.umich.edu
1317741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1327741Sgblack@eecs.umich.edu            &ISA::processTickCompare> TickCompareEvent;
1337741Sgblack@eecs.umich.edu    TickCompareEvent *tickCompare;
1346335Sgblack@eecs.umich.edu
1357741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1367741Sgblack@eecs.umich.edu            &ISA::processSTickCompare> STickCompareEvent;
1377741Sgblack@eecs.umich.edu    STickCompareEvent *sTickCompare;
1386335Sgblack@eecs.umich.edu
1397741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1407741Sgblack@eecs.umich.edu            &ISA::processHSTickCompare> HSTickCompareEvent;
1417741Sgblack@eecs.umich.edu    HSTickCompareEvent *hSTickCompare;
1426337Sgblack@eecs.umich.edu
1437741Sgblack@eecs.umich.edu    static const int NumGlobalRegs = 8;
1447741Sgblack@eecs.umich.edu    static const int NumWindowedRegs = 24;
1457741Sgblack@eecs.umich.edu    static const int WindowOverlap = 8;
1466337Sgblack@eecs.umich.edu
1477741Sgblack@eecs.umich.edu    static const int TotalGlobals = (MaxGL + 1) * NumGlobalRegs;
1487741Sgblack@eecs.umich.edu    static const int RegsPerWindow = NumWindowedRegs - WindowOverlap;
1497741Sgblack@eecs.umich.edu    static const int TotalWindowed = NWindows * RegsPerWindow;
1506337Sgblack@eecs.umich.edu
1517741Sgblack@eecs.umich.edu    enum InstIntRegOffsets {
1527741Sgblack@eecs.umich.edu        CurrentGlobalsOffset = 0,
1537741Sgblack@eecs.umich.edu        CurrentWindowOffset = CurrentGlobalsOffset + NumGlobalRegs,
1547741Sgblack@eecs.umich.edu        MicroIntOffset = CurrentWindowOffset + NumWindowedRegs,
1557741Sgblack@eecs.umich.edu        NextGlobalsOffset = MicroIntOffset + NumMicroIntRegs,
1567741Sgblack@eecs.umich.edu        NextWindowOffset = NextGlobalsOffset + NumGlobalRegs,
1577741Sgblack@eecs.umich.edu        PreviousGlobalsOffset = NextWindowOffset + NumWindowedRegs,
1587741Sgblack@eecs.umich.edu        PreviousWindowOffset = PreviousGlobalsOffset + NumGlobalRegs,
1597741Sgblack@eecs.umich.edu        TotalInstIntRegs = PreviousWindowOffset + NumWindowedRegs
1607741Sgblack@eecs.umich.edu    };
1616337Sgblack@eecs.umich.edu
1627741Sgblack@eecs.umich.edu    RegIndex intRegMap[TotalInstIntRegs];
1637741Sgblack@eecs.umich.edu    void installWindow(int cwp, int offset);
1647741Sgblack@eecs.umich.edu    void installGlobals(int gl, int offset);
1657741Sgblack@eecs.umich.edu    void reloadRegMap();
1666337Sgblack@eecs.umich.edu
1677741Sgblack@eecs.umich.edu  public:
1686335Sgblack@eecs.umich.edu
1697741Sgblack@eecs.umich.edu    void clear();
1706335Sgblack@eecs.umich.edu
17111168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
17211168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
1736335Sgblack@eecs.umich.edu
1749461Snilay@cs.wisc.edu    void startup(ThreadContext *tc) {}
1759461Snilay@cs.wisc.edu
1769553Sandreas.hansson@arm.com    /// Explicitly import the otherwise hidden startup
1779553Sandreas.hansson@arm.com    using SimObject::startup;
1789553Sandreas.hansson@arm.com
1797741Sgblack@eecs.umich.edu  protected:
1808829Sgblack@eecs.umich.edu    bool isHyperPriv() { return hpstate.hpriv; }
1818829Sgblack@eecs.umich.edu    bool isPriv() { return hpstate.hpriv || pstate.priv; }
1827741Sgblack@eecs.umich.edu    bool isNonPriv() { return !isPriv(); }
1836313Sgblack@eecs.umich.edu
1847741Sgblack@eecs.umich.edu  public:
1856313Sgblack@eecs.umich.edu
18610698Sandreas.hansson@arm.com    MiscReg readMiscRegNoEffect(int miscReg) const;
1877741Sgblack@eecs.umich.edu    MiscReg readMiscReg(int miscReg, ThreadContext *tc);
1886313Sgblack@eecs.umich.edu
1897741Sgblack@eecs.umich.edu    void setMiscRegNoEffect(int miscReg, const MiscReg val);
1907741Sgblack@eecs.umich.edu    void setMiscReg(int miscReg, const MiscReg val,
1917741Sgblack@eecs.umich.edu            ThreadContext *tc);
1926313Sgblack@eecs.umich.edu
19312106SRekai.GonzalezAlberquilla@arm.com    RegId
19412106SRekai.GonzalezAlberquilla@arm.com    flattenRegId(const RegId& regId) const
19512106SRekai.GonzalezAlberquilla@arm.com    {
19612106SRekai.GonzalezAlberquilla@arm.com        switch (regId.classValue()) {
19712106SRekai.GonzalezAlberquilla@arm.com          case IntRegClass:
19812106SRekai.GonzalezAlberquilla@arm.com            return RegId(IntRegClass, flattenIntIndex(regId.index()));
19912106SRekai.GonzalezAlberquilla@arm.com          case FloatRegClass:
20012106SRekai.GonzalezAlberquilla@arm.com            return RegId(FloatRegClass, flattenFloatIndex(regId.index()));
20112106SRekai.GonzalezAlberquilla@arm.com          case CCRegClass:
20212106SRekai.GonzalezAlberquilla@arm.com            return RegId(CCRegClass, flattenCCIndex(regId.index()));
20312106SRekai.GonzalezAlberquilla@arm.com          case MiscRegClass:
20412106SRekai.GonzalezAlberquilla@arm.com            return RegId(MiscRegClass, flattenMiscIndex(regId.index()));
20512109SRekai.GonzalezAlberquilla@arm.com          default:
20612109SRekai.GonzalezAlberquilla@arm.com            break;
20712106SRekai.GonzalezAlberquilla@arm.com        }
20812106SRekai.GonzalezAlberquilla@arm.com        return regId;
20912106SRekai.GonzalezAlberquilla@arm.com    }
21012106SRekai.GonzalezAlberquilla@arm.com
2117741Sgblack@eecs.umich.edu    int
21210035Sandreas.hansson@arm.com    flattenIntIndex(int reg) const
2137741Sgblack@eecs.umich.edu    {
2147741Sgblack@eecs.umich.edu        assert(reg < TotalInstIntRegs);
2157741Sgblack@eecs.umich.edu        RegIndex flatIndex = intRegMap[reg];
2167741Sgblack@eecs.umich.edu        assert(flatIndex < NumIntRegs);
2177741Sgblack@eecs.umich.edu        return flatIndex;
2187741Sgblack@eecs.umich.edu    }
2196313Sgblack@eecs.umich.edu
2207741Sgblack@eecs.umich.edu    int
22110035Sandreas.hansson@arm.com    flattenFloatIndex(int reg) const
2227741Sgblack@eecs.umich.edu    {
2237741Sgblack@eecs.umich.edu        return reg;
2247741Sgblack@eecs.umich.edu    }
2256313Sgblack@eecs.umich.edu
22612109SRekai.GonzalezAlberquilla@arm.com    int
22712109SRekai.GonzalezAlberquilla@arm.com    flattenVecIndex(int reg) const
22812109SRekai.GonzalezAlberquilla@arm.com    {
22912109SRekai.GonzalezAlberquilla@arm.com        return reg;
23012109SRekai.GonzalezAlberquilla@arm.com    }
23112109SRekai.GonzalezAlberquilla@arm.com
23212109SRekai.GonzalezAlberquilla@arm.com    int
23312109SRekai.GonzalezAlberquilla@arm.com    flattenVecElemIndex(int reg) const
23412109SRekai.GonzalezAlberquilla@arm.com    {
23512109SRekai.GonzalezAlberquilla@arm.com        return reg;
23612109SRekai.GonzalezAlberquilla@arm.com    }
23712109SRekai.GonzalezAlberquilla@arm.com
2389920Syasuko.eckert@amd.com    // dummy
2399920Syasuko.eckert@amd.com    int
24010035Sandreas.hansson@arm.com    flattenCCIndex(int reg) const
2419920Syasuko.eckert@amd.com    {
2429920Syasuko.eckert@amd.com        return reg;
2439920Syasuko.eckert@amd.com    }
2449920Syasuko.eckert@amd.com
24510033SAli.Saidi@ARM.com    int
24610035Sandreas.hansson@arm.com    flattenMiscIndex(int reg) const
24710033SAli.Saidi@ARM.com    {
24810033SAli.Saidi@ARM.com        return reg;
24910033SAli.Saidi@ARM.com    }
25010033SAli.Saidi@ARM.com
25110033SAli.Saidi@ARM.com
2529384SAndreas.Sandberg@arm.com    typedef SparcISAParams Params;
2539384SAndreas.Sandberg@arm.com    const Params *params() const;
2547703Sgblack@eecs.umich.edu
2559384SAndreas.Sandberg@arm.com    ISA(Params *p);
2567741Sgblack@eecs.umich.edu};
2576313Sgblack@eecs.umich.edu}
2586313Sgblack@eecs.umich.edu
2596313Sgblack@eecs.umich.edu#endif
260