isa.hh revision 9376
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"
406335Sgblack@eecs.umich.edu
416313Sgblack@eecs.umich.educlass Checkpoint;
426313Sgblack@eecs.umich.educlass EventManager;
436335Sgblack@eecs.umich.educlass ThreadContext;
446313Sgblack@eecs.umich.edu
456313Sgblack@eecs.umich.edunamespace SparcISA
466313Sgblack@eecs.umich.edu{
477741Sgblack@eecs.umich.educlass ISA
487741Sgblack@eecs.umich.edu{
497741Sgblack@eecs.umich.edu  private:
506335Sgblack@eecs.umich.edu
517741Sgblack@eecs.umich.edu    /* ASR Registers */
527741Sgblack@eecs.umich.edu    // uint64_t y;          // Y (used in obsolete multiplication)
537741Sgblack@eecs.umich.edu    // uint8_t ccr;         // Condition Code Register
547741Sgblack@eecs.umich.edu    uint8_t asi;            // Address Space Identifier
557741Sgblack@eecs.umich.edu    uint64_t tick;          // Hardware clock-tick counter
567741Sgblack@eecs.umich.edu    uint8_t fprs;           // Floating-Point Register State
577741Sgblack@eecs.umich.edu    uint64_t gsr;           // General Status Register
587741Sgblack@eecs.umich.edu    uint64_t softint;
597741Sgblack@eecs.umich.edu    uint64_t tick_cmpr;     // Hardware tick compare registers
607741Sgblack@eecs.umich.edu    uint64_t stick;         // Hardware clock-tick counter
617741Sgblack@eecs.umich.edu    uint64_t stick_cmpr;    // Hardware tick compare registers
626335Sgblack@eecs.umich.edu
636335Sgblack@eecs.umich.edu
647741Sgblack@eecs.umich.edu    /* Privileged Registers */
657741Sgblack@eecs.umich.edu    uint64_t tpc[MaxTL];    // Trap Program Counter (value from
667741Sgblack@eecs.umich.edu                            // previous trap level)
677741Sgblack@eecs.umich.edu    uint64_t tnpc[MaxTL];   // Trap Next Program Counter (value from
687741Sgblack@eecs.umich.edu                            // previous trap level)
697741Sgblack@eecs.umich.edu    uint64_t tstate[MaxTL]; // Trap State
707741Sgblack@eecs.umich.edu    uint16_t tt[MaxTL];     // Trap Type (Type of trap which occured
717741Sgblack@eecs.umich.edu                            // on the previous level)
727741Sgblack@eecs.umich.edu    uint64_t tba;           // Trap Base Address
736335Sgblack@eecs.umich.edu
748829Sgblack@eecs.umich.edu    PSTATE pstate;        // Process State Register
757741Sgblack@eecs.umich.edu    uint8_t tl;             // Trap Level
767741Sgblack@eecs.umich.edu    uint8_t pil;            // Process Interrupt Register
777741Sgblack@eecs.umich.edu    uint8_t cwp;            // Current Window Pointer
787741Sgblack@eecs.umich.edu    // uint8_t cansave;     // Savable windows
797741Sgblack@eecs.umich.edu    // uint8_t canrestore;  // Restorable windows
807741Sgblack@eecs.umich.edu    // uint8_t cleanwin;    // Clean windows
817741Sgblack@eecs.umich.edu    // uint8_t otherwin;    // Other windows
827741Sgblack@eecs.umich.edu    // uint8_t wstate;      // Window State
837741Sgblack@eecs.umich.edu    uint8_t gl;             // Global level register
846335Sgblack@eecs.umich.edu
857741Sgblack@eecs.umich.edu    /** Hyperprivileged Registers */
868829Sgblack@eecs.umich.edu    HPSTATE hpstate;       // Hyperprivileged State Register
877741Sgblack@eecs.umich.edu    uint64_t htstate[MaxTL];// Hyperprivileged Trap State Register
887741Sgblack@eecs.umich.edu    uint64_t hintp;
897741Sgblack@eecs.umich.edu    uint64_t htba;          // Hyperprivileged Trap Base Address register
907741Sgblack@eecs.umich.edu    uint64_t hstick_cmpr;   // Hardware tick compare registers
916335Sgblack@eecs.umich.edu
927741Sgblack@eecs.umich.edu    uint64_t strandStatusReg;// Per strand status register
936335Sgblack@eecs.umich.edu
947741Sgblack@eecs.umich.edu    /** Floating point misc registers. */
957741Sgblack@eecs.umich.edu    uint64_t fsr;           // Floating-Point State Register
966335Sgblack@eecs.umich.edu
977741Sgblack@eecs.umich.edu    /** MMU Internal Registers */
987741Sgblack@eecs.umich.edu    uint16_t priContext;
997741Sgblack@eecs.umich.edu    uint16_t secContext;
1007741Sgblack@eecs.umich.edu    uint16_t partId;
1017741Sgblack@eecs.umich.edu    uint64_t lsuCtrlReg;
1026335Sgblack@eecs.umich.edu
1037741Sgblack@eecs.umich.edu    uint64_t scratchPad[8];
1046335Sgblack@eecs.umich.edu
1057741Sgblack@eecs.umich.edu    uint64_t cpu_mondo_head;
1067741Sgblack@eecs.umich.edu    uint64_t cpu_mondo_tail;
1077741Sgblack@eecs.umich.edu    uint64_t dev_mondo_head;
1087741Sgblack@eecs.umich.edu    uint64_t dev_mondo_tail;
1097741Sgblack@eecs.umich.edu    uint64_t res_error_head;
1107741Sgblack@eecs.umich.edu    uint64_t res_error_tail;
1117741Sgblack@eecs.umich.edu    uint64_t nres_error_head;
1127741Sgblack@eecs.umich.edu    uint64_t nres_error_tail;
1136335Sgblack@eecs.umich.edu
1147741Sgblack@eecs.umich.edu    // These need to check the int_dis field and if 0 then
1157741Sgblack@eecs.umich.edu    // set appropriate bit in softint and checkinterrutps on the cpu
1167741Sgblack@eecs.umich.edu    void  setFSReg(int miscReg, const MiscReg &val, ThreadContext *tc);
1177741Sgblack@eecs.umich.edu    MiscReg readFSReg(int miscReg, ThreadContext * tc);
1186335Sgblack@eecs.umich.edu
1197741Sgblack@eecs.umich.edu    // Update interrupt state on softint or pil change
1207741Sgblack@eecs.umich.edu    void checkSoftInt(ThreadContext *tc);
1216335Sgblack@eecs.umich.edu
1227741Sgblack@eecs.umich.edu    /** Process a tick compare event and generate an interrupt on the cpu if
1237741Sgblack@eecs.umich.edu     * appropriate. */
1247741Sgblack@eecs.umich.edu    void processTickCompare(ThreadContext *tc);
1257741Sgblack@eecs.umich.edu    void processSTickCompare(ThreadContext *tc);
1267741Sgblack@eecs.umich.edu    void processHSTickCompare(ThreadContext *tc);
1276335Sgblack@eecs.umich.edu
1287741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1297741Sgblack@eecs.umich.edu            &ISA::processTickCompare> TickCompareEvent;
1307741Sgblack@eecs.umich.edu    TickCompareEvent *tickCompare;
1316335Sgblack@eecs.umich.edu
1327741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1337741Sgblack@eecs.umich.edu            &ISA::processSTickCompare> STickCompareEvent;
1347741Sgblack@eecs.umich.edu    STickCompareEvent *sTickCompare;
1356335Sgblack@eecs.umich.edu
1367741Sgblack@eecs.umich.edu    typedef CpuEventWrapper<ISA,
1377741Sgblack@eecs.umich.edu            &ISA::processHSTickCompare> HSTickCompareEvent;
1387741Sgblack@eecs.umich.edu    HSTickCompareEvent *hSTickCompare;
1396337Sgblack@eecs.umich.edu
1407741Sgblack@eecs.umich.edu    static const int NumGlobalRegs = 8;
1417741Sgblack@eecs.umich.edu    static const int NumWindowedRegs = 24;
1427741Sgblack@eecs.umich.edu    static const int WindowOverlap = 8;
1436337Sgblack@eecs.umich.edu
1447741Sgblack@eecs.umich.edu    static const int TotalGlobals = (MaxGL + 1) * NumGlobalRegs;
1457741Sgblack@eecs.umich.edu    static const int RegsPerWindow = NumWindowedRegs - WindowOverlap;
1467741Sgblack@eecs.umich.edu    static const int TotalWindowed = NWindows * RegsPerWindow;
1476337Sgblack@eecs.umich.edu
1487741Sgblack@eecs.umich.edu    enum InstIntRegOffsets {
1497741Sgblack@eecs.umich.edu        CurrentGlobalsOffset = 0,
1507741Sgblack@eecs.umich.edu        CurrentWindowOffset = CurrentGlobalsOffset + NumGlobalRegs,
1517741Sgblack@eecs.umich.edu        MicroIntOffset = CurrentWindowOffset + NumWindowedRegs,
1527741Sgblack@eecs.umich.edu        NextGlobalsOffset = MicroIntOffset + NumMicroIntRegs,
1537741Sgblack@eecs.umich.edu        NextWindowOffset = NextGlobalsOffset + NumGlobalRegs,
1547741Sgblack@eecs.umich.edu        PreviousGlobalsOffset = NextWindowOffset + NumWindowedRegs,
1557741Sgblack@eecs.umich.edu        PreviousWindowOffset = PreviousGlobalsOffset + NumGlobalRegs,
1567741Sgblack@eecs.umich.edu        TotalInstIntRegs = PreviousWindowOffset + NumWindowedRegs
1577741Sgblack@eecs.umich.edu    };
1586337Sgblack@eecs.umich.edu
1597741Sgblack@eecs.umich.edu    RegIndex intRegMap[TotalInstIntRegs];
1607741Sgblack@eecs.umich.edu    void installWindow(int cwp, int offset);
1617741Sgblack@eecs.umich.edu    void installGlobals(int gl, int offset);
1627741Sgblack@eecs.umich.edu    void reloadRegMap();
1636337Sgblack@eecs.umich.edu
1647741Sgblack@eecs.umich.edu  public:
1656335Sgblack@eecs.umich.edu
1667741Sgblack@eecs.umich.edu    void clear();
1676335Sgblack@eecs.umich.edu
1687741Sgblack@eecs.umich.edu    void serialize(EventManager *em, std::ostream & os);
1696335Sgblack@eecs.umich.edu
1707741Sgblack@eecs.umich.edu    void unserialize(EventManager *em, Checkpoint *cp,
1717741Sgblack@eecs.umich.edu                     const std::string & section);
1726335Sgblack@eecs.umich.edu
1737741Sgblack@eecs.umich.edu  protected:
1746335Sgblack@eecs.umich.edu
1758829Sgblack@eecs.umich.edu    bool isHyperPriv() { return hpstate.hpriv; }
1768829Sgblack@eecs.umich.edu    bool isPriv() { return hpstate.hpriv || pstate.priv; }
1777741Sgblack@eecs.umich.edu    bool isNonPriv() { return !isPriv(); }
1786313Sgblack@eecs.umich.edu
1797741Sgblack@eecs.umich.edu  public:
1806313Sgblack@eecs.umich.edu
1817741Sgblack@eecs.umich.edu    MiscReg readMiscRegNoEffect(int miscReg);
1827741Sgblack@eecs.umich.edu    MiscReg readMiscReg(int miscReg, ThreadContext *tc);
1836313Sgblack@eecs.umich.edu
1847741Sgblack@eecs.umich.edu    void setMiscRegNoEffect(int miscReg, const MiscReg val);
1857741Sgblack@eecs.umich.edu    void setMiscReg(int miscReg, const MiscReg val,
1867741Sgblack@eecs.umich.edu            ThreadContext *tc);
1876313Sgblack@eecs.umich.edu
1887741Sgblack@eecs.umich.edu    int
1897741Sgblack@eecs.umich.edu    flattenIntIndex(int reg)
1907741Sgblack@eecs.umich.edu    {
1917741Sgblack@eecs.umich.edu        assert(reg < TotalInstIntRegs);
1927741Sgblack@eecs.umich.edu        RegIndex flatIndex = intRegMap[reg];
1937741Sgblack@eecs.umich.edu        assert(flatIndex < NumIntRegs);
1947741Sgblack@eecs.umich.edu        return flatIndex;
1957741Sgblack@eecs.umich.edu    }
1966313Sgblack@eecs.umich.edu
1977741Sgblack@eecs.umich.edu    int
1987741Sgblack@eecs.umich.edu    flattenFloatIndex(int reg)
1997741Sgblack@eecs.umich.edu    {
2007741Sgblack@eecs.umich.edu        return reg;
2017741Sgblack@eecs.umich.edu    }
2026313Sgblack@eecs.umich.edu
2037741Sgblack@eecs.umich.edu    ISA()
2047741Sgblack@eecs.umich.edu    {
2057741Sgblack@eecs.umich.edu        tickCompare = NULL;
2067741Sgblack@eecs.umich.edu        sTickCompare = NULL;
2077741Sgblack@eecs.umich.edu        hSTickCompare = NULL;
2087703Sgblack@eecs.umich.edu
2097741Sgblack@eecs.umich.edu        clear();
2107741Sgblack@eecs.umich.edu    }
2117741Sgblack@eecs.umich.edu};
2126313Sgblack@eecs.umich.edu}
2136313Sgblack@eecs.umich.edu
2146313Sgblack@eecs.umich.edu#endif
215