isa.hh revision 12529
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
377629Sgblack@eecs.umich.edu#include "arch/sparc/registers.hh"
387629Sgblack@eecs.umich.edu#include "arch/sparc/types.hh"
398229Snate@binkert.org#include "cpu/cpuevent.hh"
406336Sgblack@eecs.umich.edu#include "cpu/reg_class.hh"
419384SAndreas.Sandberg@arm.com#include "sim/sim_object.hh"
426336Sgblack@eecs.umich.edu
436313Sgblack@eecs.umich.educlass Checkpoint;
446313Sgblack@eecs.umich.educlass EventManager;
456336Sgblack@eecs.umich.edustruct SparcISAParams;
469384SAndreas.Sandberg@arm.comclass ThreadContext;
476313Sgblack@eecs.umich.edu
486313Sgblack@eecs.umich.edunamespace SparcISA
496313Sgblack@eecs.umich.edu{
509384SAndreas.Sandberg@arm.comclass ISA : public SimObject
516313Sgblack@eecs.umich.edu{
526313Sgblack@eecs.umich.edu  private:
536336Sgblack@eecs.umich.edu
546336Sgblack@eecs.umich.edu    /* ASR Registers */
559376Sgblack@eecs.umich.edu    // uint64_t y;          // Y (used in obsolete multiplication)
569376Sgblack@eecs.umich.edu    // uint8_t ccr;         // Condition Code Register
576313Sgblack@eecs.umich.edu    uint8_t asi;            // Address Space Identifier
586313Sgblack@eecs.umich.edu    uint64_t tick;          // Hardware clock-tick counter
599384SAndreas.Sandberg@arm.com    uint8_t fprs;           // Floating-Point Register State
609384SAndreas.Sandberg@arm.com    uint64_t gsr;           // General Status Register
616313Sgblack@eecs.umich.edu    uint64_t softint;
626313Sgblack@eecs.umich.edu    uint64_t tick_cmpr;     // Hardware tick compare registers
639384SAndreas.Sandberg@arm.com    uint64_t stick;         // Hardware clock-tick counter
649384SAndreas.Sandberg@arm.com    uint64_t stick_cmpr;    // Hardware tick compare registers
656336Sgblack@eecs.umich.edu
6610698Sandreas.hansson@arm.com
676313Sgblack@eecs.umich.edu    /* Privileged Registers */
686313Sgblack@eecs.umich.edu    uint64_t tpc[MaxTL];    // Trap Program Counter (value from
696336Sgblack@eecs.umich.edu                            // previous trap level)
706336Sgblack@eecs.umich.edu    uint64_t tnpc[MaxTL];   // Trap Next Program Counter (value from
716313Sgblack@eecs.umich.edu                            // previous trap level)
726359Sgblack@eecs.umich.edu    uint64_t tstate[MaxTL]; // Trap State
7310035Sandreas.hansson@arm.com    uint16_t tt[MaxTL];     // Trap Type (Type of trap which occured
746359Sgblack@eecs.umich.edu                            // on the previous level)
756361Sgblack@eecs.umich.edu    uint64_t tba;           // Trap Base Address
766359Sgblack@eecs.umich.edu
776359Sgblack@eecs.umich.edu    PSTATE pstate;        // Process State Register
786359Sgblack@eecs.umich.edu    uint8_t tl;             // Trap Level
7910035Sandreas.hansson@arm.com    uint8_t pil;            // Process Interrupt Register
806359Sgblack@eecs.umich.edu    uint8_t cwp;            // Current Window Pointer
816359Sgblack@eecs.umich.edu    // uint8_t cansave;     // Savable windows
826359Sgblack@eecs.umich.edu    // uint8_t canrestore;  // Restorable windows
836359Sgblack@eecs.umich.edu    // uint8_t cleanwin;    // Clean windows
846359Sgblack@eecs.umich.edu    // uint8_t otherwin;    // Other windows
856359Sgblack@eecs.umich.edu    // uint8_t wstate;      // Window State
866359Sgblack@eecs.umich.edu    uint8_t gl;             // Global level register
876313Sgblack@eecs.umich.edu
889920Syasuko.eckert@amd.com    /** Hyperprivileged Registers */
8910035Sandreas.hansson@arm.com    HPSTATE hpstate;       // Hyperprivileged State Register
909920Syasuko.eckert@amd.com    uint64_t htstate[MaxTL];// Hyperprivileged Trap State Register
919920Syasuko.eckert@amd.com    uint64_t hintp;
929920Syasuko.eckert@amd.com    uint64_t htba;          // Hyperprivileged Trap Base Address register
939920Syasuko.eckert@amd.com    uint64_t hstick_cmpr;   // Hardware tick compare registers
9410033SAli.Saidi@ARM.com
9510035Sandreas.hansson@arm.com    uint64_t strandStatusReg;// Per strand status register
9610033SAli.Saidi@ARM.com
9710033SAli.Saidi@ARM.com    /** Floating point misc registers. */
9810033SAli.Saidi@ARM.com    uint64_t fsr;           // Floating-Point State Register
9910033SAli.Saidi@ARM.com
1009425SAndreas.Sandberg@ARM.com    /** MMU Internal Registers */
1019425SAndreas.Sandberg@ARM.com    uint16_t priContext;
1029461Snilay@cs.wisc.edu    uint16_t secContext;
1039553Sandreas.hansson@arm.com    uint16_t partId;
1049553Sandreas.hansson@arm.com    uint64_t lsuCtrlReg;
1059553Sandreas.hansson@arm.com
1069553Sandreas.hansson@arm.com    uint64_t scratchPad[8];
1076313Sgblack@eecs.umich.edu
1086313Sgblack@eecs.umich.edu    uint64_t cpu_mondo_head;
1096313Sgblack@eecs.umich.edu    uint64_t cpu_mondo_tail;
1106313Sgblack@eecs.umich.edu    uint64_t dev_mondo_head;
111    uint64_t dev_mondo_tail;
112    uint64_t res_error_head;
113    uint64_t res_error_tail;
114    uint64_t nres_error_head;
115    uint64_t nres_error_tail;
116
117    // These need to check the int_dis field and if 0 then
118    // set appropriate bit in softint and checkinterrutps on the cpu
119    void  setFSReg(int miscReg, const MiscReg &val, ThreadContext *tc);
120    MiscReg readFSReg(int miscReg, ThreadContext * tc);
121
122    // Update interrupt state on softint or pil change
123    void checkSoftInt(ThreadContext *tc);
124
125    /** Process a tick compare event and generate an interrupt on the cpu if
126     * appropriate. */
127    void processTickCompare(ThreadContext *tc);
128    void processSTickCompare(ThreadContext *tc);
129    void processHSTickCompare(ThreadContext *tc);
130
131    typedef CpuEventWrapper<ISA,
132            &ISA::processTickCompare> TickCompareEvent;
133    TickCompareEvent *tickCompare;
134
135    typedef CpuEventWrapper<ISA,
136            &ISA::processSTickCompare> STickCompareEvent;
137    STickCompareEvent *sTickCompare;
138
139    typedef CpuEventWrapper<ISA,
140            &ISA::processHSTickCompare> HSTickCompareEvent;
141    HSTickCompareEvent *hSTickCompare;
142
143    static const int NumGlobalRegs = 8;
144    static const int NumWindowedRegs = 24;
145    static const int WindowOverlap = 8;
146
147    static const int TotalGlobals = (MaxGL + 1) * NumGlobalRegs;
148    static const int RegsPerWindow = NumWindowedRegs - WindowOverlap;
149    static const int TotalWindowed = NWindows * RegsPerWindow;
150
151    enum InstIntRegOffsets {
152        CurrentGlobalsOffset = 0,
153        CurrentWindowOffset = CurrentGlobalsOffset + NumGlobalRegs,
154        MicroIntOffset = CurrentWindowOffset + NumWindowedRegs,
155        NextGlobalsOffset = MicroIntOffset + NumMicroIntRegs,
156        NextWindowOffset = NextGlobalsOffset + NumGlobalRegs,
157        PreviousGlobalsOffset = NextWindowOffset + NumWindowedRegs,
158        PreviousWindowOffset = PreviousGlobalsOffset + NumGlobalRegs,
159        TotalInstIntRegs = PreviousWindowOffset + NumWindowedRegs
160    };
161
162    RegIndex intRegMap[TotalInstIntRegs];
163    void installWindow(int cwp, int offset);
164    void installGlobals(int gl, int offset);
165    void reloadRegMap();
166
167  public:
168
169    void clear();
170
171    void serialize(CheckpointOut &cp) const override;
172    void unserialize(CheckpointIn &cp) override;
173
174    void startup(ThreadContext *tc) {}
175
176    /// Explicitly import the otherwise hidden startup
177    using SimObject::startup;
178
179  protected:
180    bool isHyperPriv() { return hpstate.hpriv; }
181    bool isPriv() { return hpstate.hpriv || pstate.priv; }
182    bool isNonPriv() { return !isPriv(); }
183
184  public:
185
186    MiscReg readMiscRegNoEffect(int miscReg) const;
187    MiscReg readMiscReg(int miscReg, ThreadContext *tc);
188
189    void setMiscRegNoEffect(int miscReg, const MiscReg val);
190    void setMiscReg(int miscReg, const MiscReg val,
191            ThreadContext *tc);
192
193    RegId
194    flattenRegId(const RegId& regId) const
195    {
196        switch (regId.classValue()) {
197          case IntRegClass:
198            return RegId(IntRegClass, flattenIntIndex(regId.index()));
199          case FloatRegClass:
200            return RegId(FloatRegClass, flattenFloatIndex(regId.index()));
201          case CCRegClass:
202            return RegId(CCRegClass, flattenCCIndex(regId.index()));
203          case MiscRegClass:
204            return RegId(MiscRegClass, flattenMiscIndex(regId.index()));
205          default:
206            break;
207        }
208        return regId;
209    }
210
211    int
212    flattenIntIndex(int reg) const
213    {
214        assert(reg < TotalInstIntRegs);
215        RegIndex flatIndex = intRegMap[reg];
216        assert(flatIndex < NumIntRegs);
217        return flatIndex;
218    }
219
220    int
221    flattenFloatIndex(int reg) const
222    {
223        return reg;
224    }
225
226    int
227    flattenVecIndex(int reg) const
228    {
229        return reg;
230    }
231
232    int
233    flattenVecElemIndex(int reg) const
234    {
235        return reg;
236    }
237
238    // dummy
239    int
240    flattenCCIndex(int reg) const
241    {
242        return reg;
243    }
244
245    int
246    flattenMiscIndex(int reg) const
247    {
248        return reg;
249    }
250
251
252    typedef SparcISAParams Params;
253    const Params *params() const;
254
255    ISA(Params *p);
256};
257}
258
259#endif
260