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 //#include "arch/mips/misc_regfile.hh"
33 #include "base/misc.hh"
34 #include "config/full_system.hh"
35 #include "sim/host.hh"
36 #include "sim/faults.hh"
44 namespace LittleEndianGuest {};
45 using namespace LittleEndianGuest;
53 int DTB_ASN_ASN(uint64_t reg);
54 int ITB_ASN_ASN(uint64_t reg);
61 SyscallReturn(T v, bool s)
76 SyscallReturn& operator=(const SyscallReturn& s) {
82 bool successful() { return success; }
83 uint64_t value() { return retval; }
94 typedef uint32_t MachInst;
95 typedef uint32_t MachInst;
96 typedef uint64_t ExtMachInst;
97 typedef uint8_t RegIndex;
98 // typedef uint64_t Addr;
100 MemoryEnd = 0xffffffffffffffffULL,
104 NumMiscRegs = 258, //account for hi,lo regs
106 MaxRegsOfAnyType = 32,
107 // Static instruction parameters
111 // semantically meaningful register indices
112 ZeroReg = 0, // architecturally meaningful
113 // the rest of these depend on the ABI
114 StackPointerReg = 30,
115 GlobalPointerReg = 29,
116 ProcedureValueReg = 27,
117 ReturnAddressReg = 26,
119 FramePointerReg = 15,
126 SyscallNumReg = ReturnValueReg,
127 SyscallPseudoReturnReg = ArgumentReg4,
128 SyscallSuccessReg = 19,
129 LogVMPageSize = 13, // 8K bytes
130 VMPageSize = (1 << LogVMPageSize),
132 BranchPredAddrShiftAmt = 2, // instructions are 4-byte aligned
140 // These enumerate all the registers for dependence tracking.
141 enum DependenceTags {
142 // 0..31 are the integer regs 0..31
143 // 32..63 are the FP regs 0..31, i.e. use (reg + FP_Base_DepTag)
145 Ctrl_Base_DepTag = 64,
146 Fpcr_DepTag = 64, // floating point control register
148 IPR_Base_DepTag = 66,
152 typedef uint64_t IntReg;
153 typedef IntReg IntRegFile[NumIntRegs];
155 // floating point register file entry type
162 uint64_t q[NumFloatRegs]; // integer qword view
163 double d[NumFloatRegs]; // double-precision floating point view
166 // cop-0/cop-1 system control register file
167 typedef uint64_t MiscReg;
168 //typedef MiscReg MiscRegFile[NumMiscRegs];
172 uint64_t fpcr; // floating point condition codes
173 uint64_t uniq; // process-unique register
174 bool lock_flag; // lock flag for LL/SC
175 Addr lock_addr; // lock address for LL/SC
177 MiscReg miscRegFile[NumMiscRegs];
180 //These functions should be removed once the simplescalar cpu model
185 void copyMiscRegs(ExecContext *xc);
187 MiscReg readReg(int misc_reg)
188 { return miscRegFile[misc_reg]; }
190 MiscReg readRegWithEffect(int misc_reg, Fault &fault, ExecContext *xc)
191 { return miscRegFile[misc_reg];}
193 Fault setReg(int misc_reg, const MiscReg &val)
194 { miscRegFile[misc_reg] = val; return NoFault; }
196 Fault setRegWithEffect(int misc_reg, const MiscReg &val,
198 { miscRegFile[misc_reg] = val; return NoFault; }
204 InternalProcReg ipr[NumInternalProcRegs]; // Internal processor regs
207 MiscReg readIpr(int idx, Fault &fault, ExecContext *xc) { }
209 Fault setIpr(int idx, uint64_t val, ExecContext *xc) { }
211 friend class RegFile;
215 //Coprocessor 0 Registers
216 //Reference MIPS32 Arch. for Programmers, Vol. III, Ch.8
217 //(Register Number-Register Select) Summary of Register
218 //------------------------------------------------------
219 Index = 0, //0-0 Index into the TLB array
221 MVPControl = 1, //0-1 Per-processor register containing global
222 //MIPS® MT configuration data
224 MVPConf0 = 2, //0-2 Per-processor register containing global
225 //MIPS® MT configuration data
227 MVPConf1 = 3, //0-3 Per-processor register containing global
228 //MIPS® MT configuration data
230 Random = 8, //1-0 Randomly generated index into the TLB array
232 VPEControl = 9, //1-1 Per-VPE register containing relatively volatile
233 //thread configuration data
235 VPEConf0 = 10, //1-2 Per-VPE multi-thread configuration
239 VPEConf1 = 11, //1-2 Per-VPE multi-thread configuration
242 YQMask = 12, //Per-VPE register defining which YIELD
243 //qualifier bits may be used without generating
249 EntryLo0 = 16, // Bank 3: 16 - 23
258 EntryLo1 = 24,// Bank 4: 24 - 31
260 Context = 32, // Bank 5: 32 - 39
263 //PageMask = 40, //Bank 6: 40 - 47
266 Wired = 48, //Bank 7:48 - 55
274 HWRena = 56,//Bank 8:56 - 63
276 Count = 64, //Bank 9:64 - 71
278 EntryHi = 72,//Bank 10:72 - 79
280 Compare = 80,//Bank 11:80 - 87
282 Status = 88,//Bank 12:88 - 96 //12-0 Processor status and control
283 IntCtl = 89, //12-1 Interrupt system status and control
284 SRSCtl = 90, //12-2 Shadow register set status and control
285 SRSMap = 91, //12-3 Shadow set IPL mapping
287 Cause = 97,//97-104 //13-0 Cause of last general exception
289 EPC = 105,//105-112 //14-0 Program counter at last exception
291 PRId = 113,//113-120, //15-0 Processor identification and revision
292 EBase = 114, //15-1 Exception vector base register
294 Config = 121,//Bank 16: 121-128
302 LLAddr = 129,//Bank 17: 129-136
304 WatchLo0 = 137,//Bank 18: 137-144
313 WatchHi0 = 145,//Bank 19: 145-152
322 XCContext64 = 153,//Bank 20: 153-160
328 Debug = 177, //Bank 23: 177-184
334 DEPC = 185,//Bank 24: 185-192
336 PerfCnt0 = 193,//Bank 25: 193 - 200
345 ErrCtl = 201, //Bank 26: 201 - 208
347 CacheErr0 = 209, //Bank 27: 209 - 216
352 TagLo0 = 217,//Bank 28: 217 - 224
361 TagHi0 = 233,//Bank 29: 233 - 240
371 ErrorEPC = 249,//Bank 30: 241 - 248
373 DESAVE = 257,//Bank 31: 249-256
381 //Alpha Regs, but here now, for
388 extern const Addr PageShift;
389 extern const Addr PageBytes;
390 extern const Addr PageMask;
391 extern const Addr PageOffset;
395 typedef uint64_t InternalProcReg;
397 #include "arch/mips/isa_fullsys_traits.hh"
401 NumInternalProcRegs = 0
407 NumIntRegs + NumFloatRegs + NumMiscRegs + NumInternalProcRegs
411 TotalDataRegs = NumIntRegs + NumFloatRegs
421 IntRegFile intRegFile; // (signed) integer register file
422 FloatRegFile floatRegFile; // floating point register file
423 MiscRegFile miscRegs; // control register file
426 Addr pc; // program counter
427 Addr npc; // next-cycle program counter
428 Addr nnpc; // next-next-cycle program counter
429 // used to implement branch delay slot
432 MiscReg hi; // MIPS HI Register
433 MiscReg lo; // MIPS LO Register
437 IntReg palregs[NumIntRegs]; // PAL shadow registers
438 InternalProcReg ipr[NumInternalProcRegs]; // internal processor regs
439 int intrflag; // interrupt flag
440 bool pal_shadow; // using pal_shadow registers
441 inline int instAsid() { return MIPS34K::ITB_ASN_ASN(ipr[IPR_ITB_ASN]); }
442 inline int dataAsid() { return MIPS34K::DTB_ASN_ASN(ipr[IPR_DTB_ASN]); }
443 #endif // FULL_SYSTEM
445 //void initCP0Regs();
446 void serialize(std::ostream &os);
447 void unserialize(Checkpoint *cp, const std::string §ion);
449 void createCP0Regs();
453 StaticInstPtr decodeInst(ExtMachInst);
455 // return a no-op instruction... used for instruction fetch faults
456 extern const MachInst NoopMachInst;
460 // An impossible number for instruction annotations
461 ITOUCH_ANNOTE = 0xffffffff,
464 //void getMiscRegIdx(int reg_name,int &idx, int &sel);
466 static inline ExtMachInst
467 makeExtMI(MachInst inst, const uint64_t &pc) {
469 ExtMachInst ext_inst = inst;
471 return ext_inst|=(static_cast<ExtMachInst>(pc & 0x1) << 32);
475 return ExtMachInst(inst);
479 static inline bool isCallerSaveIntegerRegister(unsigned int reg) {
480 panic("register classification not implemented");
481 return (reg >= 1 && reg <= 8 || reg >= 22 && reg <= 25 || reg == 27);
484 static inline bool isCalleeSaveIntegerRegister(unsigned int reg) {
485 panic("register classification not implemented");
486 return (reg >= 9 && reg <= 15);
489 static inline bool isCallerSaveFloatRegister(unsigned int reg) {
490 panic("register classification not implemented");
494 static inline bool isCalleeSaveFloatRegister(unsigned int reg) {
495 panic("register classification not implemented");
499 static inline Addr alignAddress(const Addr &addr,
500 unsigned int nbytes) {
501 return (addr & ~(nbytes - 1));
504 // Instruction address compression hooks
505 static inline Addr realPCToFetchPC(const Addr &addr) {
509 static inline Addr fetchPCToRealPC(const Addr &addr) {
513 // the size of "fetched" instructions (not necessarily the size
514 // of real instructions for PISA)
515 static inline size_t fetchInstSize() {
516 return sizeof(MachInst);
519 static inline MachInst makeRegisterCopy(int dest, int src) {
520 panic("makeRegisterCopy not implemented");
524 static inline void setSyscallReturn(SyscallReturn return_value, RegFile *regs)
526 // check for error condition. SPARC syscall convention is to
527 // indicate success/failure in reg the carry bit of the ccr
528 // and put the return value itself in the standard return value reg ().
529 if (return_value.successful()) {
531 //regs->miscRegFile.ccrFields.iccFields.c = 0;
532 regs->intRegFile[ReturnValueReg] = return_value.value();
534 // got an error, return details
535 //regs->miscRegFile.ccrFields.iccFields.c = 1;
536 regs->intRegFile[ReturnValueReg] = -return_value.value();
540 // Machine operations
542 void saveMachineReg(AnyReg &savereg, const RegFile ®_file,
545 void restoreMachineReg(RegFile ®s, const AnyReg ®,
549 static void serializeSpecialRegs(const Serializable::Proxy &proxy,
550 const RegFile ®s);
552 static void unserializeSpecialRegs(const IniFile *db,
553 const std::string &category,
559 * Function to insure ISA semantics about 0 registers.
560 * @param xc The execution context.
563 void zeroRegisters(XC *xc);
565 const Addr MaxAddr = (Addr)-1;
569 //typedef TheISA::InternalProcReg InternalProcReg;
570 //const int NumInternalProcRegs = TheISA::NumInternalProcRegs;
571 //const int NumInterruptLevels = TheISA::NumInterruptLevels;
573 #include "arch/mips/mips34k.hh"
576 using namespace MipsISA;
578 #endif // __ARCH_MIPS_ISA_TRAITS_HH__