2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
29 #ifndef __ARCH_MIPS_ISA_TRAITS_HH__
30 #define __ARCH_MIPS_ISA_TRAITS_HH__
32 //This makes sure the big endian versions of certain functions are used.
33 namespace LittleEndianGuest {}
34 using namespace LittleEndianGuest
36 #include "arch/mips/faults.hh"
37 #include "base/misc.hh"
38 #include "sim/host.hh"
46 template <class ISA> class StaticInst;
47 template <class ISA> class StaticInstPtr;
51 // int DTB_ASN_ASN(uint64_t reg);
52 // int ITB_ASN_ASN(uint64_t reg);
59 typedef uint32_t MachInst;
60 typedef uint64_t Addr;
61 typedef uint8_t RegIndex;
65 MemoryEnd = 0xffffffffffffffffULL,
70 MaxRegsOfAnyType = 32,
71 // Static instruction parameters
78 // semantically meaningful register indices
79 ZeroReg = 0, // architecturally meaningful
80 // the rest of these depend on the ABI
82 typedef uint64_t IntReg;
87 //For right now, let's pretend the register file is static
90 IntReg & operator [] (RegIndex index)
92 //Don't allow indexes outside of the 32 registers
98 void inline serialize(std::ostream & os)
100 SERIALIZE_ARRAY(regs, 32);
103 void inline unserialize(Checkpoint &*cp, const std::string §ion)
105 UNSERIALIZE_ARRAY(regs, 32);
111 //By using the largest data type, we ensure everything
112 //is aligned correctly in memory
115 double double rawRegs[16];
116 uint64_t regDump[32];
121 FloatRegFile * parent;
123 QuadRegs(FloatRegFile * p) : parent(p) {;}
124 double double & operator [] (RegIndex index)
126 //Quad floats are index by the single
127 //precision register the start on,
128 //and only 16 should be accessed
129 index = (index >> 2) & 0xF;
130 return parent->rawRegs[index];
136 FloatRegFile * parent;
138 DoubleRegs(FloatRegFile * p) : parent(p) {;}
139 double & operator [] (RegIndex index)
141 //Double floats are index by the single
142 //precision register the start on,
143 //and only 32 should be accessed
144 index = (index >> 1) & 0x1F
145 return ((double [])parent->rawRegs)[index];
151 FloatRegFile * parent;
153 SingleRegs(FloatRegFile * p) : parent(p) {;}
154 double & operator [] (RegFile index)
156 //Only 32 single floats should be accessed
158 return ((float [])parent->rawRegs)[index];
162 void inline serialize(std::ostream & os)
164 SERIALIZE_ARRAY(regDump, 32);
167 void inline unserialize(Checkpoint &* cp, std::string & section)
169 UNSERIALIZE_ARRAY(regDump, 32);
173 DoubleRegs doubleRegs;
174 SingleRegs singleRegs;
175 FloatRegFile() : quadRegs(this), doubleRegs(this), singleRegs(this)
179 // control register file contents
180 typedef uint64_t MiscReg;
181 // The control registers, broken out into fields
187 uint16_t pstate; // Process State Register
190 uint16_t ag:1; // Alternate Globals
191 uint16_t ie:1; // Interrupt enable
192 uint16_t priv:1; // Privelege mode
193 uint16_t am:1; // Address mask
194 uint16_t pef:1; // PSTATE enable floating-point
195 uint16_t red:1; // RED (reset, error, debug) state
196 uint16_t mm:2; // Memory Model
197 uint16_t tle:1; // Trap little-endian
198 uint16_t cle:1; // Current little-endian
201 uint64_t tba; // Trap Base Address
204 uint64_t y; // Y (used in obsolete multiplication)
207 uint64_t value:32; // The actual value stored in y
208 const uint64_t :32; // reserved bits
211 uint8_t pil; // Process Interrupt Register
212 uint8_t cwp; // Current Window Pointer
213 uint16_t tt[MaxTL]; // Trap Type (Type of trap which occured on the previous level)
216 uint8_t ccr; // Condition Code Register
221 uint8_t icc:4; // 32-bit condition codes
224 uint8_t c:1; // Carry
225 uint8_t v:1; // Overflow
227 uint8_t n:1; // Negative
232 uint8_t xcc:4; // 64-bit condition codes
235 uint8_t c:1; // Carry
236 uint8_t v:1; // Overflow
238 uint8_t n:1; // Negative
243 uint8_t asi; // Address Space Identifier
244 uint8_t tl; // Trap Level
245 uint64_t tpc[MaxTL]; // Trap Program Counter (value from previous trap level)
246 uint64_t tnpc[MaxTL]; // Trap Next Program Counter (value from previous trap level)
249 uint64_t tstate[MaxTL]; // Trap State
252 //Values are from previous trap level
253 uint64_t cwp:5; // Current Window Pointer
254 const uint64_t :2; // Reserved bits
255 uint64_t pstate:10; // Process State
256 const uint64_t :6; // Reserved bits
257 uint64_t asi:8; // Address Space Identifier
258 uint64_t ccr:8; // Condition Code Register
259 } tstateFields[MaxTL];
263 uint64_t tick; // Hardware clock-tick counter
266 uint64_t counter:63; // Clock-tick count
267 uint64_t npt:1; // Non-priveleged trap
270 uint8_t cansave; // Savable windows
271 uint8_t canrestore; // Restorable windows
272 uint8_t otherwin; // Other windows
273 uint8_t cleanwin; // Clean windows
276 uint8_t wstate; // Window State
279 uint8_t normal:3; // Bits TT<4:2> are set to on a normal
280 // register window trap
281 uint8_t other:3; // Bits TT<4:2> are set to on an "otherwin"
282 // register window trap
287 uint64_t ver; // Version
290 uint64_t maxwin:5; // Max CWP value
291 const uint64_t :2; // Reserved bits
292 uint64_t maxtl:8; // Maximum trap level
293 const uint64_t :8; // Reserved bits
294 uint64_t mask:8; // Processor mask set revision number
295 uint64_t impl:16; // Implementation identification number
296 uint64_t manuf:16; // Manufacturer code
301 uint64_t fsr; // Floating-Point State Register
306 uint64_t cexc:5; // Current excpetion
309 uint64_t nxc:1; // Inexact
310 uint64_t dzc:1; // Divide by zero
311 uint64_t ufc:1; // Underflow
312 uint64_t ofc:1; // Overflow
313 uint64_t nvc:1; // Invalid operand
318 uint64_t aexc:5; // Accrued exception
321 uint64_t nxc:1; // Inexact
322 uint64_t dzc:1; // Divide by zero
323 uint64_t ufc:1; // Underflow
324 uint64_t ofc:1; // Overflow
325 uint64_t nvc:1; // Invalid operand
328 uint64_t fcc0:2; // Floating-Point condtion codes
329 const uint64_t :1; // Reserved bits
330 uint64_t qne:1; // Deferred trap queue not empty
331 // with no queue, it should read 0
332 uint64_t ftt:3; // Floating-Point trap type
333 uint64_t ver:3; // Version (of the FPU)
334 const uint64_t :2; // Reserved bits
335 uint64_t ns:1; // Nonstandard floating point
338 uint64_t tem:5; // Trap Enable Mask
341 uint64_t nxm:1; // Inexact
342 uint64_t dzm:1; // Divide by zero
343 uint64_t ufm:1; // Underflow
344 uint64_t ofm:1; // Overflow
345 uint64_t nvm:1; // Invalid operand
348 const uint64_t :2; // Reserved bits
349 uint64_t rd:2; // Rounding direction
350 uint64_t fcc1:2; // Floating-Point condition codes
351 uint64_t fcc2:2; // Floating-Point condition codes
352 uint64_t fcc3:2; // Floating-Point condition codes
353 const uint64_t :26; // Reserved bits
358 uint8_t fprs; // Floating-Point Register State
363 fef:1; // FPRS enable floating-Point
367 void serialize(std::ostream & os)
369 SERIALIZE_SCALAR(pstate);
370 SERIAlIZE_SCALAR(tba);
372 SERIALIZE_SCALAR(pil);
373 SERIALIZE_SCALAR(cwp);
374 SERIALIZE_ARRAY(tt, MaxTL);
375 SERIALIZE_SCALAR(ccr);
376 SERIALIZE_SCALAR(asi);
377 SERIALIZE_SCALAR(tl);
378 SERIALIZE_SCALAR(tpc);
379 SERIALIZE_SCALAR(tnpc);
380 SERIALIZE_ARRAY(tstate, MaxTL);
381 SERIALIZE_SCALAR(tick);
382 SERIALIZE_SCALAR(cansave);
383 SERIALIZE_SCALAR(canrestore);
384 SERIALIZE_SCALAR(otherwin);
385 SERIALIZE_SCALAR(cleanwin);
386 SERIALIZE_SCALAR(wstate);
387 SERIALIZE_SCALAR(ver);
388 SERIALIZE_SCALAR(fsr);
389 SERIALIZE_SCALAR(fprs);
392 void unserialize(Checkpoint &* cp, std::string & section)
394 UNSERIALIZE_SCALAR(pstate);
395 UNSERIAlIZE_SCALAR(tba);
396 UNSERIALIZE_SCALAR(y);
397 UNSERIALIZE_SCALAR(pil);
398 UNSERIALIZE_SCALAR(cwp);
399 UNSERIALIZE_ARRAY(tt, MaxTL);
400 UNSERIALIZE_SCALAR(ccr);
401 UNSERIALIZE_SCALAR(asi);
402 UNSERIALIZE_SCALAR(tl);
403 UNSERIALIZE_SCALAR(tpc);
404 UNSERIALIZE_SCALAR(tnpc);
405 UNSERIALIZE_ARRAY(tstate, MaxTL);
406 UNSERIALIZE_SCALAR(tick);
407 UNSERIALIZE_SCALAR(cansave);
408 UNSERIALIZE_SCALAR(canrestore);
409 UNSERIALIZE_SCALAR(otherwin);
410 UNSERIALIZE_SCALAR(cleanwin);
411 UNSERIALIZE_SCALAR(wstate);
412 UNSERIALIZE_SCALAR(ver);
413 UNSERIALIZE_SCALAR(fsr);
414 UNSERIALIZE_SCALAR(fprs);
427 IntRegFile intRegFile; // (signed) integer register file
428 FloatRegFile floatRegFile; // floating point register file
429 MiscRegFile miscRegFile; // control register file
431 Addr pc; // Program Counter
432 Addr npc; // Next Program Counter
433 Addr nnpc; // Next next program Counter
436 void serialize(std::ostream &os);
437 void unserialize(Checkpoint *cp, const std::string §ion);
440 static StaticInstPtr<MipsISA> decodeInst(MachInst);
442 // return a no-op instruction... used for instruction fetch faults
443 static const MachInst NoopMachInst;
445 // Instruction address compression hooks
446 static inline Addr realPCToFetchPC(const Addr &addr)
451 static inline Addr fetchPCToRealPC(const Addr &addr)
456 // the size of "fetched" instructions (not necessarily the size
457 // of real instructions for PISA)
458 static inline size_t fetchInstSize()
460 return sizeof(MachInst);
464 * Function to insure ISA semantics about 0 registers.
465 * @param xc The execution context.
468 static void zeroRegisters(XC *xc);
472 typedef MIPSISA TheISA;
474 typedef TheISA::MachInst MachInst;
475 typedef TheISA::Addr Addr;
476 typedef TheISA::RegIndex RegIndex;
477 typedef TheISA::IntReg IntReg;
478 typedef TheISA::IntRegFile IntRegFile;
479 typedef TheISA::FloatReg FloatReg;
480 typedef TheISA::FloatRegFile FloatRegFile;
481 typedef TheISA::MiscReg MiscReg;
482 typedef TheISA::MiscRegFile MiscRegFile;
483 typedef TheISA::AnyReg AnyReg;
484 typedef TheISA::RegFile RegFile;
486 const int VMPageSize = TheISA::VMPageSize;
487 const int LogVMPageSize = TheISA::LogVMPageSize;
488 const int ZeroReg = TheISA::ZeroReg;
489 const int BranchPredAddrShiftAmt = TheISA::BranchPredAddrShiftAmt;
490 const int MaxAddr = (Addr)-1;
493 class SyscallReturn {
496 SyscallReturn(T v, bool s)
498 retval = (uint64_t)v;
506 retval = (uint64_t)v;
511 SyscallReturn& operator=(const SyscallReturn& s) {
517 bool successful() { return success; }
518 uint64_t value() { return retval; }
531 #include "arch/mips/mips34k.hh"
534 #endif // __ARCH_MIPS_ISA_TRAITS_HH__