Don't use magic numbers.
[gem5.git] / arch / alpha / isa_traits.hh
1 /*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __ISA_TRAITS_HH__
30 #define __ISA_TRAITS_HH__
31
32 #include "arch/alpha/faults.hh"
33 #include "base/misc.hh"
34 #include "sim/host.hh"
35
36 class FastCPU;
37 class FullCPU;
38 class Checkpoint;
39
40 #define TARGET_ALPHA
41
42 template <class ISA> class StaticInst;
43 template <class ISA> class StaticInstPtr;
44
45 class AlphaISA
46 {
47 public:
48
49 typedef uint32_t MachInst;
50 typedef uint64_t Addr;
51 typedef uint8_t RegIndex;
52
53 enum {
54 MemoryEnd = 0xffffffffffffffffULL,
55
56 NumIntRegs = 32,
57 NumFloatRegs = 32,
58 NumMiscRegs = 32,
59
60 MaxRegsOfAnyType = 32,
61 // Static instruction parameters
62 MaxInstSrcRegs = 3,
63 MaxInstDestRegs = 2,
64
65 // semantically meaningful register indices
66 ZeroReg = 31, // architecturally meaningful
67 // the rest of these depend on the ABI
68 StackPointerReg = 30,
69 GlobalPointerReg = 29,
70 ReturnAddressReg = 26,
71 ReturnValueReg = 0,
72 ArgumentReg0 = 16,
73 ArgumentReg1 = 17,
74 ArgumentReg2 = 18,
75 ArgumentReg3 = 19,
76 ArgumentReg4 = 20,
77 ArgumentReg5 = 21,
78
79 LogVMPageSize = 13, // 8K bytes
80 VMPageSize = (1 << LogVMPageSize),
81
82 BranchPredAddrShiftAmt = 2, // instructions are 4-byte aligned
83
84 WordBytes = 4,
85 HalfwordBytes = 2,
86 ByteBytes = 1,
87 DepNA = 0,
88 };
89
90 // These enumerate all the registers for dependence tracking.
91 enum DependenceTags {
92 // 0..31 are the integer regs 0..31
93 // 32..63 are the FP regs 0..31, i.e. use (reg + FP_Base_DepTag)
94 FP_Base_DepTag = 32,
95 Ctrl_Base_DepTag = 64,
96 Fpcr_DepTag = 64, // floating point control register
97 Uniq_DepTag = 65,
98 IPR_Base_DepTag = 66
99 };
100
101 typedef uint64_t IntReg;
102 typedef IntReg IntRegFile[NumIntRegs];
103
104 // floating point register file entry type
105 typedef union {
106 uint64_t q;
107 double d;
108 } FloatReg;
109
110 typedef union {
111 uint64_t q[NumFloatRegs]; // integer qword view
112 double d[NumFloatRegs]; // double-precision floating point view
113 } FloatRegFile;
114
115 // control register file contents
116 typedef uint64_t MiscReg;
117 typedef struct {
118 uint64_t fpcr; // floating point condition codes
119 uint64_t uniq; // process-unique register
120 bool lock_flag; // lock flag for LL/SC
121 Addr lock_addr; // lock address for LL/SC
122 } MiscRegFile;
123
124 static const Addr PageShift = 13;
125 static const Addr PageBytes = ULL(1) << PageShift;
126 static const Addr PageMask = ~(PageBytes - 1);
127 static const Addr PageOffset = PageBytes - 1;
128
129 #ifdef FULL_SYSTEM
130
131 typedef uint64_t InternalProcReg;
132
133 #include "arch/alpha/isa_fullsys_traits.hh"
134
135 #else
136 enum {
137 NumInternalProcRegs = 0
138 };
139 #endif
140
141 enum {
142 TotalNumRegs =
143 NumIntRegs + NumFloatRegs + NumMiscRegs + NumInternalProcRegs
144 };
145
146 typedef union {
147 IntReg intreg;
148 FloatReg fpreg;
149 MiscReg ctrlreg;
150 } AnyReg;
151
152 struct RegFile {
153 IntRegFile intRegFile; // (signed) integer register file
154 FloatRegFile floatRegFile; // floating point register file
155 MiscRegFile miscRegs; // control register file
156 Addr pc; // program counter
157 Addr npc; // next-cycle program counter
158 #ifdef FULL_SYSTEM
159 IntReg palregs[NumIntRegs]; // PAL shadow registers
160 InternalProcReg ipr[NumInternalProcRegs]; // internal processor regs
161 int intrflag; // interrupt flag
162 bool pal_shadow; // using pal_shadow registers
163 #endif // FULL_SYSTEM
164
165 void serialize(std::ostream &os);
166 void unserialize(Checkpoint *cp, const std::string &section);
167 };
168
169 static StaticInstPtr<AlphaISA> decodeInst(MachInst);
170
171 enum annotes {
172 ANNOTE_NONE = 0,
173 // An impossible number for instruction annotations
174 ITOUCH_ANNOTE = 0xffffffff,
175 };
176
177 static inline bool isCallerSaveIntegerRegister(unsigned int reg) {
178 panic("register classification not implemented");
179 return (reg >= 1 && reg <= 8 || reg >= 22 && reg <= 25 || reg == 27);
180 }
181
182 static inline bool isCalleeSaveIntegerRegister(unsigned int reg) {
183 panic("register classification not implemented");
184 return (reg >= 9 && reg <= 15);
185 }
186
187 static inline bool isCallerSaveFloatRegister(unsigned int reg) {
188 panic("register classification not implemented");
189 return false;
190 }
191
192 static inline bool isCalleeSaveFloatRegister(unsigned int reg) {
193 panic("register classification not implemented");
194 return false;
195 }
196
197 static inline Addr alignAddress(const Addr &addr,
198 unsigned int nbytes) {
199 return (addr & ~(nbytes - 1));
200 }
201
202 // Instruction address compression hooks
203 static inline Addr realPCToFetchPC(const Addr &addr) {
204 return addr;
205 }
206
207 static inline Addr fetchPCToRealPC(const Addr &addr) {
208 return addr;
209 }
210
211 // the size of "fetched" instructions (not necessarily the size
212 // of real instructions for PISA)
213 static inline size_t fetchInstSize() {
214 return sizeof(MachInst);
215 }
216
217 static inline MachInst makeRegisterCopy(int dest, int src) {
218 panic("makeRegisterCopy not implemented");
219 return 0;
220 }
221
222 // Machine operations
223
224 static void saveMachineReg(AnyReg &savereg, const RegFile &reg_file,
225 int regnum);
226
227 static void restoreMachineReg(RegFile &regs, const AnyReg &reg,
228 int regnum);
229
230 #if 0
231 static void serializeSpecialRegs(const Serializable::Proxy &proxy,
232 const RegFile &regs);
233
234 static void unserializeSpecialRegs(const IniFile *db,
235 const std::string &category,
236 ConfigNode *node,
237 RegFile &regs);
238 #endif
239
240 /**
241 * Function to insure ISA semantics about 0 registers.
242 * @param xc The execution context.
243 */
244 template <class XC>
245 static void zeroRegisters(XC *xc);
246 };
247
248
249 typedef AlphaISA TheISA;
250
251 typedef TheISA::MachInst MachInst;
252 typedef TheISA::Addr Addr;
253 typedef TheISA::RegIndex RegIndex;
254 typedef TheISA::IntReg IntReg;
255 typedef TheISA::IntRegFile IntRegFile;
256 typedef TheISA::FloatReg FloatReg;
257 typedef TheISA::FloatRegFile FloatRegFile;
258 typedef TheISA::MiscReg MiscReg;
259 typedef TheISA::MiscRegFile MiscRegFile;
260 typedef TheISA::AnyReg AnyReg;
261 typedef TheISA::RegFile RegFile;
262
263 const int NumIntRegs = TheISA::NumIntRegs;
264 const int NumFloatRegs = TheISA::NumFloatRegs;
265 const int NumMiscRegs = TheISA::NumMiscRegs;
266 const int TotalNumRegs = TheISA::TotalNumRegs;
267 const int VMPageSize = TheISA::VMPageSize;
268 const int LogVMPageSize = TheISA::LogVMPageSize;
269 const int ZeroReg = TheISA::ZeroReg;
270 const int StackPointerReg = TheISA::StackPointerReg;
271 const int GlobalPointerReg = TheISA::GlobalPointerReg;
272 const int ReturnAddressReg = TheISA::ReturnAddressReg;
273 const int ReturnValueReg = TheISA::ReturnValueReg;
274 const int ArgumentReg0 = TheISA::ArgumentReg0;
275 const int ArgumentReg1 = TheISA::ArgumentReg1;
276 const int BranchPredAddrShiftAmt = TheISA::BranchPredAddrShiftAmt;
277 const int MaxAddr = (Addr)-1;
278
279 #ifdef FULL_SYSTEM
280 typedef TheISA::InternalProcReg InternalProcReg;
281 const int NumInternalProcRegs = TheISA::NumInternalProcRegs;
282 const int NumInterruptLevels = TheISA::NumInterruptLevels;
283
284 // more stuff that should be imported here, but I'm too tired to do it
285 // right now...
286 #include "arch/alpha/ev5.hh"
287 #endif
288
289 #endif // __ALPHA_ISA_H__