isa_traits.hh revision 1458
19288Sandreas.hansson@arm.com/*
29288Sandreas.hansson@arm.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
39288Sandreas.hansson@arm.com * All rights reserved.
49288Sandreas.hansson@arm.com *
59288Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
69288Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
79288Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
89288Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
99288Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
109288Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
119288Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
129288Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
139288Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
149288Sandreas.hansson@arm.com * this software without specific prior written permission.
159288Sandreas.hansson@arm.com *
169288Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179288Sandreas.hansson@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189288Sandreas.hansson@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199288Sandreas.hansson@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209288Sandreas.hansson@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219288Sandreas.hansson@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229288Sandreas.hansson@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239288Sandreas.hansson@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249288Sandreas.hansson@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259288Sandreas.hansson@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269288Sandreas.hansson@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279288Sandreas.hansson@arm.com */
289288Sandreas.hansson@arm.com
299288Sandreas.hansson@arm.com#ifndef __ARCH_ALPHA_ISA_TRAITS_HH__
309288Sandreas.hansson@arm.com#define __ARCH_ALPHA_ISA_TRAITS_HH__
319288Sandreas.hansson@arm.com
329288Sandreas.hansson@arm.com#include "arch/alpha/faults.hh"
339288Sandreas.hansson@arm.com#include "base/misc.hh"
349288Sandreas.hansson@arm.com#include "sim/host.hh"
359288Sandreas.hansson@arm.com
369288Sandreas.hansson@arm.comclass FastCPU;
379288Sandreas.hansson@arm.comclass FullCPU;
389288Sandreas.hansson@arm.comclass Checkpoint;
399288Sandreas.hansson@arm.com
409288Sandreas.hansson@arm.com#define TARGET_ALPHA
419288Sandreas.hansson@arm.com
428831Smrinmoy.ghosh@arm.comtemplate <class ISA> class StaticInst;
438832SAli.Saidi@ARM.comtemplate <class ISA> class StaticInstPtr;
448832SAli.Saidi@ARM.com
459288Sandreas.hansson@arm.comnamespace EV5 {
468831Smrinmoy.ghosh@arm.comint DTB_ASN_ASN(uint64_t reg);
478831Smrinmoy.ghosh@arm.comint ITB_ASN_ASN(uint64_t reg);
488831Smrinmoy.ghosh@arm.com}
498831Smrinmoy.ghosh@arm.com
508831Smrinmoy.ghosh@arm.comclass AlphaISA
518831Smrinmoy.ghosh@arm.com{
528831Smrinmoy.ghosh@arm.com  public:
538831Smrinmoy.ghosh@arm.com
548831Smrinmoy.ghosh@arm.com    typedef uint32_t MachInst;
558831Smrinmoy.ghosh@arm.com    typedef uint64_t Addr;
569288Sandreas.hansson@arm.com    typedef uint8_t  RegIndex;
578832SAli.Saidi@ARM.com
588832SAli.Saidi@ARM.com    enum {
598831Smrinmoy.ghosh@arm.com        MemoryEnd = 0xffffffffffffffffULL,
608831Smrinmoy.ghosh@arm.com
618832SAli.Saidi@ARM.com        NumIntRegs = 32,
628831Smrinmoy.ghosh@arm.com        NumFloatRegs = 32,
638831Smrinmoy.ghosh@arm.com        NumMiscRegs = 32,
648831Smrinmoy.ghosh@arm.com
658831Smrinmoy.ghosh@arm.com        MaxRegsOfAnyType = 32,
668831Smrinmoy.ghosh@arm.com        // Static instruction parameters
678831Smrinmoy.ghosh@arm.com        MaxInstSrcRegs = 3,
688831Smrinmoy.ghosh@arm.com        MaxInstDestRegs = 2,
698831Smrinmoy.ghosh@arm.com
708831Smrinmoy.ghosh@arm.com        // semantically meaningful register indices
718831Smrinmoy.ghosh@arm.com        ZeroReg = 31,	// architecturally meaningful
728831Smrinmoy.ghosh@arm.com        // the rest of these depend on the ABI
738831Smrinmoy.ghosh@arm.com        StackPointerReg = 30,
748831Smrinmoy.ghosh@arm.com        GlobalPointerReg = 29,
758831Smrinmoy.ghosh@arm.com        ReturnAddressReg = 26,
768831Smrinmoy.ghosh@arm.com        ReturnValueReg = 0,
778831Smrinmoy.ghosh@arm.com        ArgumentReg0 = 16,
78        ArgumentReg1 = 17,
79        ArgumentReg2 = 18,
80        ArgumentReg3 = 19,
81        ArgumentReg4 = 20,
82        ArgumentReg5 = 21,
83
84        LogVMPageSize = 13,	// 8K bytes
85        VMPageSize = (1 << LogVMPageSize),
86
87        BranchPredAddrShiftAmt = 2, // instructions are 4-byte aligned
88
89        WordBytes = 4,
90        HalfwordBytes = 2,
91        ByteBytes = 1,
92        DepNA = 0,
93    };
94
95    // These enumerate all the registers for dependence tracking.
96    enum DependenceTags {
97        // 0..31 are the integer regs 0..31
98        // 32..63 are the FP regs 0..31, i.e. use (reg + FP_Base_DepTag)
99        FP_Base_DepTag = 32,
100        Ctrl_Base_DepTag = 64,
101        Fpcr_DepTag = 64,		// floating point control register
102        Uniq_DepTag = 65,
103        IPR_Base_DepTag = 66
104    };
105
106    typedef uint64_t IntReg;
107    typedef IntReg IntRegFile[NumIntRegs];
108
109    // floating point register file entry type
110    typedef union {
111        uint64_t q;
112        double d;
113    } FloatReg;
114
115    typedef union {
116        uint64_t q[NumFloatRegs];	// integer qword view
117        double d[NumFloatRegs];		// double-precision floating point view
118    } FloatRegFile;
119
120    // control register file contents
121    typedef uint64_t MiscReg;
122    typedef struct {
123        uint64_t	fpcr;		// floating point condition codes
124        uint64_t	uniq;		// process-unique register
125        bool		lock_flag;	// lock flag for LL/SC
126        Addr		lock_addr;	// lock address for LL/SC
127    } MiscRegFile;
128
129static const Addr PageShift = 13;
130static const Addr PageBytes = ULL(1) << PageShift;
131static const Addr PageMask = ~(PageBytes - 1);
132static const Addr PageOffset = PageBytes - 1;
133
134#ifdef FULL_SYSTEM
135
136    typedef uint64_t InternalProcReg;
137
138#include "arch/alpha/isa_fullsys_traits.hh"
139
140#else
141    enum {
142        NumInternalProcRegs = 0
143    };
144#endif
145
146    enum {
147        TotalNumRegs =
148        NumIntRegs + NumFloatRegs + NumMiscRegs + NumInternalProcRegs
149    };
150
151    typedef union {
152        IntReg  intreg;
153        FloatReg   fpreg;
154        MiscReg ctrlreg;
155    } AnyReg;
156
157    struct RegFile {
158        IntRegFile intRegFile;		// (signed) integer register file
159        FloatRegFile floatRegFile;	// floating point register file
160        MiscRegFile miscRegs;		// control register file
161        Addr pc;			// program counter
162        Addr npc;			// next-cycle program counter
163#ifdef FULL_SYSTEM
164        IntReg palregs[NumIntRegs];	// PAL shadow registers
165        InternalProcReg ipr[NumInternalProcRegs]; // internal processor regs
166        int intrflag;			// interrupt flag
167        bool pal_shadow;		// using pal_shadow registers
168        inline int instAsid() { return EV5::ITB_ASN_ASN(ipr[IPR_ITB_ASN]); }
169        inline int dataAsid() { return EV5::DTB_ASN_ASN(ipr[IPR_DTB_ASN]); }
170#endif // FULL_SYSTEM
171
172        void serialize(std::ostream &os);
173        void unserialize(Checkpoint *cp, const std::string &section);
174    };
175
176    static StaticInstPtr<AlphaISA> decodeInst(MachInst);
177
178    // return a no-op instruction... used for instruction fetch faults
179    static const MachInst NoopMachInst;
180
181    enum annotes {
182        ANNOTE_NONE = 0,
183        // An impossible number for instruction annotations
184        ITOUCH_ANNOTE = 0xffffffff,
185    };
186
187    static inline bool isCallerSaveIntegerRegister(unsigned int reg) {
188        panic("register classification not implemented");
189        return (reg >= 1 && reg <= 8 || reg >= 22 && reg <= 25 || reg == 27);
190    }
191
192    static inline bool isCalleeSaveIntegerRegister(unsigned int reg) {
193        panic("register classification not implemented");
194        return (reg >= 9 && reg <= 15);
195    }
196
197    static inline bool isCallerSaveFloatRegister(unsigned int reg) {
198        panic("register classification not implemented");
199        return false;
200    }
201
202    static inline bool isCalleeSaveFloatRegister(unsigned int reg) {
203        panic("register classification not implemented");
204        return false;
205    }
206
207    static inline Addr alignAddress(const Addr &addr,
208                                         unsigned int nbytes) {
209        return (addr & ~(nbytes - 1));
210    }
211
212    // Instruction address compression hooks
213    static inline Addr realPCToFetchPC(const Addr &addr) {
214        return addr;
215    }
216
217    static inline Addr fetchPCToRealPC(const Addr &addr) {
218        return addr;
219    }
220
221    // the size of "fetched" instructions (not necessarily the size
222    // of real instructions for PISA)
223    static inline size_t fetchInstSize() {
224        return sizeof(MachInst);
225    }
226
227    static inline MachInst makeRegisterCopy(int dest, int src) {
228        panic("makeRegisterCopy not implemented");
229        return 0;
230    }
231
232    // Machine operations
233
234    static void saveMachineReg(AnyReg &savereg, const RegFile &reg_file,
235                               int regnum);
236
237    static void restoreMachineReg(RegFile &regs, const AnyReg &reg,
238                                  int regnum);
239
240#if 0
241    static void serializeSpecialRegs(const Serializable::Proxy &proxy,
242                                     const RegFile &regs);
243
244    static void unserializeSpecialRegs(const IniFile *db,
245                                       const std::string &category,
246                                       ConfigNode *node,
247                                       RegFile &regs);
248#endif
249
250    /**
251     * Function to insure ISA semantics about 0 registers.
252     * @param xc The execution context.
253     */
254    template <class XC>
255    static void zeroRegisters(XC *xc);
256};
257
258
259typedef AlphaISA TheISA;
260
261typedef TheISA::MachInst MachInst;
262typedef TheISA::Addr Addr;
263typedef TheISA::RegIndex RegIndex;
264typedef TheISA::IntReg IntReg;
265typedef TheISA::IntRegFile IntRegFile;
266typedef TheISA::FloatReg FloatReg;
267typedef TheISA::FloatRegFile FloatRegFile;
268typedef TheISA::MiscReg MiscReg;
269typedef TheISA::MiscRegFile MiscRegFile;
270typedef TheISA::AnyReg AnyReg;
271typedef TheISA::RegFile RegFile;
272
273const int NumIntRegs   = TheISA::NumIntRegs;
274const int NumFloatRegs = TheISA::NumFloatRegs;
275const int NumMiscRegs  = TheISA::NumMiscRegs;
276const int TotalNumRegs = TheISA::TotalNumRegs;
277const int VMPageSize   = TheISA::VMPageSize;
278const int LogVMPageSize   = TheISA::LogVMPageSize;
279const int ZeroReg = TheISA::ZeroReg;
280const int StackPointerReg = TheISA::StackPointerReg;
281const int GlobalPointerReg = TheISA::GlobalPointerReg;
282const int ReturnAddressReg = TheISA::ReturnAddressReg;
283const int ReturnValueReg = TheISA::ReturnValueReg;
284const int ArgumentReg0 = TheISA::ArgumentReg0;
285const int ArgumentReg1 = TheISA::ArgumentReg1;
286const int BranchPredAddrShiftAmt = TheISA::BranchPredAddrShiftAmt;
287const int MaxAddr = (Addr)-1;
288
289#ifndef FULL_SYSTEM
290class SyscallReturn {
291        public:
292           template <class T>
293           SyscallReturn(T v, bool s)
294           {
295               retval = (uint64_t)v;
296               success = s;
297           }
298
299           template <class T>
300           SyscallReturn(T v)
301           {
302               success = (v >= 0);
303               retval = (uint64_t)v;
304           }
305
306           ~SyscallReturn() {}
307
308           SyscallReturn& operator=(const SyscallReturn& s) {
309               retval = s.retval;
310               success = s.success;
311               return *this;
312           }
313
314           bool successful() { return success; }
315           uint64_t value() { return retval; }
316
317
318       private:
319           uint64_t retval;
320           bool success;
321};
322
323#endif
324
325
326#ifdef FULL_SYSTEM
327typedef TheISA::InternalProcReg InternalProcReg;
328const int NumInternalProcRegs  = TheISA::NumInternalProcRegs;
329const int NumInterruptLevels = TheISA::NumInterruptLevels;
330
331#include "arch/alpha/ev5.hh"
332#endif
333
334#endif // __ARCH_ALPHA_ISA_TRAITS_HH__
335