isa.hh revision 10844
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"
409384SAndreas.Sandberg@arm.com#include "sim/sim_object.hh"
416335Sgblack@eecs.umich.edu
426313Sgblack@eecs.umich.educlass Checkpoint;
436313Sgblack@eecs.umich.educlass EventManager;
449384SAndreas.Sandberg@arm.comstruct SparcISAParams;
456335Sgblack@eecs.umich.educlass ThreadContext;
466313Sgblack@eecs.umich.edu
476313Sgblack@eecs.umich.edunamespace SparcISA
486313Sgblack@eecs.umich.edu{
499384SAndreas.Sandberg@arm.comclass ISA : public SimObject
507741Sgblack@eecs.umich.edu{
517741Sgblack@eecs.umich.edu  private:
526335Sgblack@eecs.umich.edu
537741Sgblack@eecs.umich.edu    /* ASR Registers */
547741Sgblack@eecs.umich.edu    // uint64_t y;          // Y (used in obsolete multiplication)
557741Sgblack@eecs.umich.edu    // uint8_t ccr;         // Condition Code Register
567741Sgblack@eecs.umich.edu    uint8_t asi;            // Address Space Identifier
577741Sgblack@eecs.umich.edu    uint64_t tick;          // Hardware clock-tick counter
587741Sgblack@eecs.umich.edu    uint8_t fprs;           // Floating-Point Register State
597741Sgblack@eecs.umich.edu    uint64_t gsr;           // General Status Register
607741Sgblack@eecs.umich.edu    uint64_t softint;
617741Sgblack@eecs.umich.edu    uint64_t tick_cmpr;     // Hardware tick compare registers
627741Sgblack@eecs.umich.edu    uint64_t stick;         // Hardware clock-tick counter
637741Sgblack@eecs.umich.edu    uint64_t stick_cmpr;    // Hardware tick compare registers
646335Sgblack@eecs.umich.edu
656335Sgblack@eecs.umich.edu
667741Sgblack@eecs.umich.edu    /* Privileged Registers */
677741Sgblack@eecs.umich.edu    uint64_t tpc[MaxTL];    // Trap Program Counter (value from
687741Sgblack@eecs.umich.edu                            // previous trap level)
697741Sgblack@eecs.umich.edu    uint64_t tnpc[MaxTL];   // Trap Next Program Counter (value from
707741Sgblack@eecs.umich.edu                            // previous trap level)
717741Sgblack@eecs.umich.edu    uint64_t tstate[MaxTL]; // Trap State
727741Sgblack@eecs.umich.edu    uint16_t tt[MaxTL];     // Trap Type (Type of trap which occured
737741Sgblack@eecs.umich.edu                            // on the previous level)
747741Sgblack@eecs.umich.edu    uint64_t tba;           // Trap Base Address
756335Sgblack@eecs.umich.edu
768829Sgblack@eecs.umich.edu    PSTATE pstate;        // Process State Register
777741Sgblack@eecs.umich.edu    uint8_t tl;             // Trap Level
787741Sgblack@eecs.umich.edu    uint8_t pil;            // Process Interrupt Register
797741Sgblack@eecs.umich.edu    uint8_t cwp;            // Current Window Pointer
807741Sgblack@eecs.umich.edu    // uint8_t cansave;     // Savable windows
817741Sgblack@eecs.umich.edu    // uint8_t canrestore;  // Restorable windows
827741Sgblack@eecs.umich.edu    // uint8_t cleanwin;    // Clean windows
837741Sgblack@eecs.umich.edu    // uint8_t otherwin;    // Other windows
847741Sgblack@eecs.umich.edu    // uint8_t wstate;      // Window State
857741Sgblack@eecs.umich.edu    uint8_t gl;             // Global level register
866335Sgblack@eecs.umich.edu
877741Sgblack@eecs.umich.edu    /** Hyperprivileged Registers */
888829Sgblack@eecs.umich.edu    HPSTATE hpstate;       // Hyperprivileged State Register
897741Sgblack@eecs.umich.edu    uint64_t htstate[MaxTL];// Hyperprivileged Trap State Register
907741Sgblack@eecs.umich.edu    uint64_t hintp;
917741Sgblack@eecs.umich.edu    uint64_t htba;          // Hyperprivileged Trap Base Address register
927741Sgblack@eecs.umich.edu    uint64_t hstick_cmpr;   // Hardware tick compare registers
936335Sgblack@eecs.umich.edu
947741Sgblack@eecs.umich.edu    uint64_t strandStatusReg;// Per strand status register
956335Sgblack@eecs.umich.edu
967741Sgblack@eecs.umich.edu    /** Floating point misc registers. */
977741Sgblack@eecs.umich.edu    uint64_t fsr;           // Floating-Point State Register
986335Sgblack@eecs.umich.edu
997741Sgblack@eecs.umich.edu    /** MMU Internal Registers */
1007741Sgblack@eecs.umich.edu    uint16_t priContext;
1017741Sgblack@eecs.umich.edu    uint16_t secContext;
1027741Sgblack@eecs.umich.edu    uint16_t partId;
1037741Sgblack@eecs.umich.edu    uint64_t lsuCtrlReg;
1046335Sgblack@eecs.umich.edu
1057741Sgblack@eecs.umich.edu    uint64_t scratchPad[8];
1066335Sgblack@eecs.umich.edu
1077741Sgblack@eecs.umich.edu    uint64_t cpu_mondo_head;
1087741Sgblack@eecs.umich.edu    uint64_t cpu_mondo_tail;
1097741Sgblack@eecs.umich.edu    uint64_t dev_mondo_head;
1107741Sgblack@eecs.umich.edu    uint64_t dev_mondo_tail;
1117741Sgblack@eecs.umich.edu    uint64_t res_error_head;
1127741Sgblack@eecs.umich.edu    uint64_t res_error_tail;
1137741Sgblack@eecs.umich.edu    uint64_t nres_error_head;
1147741Sgblack@eecs.umich.edu    uint64_t nres_error_tail;
1156335Sgblack@eecs.umich.edu
1167741Sgblack@eecs.umich.edu    // These need to check the int_dis field and if 0 then
1177741Sgblack@eecs.umich.edu    // set appropriate bit in softint and checkinterrutps on the cpu
1187741Sgblack@eecs.umich.edu    void  setFSReg(int miscReg, const MiscReg &val, ThreadContext *tc);
1197741Sgblack@eecs.umich.edu    MiscReg readFSReg(int miscReg, ThreadContext * tc);
1206335Sgblack@eecs.umich.edu
1217741Sgblack@eecs.umich.edu    // Update interrupt state on softint or pil change
1227741Sgblack@eecs.umich.edu    void checkSoftInt(ThreadContext *tc);
1236335Sgblack@eecs.umich.edu
1247741Sgblack@eecs.umich.edu    /** Process a tick compare event and generate an interrupt on the cpu if
1257741Sgblack@eecs.umich.edu     * appropriate. */
1267741Sgblack@eecs.umich.edu    void processTickCompare(ThreadContext *tc);
1277741Sgblack@eecs.umich.edu    void processSTickCompare(ThreadContext *tc);
1287741Sgblack@eecs.umich.edu    void processHSTickCompare(ThreadContext *tc);
1296335Sgblack@eecs.umich.edu
1307741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1317741Sgblack@eecs.umich.edu            &ISA::processTickCompare> TickCompareEvent;
1327741Sgblack@eecs.umich.edu    TickCompareEvent *tickCompare;
1336335Sgblack@eecs.umich.edu
1347741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1357741Sgblack@eecs.umich.edu            &ISA::processSTickCompare> STickCompareEvent;
1367741Sgblack@eecs.umich.edu    STickCompareEvent *sTickCompare;
1376335Sgblack@eecs.umich.edu
1387741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1397741Sgblack@eecs.umich.edu            &ISA::processHSTickCompare> HSTickCompareEvent;
1407741Sgblack@eecs.umich.edu    HSTickCompareEvent *hSTickCompare;
1416337Sgblack@eecs.umich.edu
1427741Sgblack@eecs.umich.edu    static const int NumGlobalRegs = 8;
1437741Sgblack@eecs.umich.edu    static const int NumWindowedRegs = 24;
1447741Sgblack@eecs.umich.edu    static const int WindowOverlap = 8;
1456337Sgblack@eecs.umich.edu
1467741Sgblack@eecs.umich.edu    static const int TotalGlobals = (MaxGL + 1) * NumGlobalRegs;
1477741Sgblack@eecs.umich.edu    static const int RegsPerWindow = NumWindowedRegs - WindowOverlap;
1487741Sgblack@eecs.umich.edu    static const int TotalWindowed = NWindows * RegsPerWindow;
1496337Sgblack@eecs.umich.edu
1507741Sgblack@eecs.umich.edu    enum InstIntRegOffsets {
1517741Sgblack@eecs.umich.edu        CurrentGlobalsOffset = 0,
1527741Sgblack@eecs.umich.edu        CurrentWindowOffset = CurrentGlobalsOffset + NumGlobalRegs,
1537741Sgblack@eecs.umich.edu        MicroIntOffset = CurrentWindowOffset + NumWindowedRegs,
1547741Sgblack@eecs.umich.edu        NextGlobalsOffset = MicroIntOffset + NumMicroIntRegs,
1557741Sgblack@eecs.umich.edu        NextWindowOffset = NextGlobalsOffset + NumGlobalRegs,
1567741Sgblack@eecs.umich.edu        PreviousGlobalsOffset = NextWindowOffset + NumWindowedRegs,
1577741Sgblack@eecs.umich.edu        PreviousWindowOffset = PreviousGlobalsOffset + NumGlobalRegs,
1587741Sgblack@eecs.umich.edu        TotalInstIntRegs = PreviousWindowOffset + NumWindowedRegs
1597741Sgblack@eecs.umich.edu    };
1606337Sgblack@eecs.umich.edu
1617741Sgblack@eecs.umich.edu    RegIndex intRegMap[TotalInstIntRegs];
1627741Sgblack@eecs.umich.edu    void installWindow(int cwp, int offset);
1637741Sgblack@eecs.umich.edu    void installGlobals(int gl, int offset);
1647741Sgblack@eecs.umich.edu    void reloadRegMap();
1656337Sgblack@eecs.umich.edu
1667741Sgblack@eecs.umich.edu  public:
1676335Sgblack@eecs.umich.edu
1687741Sgblack@eecs.umich.edu    void clear();
1696335Sgblack@eecs.umich.edu
1709425SAndreas.Sandberg@ARM.com    void serialize(std::ostream & os);
1716335Sgblack@eecs.umich.edu
1729425SAndreas.Sandberg@ARM.com    void unserialize(Checkpoint *cp, const std::string & section);
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
1937741Sgblack@eecs.umich.edu    int
19410035Sandreas.hansson@arm.com    flattenIntIndex(int reg) const
1957741Sgblack@eecs.umich.edu    {
1967741Sgblack@eecs.umich.edu        assert(reg < TotalInstIntRegs);
1977741Sgblack@eecs.umich.edu        RegIndex flatIndex = intRegMap[reg];
1987741Sgblack@eecs.umich.edu        assert(flatIndex < NumIntRegs);
1997741Sgblack@eecs.umich.edu        return flatIndex;
2007741Sgblack@eecs.umich.edu    }
2016313Sgblack@eecs.umich.edu
2027741Sgblack@eecs.umich.edu    int
20310035Sandreas.hansson@arm.com    flattenFloatIndex(int reg) const
2047741Sgblack@eecs.umich.edu    {
2057741Sgblack@eecs.umich.edu        return reg;
2067741Sgblack@eecs.umich.edu    }
2076313Sgblack@eecs.umich.edu
2089920Syasuko.eckert@amd.com    // dummy
2099920Syasuko.eckert@amd.com    int
21010035Sandreas.hansson@arm.com    flattenCCIndex(int reg) const
2119920Syasuko.eckert@amd.com    {
2129920Syasuko.eckert@amd.com        return reg;
2139920Syasuko.eckert@amd.com    }
2149920Syasuko.eckert@amd.com
21510033SAli.Saidi@ARM.com    int
21610035Sandreas.hansson@arm.com    flattenMiscIndex(int reg) const
21710033SAli.Saidi@ARM.com    {
21810033SAli.Saidi@ARM.com        return reg;
21910033SAli.Saidi@ARM.com    }
22010033SAli.Saidi@ARM.com
22110033SAli.Saidi@ARM.com
2229384SAndreas.Sandberg@arm.com    typedef SparcISAParams Params;
2239384SAndreas.Sandberg@arm.com    const Params *params() const;
2247703Sgblack@eecs.umich.edu
2259384SAndreas.Sandberg@arm.com    ISA(Params *p);
2267741Sgblack@eecs.umich.edu};
2276313Sgblack@eecs.umich.edu}
2286313Sgblack@eecs.umich.edu
2296313Sgblack@eecs.umich.edu#endif
230