isa_traits.hh revision 2472
12SN/A/* 21762SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 292665Ssaidi@eecs.umich.edu#ifndef __ARCH_MIPS_ISA_TRAITS_HH__ 302SN/A#define __ARCH_MIPS_ISA_TRAITS_HH__ 312SN/A 324997Sgblack@eecs.umich.edu//#include "arch/mips/misc_regfile.hh" 331110SN/A#include "base/misc.hh" 344997Sgblack@eecs.umich.edu#include "config/full_system.hh" 352680Sktlim@umich.edu#include "sim/host.hh" 362196SN/A#include "sim/faults.hh" 372196SN/A 384997Sgblack@eecs.umich.edu#include <vector> 392800Ssaidi@eecs.umich.edu 402800Ssaidi@eecs.umich.educlass FastCPU; 412289SN/Aclass FullCPU; 422SN/Aclass Checkpoint; 435569Snate@binkert.orgclass ExecContext; 442167SN/A 452203SN/Anamespace LittleEndianGuest {}; 462203SN/Ausing namespace LittleEndianGuest; 472222SN/A 482166SN/A#define TARGET_MIPS 492203SN/A 502203SN/Aclass StaticInst; 512222SN/Aclass StaticInstPtr; 522166SN/A 532147SN/Anamespace MIPS34K { 542147SN/Aint DTB_ASN_ASN(uint64_t reg); 552222SN/Aint ITB_ASN_ASN(uint64_t reg); 562147SN/A}; 572147SN/A 582147SN/A#if !FULL_SYSTEM 592222SN/Aclass SyscallReturn { 602147SN/A public: 612147SN/A template <class T> 622147SN/A SyscallReturn(T v, bool s) 632222SN/A { 642147SN/A retval = (uint64_t)v; 652147SN/A success = s; 662147SN/A } 672222SN/A 682147SN/A template <class T> 692147SN/A SyscallReturn(T v) 702147SN/A { 712222SN/A success = (v >= 0); 722147SN/A retval = (uint64_t)v; 732147SN/A } 742147SN/A 752222SN/A ~SyscallReturn() {} 762147SN/A 772147SN/A SyscallReturn& operator=(const SyscallReturn& s) { 782147SN/A retval = s.retval; 792222SN/A success = s.success; 802147SN/A return *this; 812289SN/A } 822289SN/A 832289SN/A bool successful() { return success; } 842289SN/A uint64_t value() { return retval; } 852147SN/A 862147SN/A 872222SN/A private: 882147SN/A uint64_t retval; 892147SN/A bool success; 902147SN/A}; 912222SN/A#endif 922147SN/A 932147SN/Anamespace MipsISA 942147SN/A{ 952222SN/A typedef uint32_t MachInst; 962147SN/A typedef uint32_t MachInst; 972147SN/A typedef uint64_t ExtMachInst; 982147SN/A typedef uint8_t RegIndex; 992222SN/A// typedef uint64_t Addr; 1002147SN/A 1012147SN/A // Constants Related to the number of registers 1022147SN/A 1032222SN/A const int NumIntArchRegs = 32; 1042147SN/A const int NumPALShadowRegs = 8; 1052147SN/A const int NumFloatArchRegs = 32; 1062147SN/A // @todo: Figure out what this number really should be. 1072222SN/A const int NumMiscArchRegs = 32; 1082147SN/A 1092174SN/A const int NumIntRegs = NumIntArchRegs + NumPALShadowRegs; 1102174SN/A const int NumFloatRegs = NumFloatArchRegs; 1115569Snate@binkert.org const int NumMiscRegs = NumMiscArchRegs; 1125569Snate@binkert.org 1132174SN/A const int TotalNumRegs = NumIntRegs + NumFloatRegs + 1142680Sktlim@umich.edu NumMiscRegs + 0/*NumInternalProcRegs*/; 1152222SN/A 1162174SN/A const int TotalDataRegs = NumIntRegs + NumFloatRegs; 1172196SN/A 1183521Sgblack@eecs.umich.edu // Static instruction parameters 1195568Snate@binkert.org const int MaxInstSrcRegs = 3; 1202196SN/A const int MaxInstDestRegs = 2; 1212201SN/A 1222196SN/A // semantically meaningful register indices 1235568Snate@binkert.org const int ZeroReg = 0; 1245568Snate@binkert.org const int AssemblerReg = 1; 1252196SN/A const int ReturnValueReg1 = 2; 1262196SN/A const int ReturnValueReg2 = 3; 1275568Snate@binkert.org const int ArgumentReg0 = 4; 1282680Sktlim@umich.edu const int ArgumentReg1 = 5; 1292174SN/A const int ArgumentReg2 = 6; 1302174SN/A const int ArgumentReg3 = 7; 1315569Snate@binkert.org const int KernelReg0 = 26; 1325569Snate@binkert.org const int KernelReg1 = 27; 1332201SN/A const int GlobalPointerReg = 28; 1342680Sktlim@umich.edu const int StackPointerReg = 29; 1352201SN/A const int FramePointerReg = 30; 1362201SN/A const int ReturnAddressReg = 31; 1372201SN/A 1385569Snate@binkert.org const int SyscallNumReg = ReturnValueReg1; 1395569Snate@binkert.org const int SyscallPseudoReturnReg = ArgumentReg3; 1402289SN/A const int SyscallSuccessReg = 19; 1412289SN/A 1422289SN/A const int LogVMPageSize = 13; // 8K bytes 1432289SN/A const int VMPageSize = (1 << LogVMPageSize); 1442289SN/A 1452289SN/A const int BranchPredAddrShiftAmt = 2; // instructions are 4-byte aligned 1465569Snate@binkert.org 1475569Snate@binkert.org const int WordBytes = 4; 1482289SN/A const int HalfwordBytes = 2; 1495568Snate@binkert.org const int ByteBytes = 1; 1502289SN/A 1512289SN/A 1525568Snate@binkert.org // These enumerate all the registers for dependence tracking. 1535569Snate@binkert.org enum DependenceTags { 1545569Snate@binkert.org // 0..31 are the integer regs 0..31 1555569Snate@binkert.org // 32..63 are the FP regs 0..31, i.e. use (reg + FP_Base_DepTag) 1562289SN/A FP_Base_DepTag = 32, 1572289SN/A Ctrl_Base_DepTag = 64, 1585568Snate@binkert.org Fpcr_DepTag = 64, // floating point control register 1595568Snate@binkert.org Uniq_DepTag = 65, 1602289SN/A IPR_Base_DepTag = 66, 1612289SN/A MiscReg_DepTag = 67 1622680Sktlim@umich.edu }; 1632289SN/A 1642289SN/A typedef uint64_t IntReg; 1655569Snate@binkert.org typedef IntReg IntRegFile[NumIntRegs]; 1665569Snate@binkert.org 1672289SN/A/* floating point register file entry type 1682680Sktlim@umich.edu typedef union { 1695568Snate@binkert.org uint64_t q; 1705568Snate@binkert.org double d; 1715569Snate@binkert.org } FloatReg;*/ 1722289SN/A 1732289SN/A typedef double FloatReg; 1742680Sktlim@umich.edu typedef uint64_t FloatRegBits; 1752289SN/A 1762289SN/A/*typedef union { 1774997Sgblack@eecs.umich.edu uint64_t q[NumFloatRegs]; // integer qword view 1784997Sgblack@eecs.umich.edu double d[NumFloatRegs]; // double-precision floating point view 1795569Snate@binkert.org } FloatRegFile;*/ 1805569Snate@binkert.org 1814997Sgblack@eecs.umich.edu class FloatRegFile 1824997Sgblack@eecs.umich.edu { 1835184Sgblack@eecs.umich.edu protected: 1845184Sgblack@eecs.umich.edu 1855569Snate@binkert.org FloatRegBits q[NumFloatRegs]; // integer qword view 1864997Sgblack@eecs.umich.edu double d[NumFloatRegs]; // double-precision floating point view 1874997Sgblack@eecs.umich.edu 1884997Sgblack@eecs.umich.edu public: 1895004Sgblack@eecs.umich.edu 1904997Sgblack@eecs.umich.edu FloatReg readReg(int floatReg) 1914997Sgblack@eecs.umich.edu { 1924997Sgblack@eecs.umich.edu return d[floatReg]; 1935569Snate@binkert.org } 1945569Snate@binkert.org 1954997Sgblack@eecs.umich.edu FloatReg readReg(int floatReg, int width) 1964997Sgblack@eecs.umich.edu { 1975184Sgblack@eecs.umich.edu return readReg(floatReg); 1985184Sgblack@eecs.umich.edu } 1995569Snate@binkert.org 2004997Sgblack@eecs.umich.edu FloatRegBits readRegBits(int floatReg) 2015184Sgblack@eecs.umich.edu { 2024997Sgblack@eecs.umich.edu return q[floatReg]; 2035569Snate@binkert.org } 2044997Sgblack@eecs.umich.edu 2054997Sgblack@eecs.umich.edu FloatRegBits readRegBits(int floatReg, int width) 2065004Sgblack@eecs.umich.edu { 2074997Sgblack@eecs.umich.edu return readRegBits(floatReg); 2084997Sgblack@eecs.umich.edu } 2094997Sgblack@eecs.umich.edu 2102174SN/A Fault setReg(int floatReg, const FloatReg &val) 2112174SN/A { 2122167SN/A d[floatReg] = val; 2132167SN/A return NoFault; 214 } 215 216 Fault setReg(int floatReg, const FloatReg &val, int width) 217 { 218 return setReg(floatReg, val); 219 } 220 221 Fault setRegBits(int floatReg, const FloatRegBits &val) 222 { 223 q[floatReg] = val; 224 return NoFault; 225 } 226 227 Fault setRegBits(int floatReg, const FloatRegBits &val, int width) 228 { 229 return setRegBits(floatReg, val); 230 } 231 232 void serialize(std::ostream &os); 233 234 void unserialize(Checkpoint *cp, const std::string §ion); 235 236 }; 237 238 void copyRegs(ExecContext *src, ExecContext *dest); 239 240 // cop-0/cop-1 system control register file 241 typedef uint64_t MiscReg; 242//typedef MiscReg MiscRegFile[NumMiscRegs]; 243 class MiscRegFile { 244 245 protected: 246 uint64_t fpcr; // floating point condition codes 247 uint64_t uniq; // process-unique register 248 bool lock_flag; // lock flag for LL/SC 249 Addr lock_addr; // lock address for LL/SC 250 251 MiscReg miscRegFile[NumMiscRegs]; 252 253 public: 254 //These functions should be removed once the simplescalar cpu model 255 //has been replaced. 256 int getInstAsid(); 257 int getDataAsid(); 258 259 void copyMiscRegs(ExecContext *xc); 260 261 MiscReg readReg(int misc_reg) 262 { return miscRegFile[misc_reg]; } 263 264 MiscReg readRegWithEffect(int misc_reg, Fault &fault, ExecContext *xc) 265 { return miscRegFile[misc_reg];} 266 267 Fault setReg(int misc_reg, const MiscReg &val) 268 { miscRegFile[misc_reg] = val; return NoFault; } 269 270 Fault setRegWithEffect(int misc_reg, const MiscReg &val, 271 ExecContext *xc) 272 { miscRegFile[misc_reg] = val; return NoFault; } 273 274#if FULL_SYSTEM 275 void clearIprs() { } 276 277 protected: 278 InternalProcReg ipr[NumInternalProcRegs]; // Internal processor regs 279 280 private: 281 MiscReg readIpr(int idx, Fault &fault, ExecContext *xc) { } 282 283 Fault setIpr(int idx, uint64_t val, ExecContext *xc) { } 284#endif 285 friend class RegFile; 286 }; 287 288 enum MiscRegTags { 289 //Coprocessor 0 Registers 290 //Reference MIPS32 Arch. for Programmers, Vol. III, Ch.8 291 //(Register Number-Register Select) Summary of Register 292 //------------------------------------------------------ 293 Index = 0, //0-0 Index into the TLB array 294 295 MVPControl = 1, //0-1 Per-processor register containing global 296 //MIPS� MT configuration data 297 298 MVPConf0 = 2, //0-2 Per-processor register containing global 299 //MIPS� MT configuration data 300 301 MVPConf1 = 3, //0-3 Per-processor register containing global 302 //MIPS� MT configuration data 303 304 Random = 8, //1-0 Randomly generated index into the TLB array 305 306 VPEControl = 9, //1-1 Per-VPE register containing relatively volatile 307 //thread configuration data 308 309 VPEConf0 = 10, //1-2 Per-VPE multi-thread configuration 310 //information 311 312 313 VPEConf1 = 11, //1-2 Per-VPE multi-thread configuration 314 //information 315 316 YQMask = 12, //Per-VPE register defining which YIELD 317 //qualifier bits may be used without generating 318 //an exception 319 320 VPESchedule = 13, 321 VPEScheFBack = 14, 322 VPEOpt = 15, 323 EntryLo0 = 16, // Bank 3: 16 - 23 324 TCStatus = 17, 325 TCBind = 18, 326 TCRestart = 19, 327 TCHalt = 20, 328 TCContext = 21, 329 TCSchedule = 22, 330 TCScheFBack = 23, 331 332 EntryLo1 = 24,// Bank 4: 24 - 31 333 334 Context = 32, // Bank 5: 32 - 39 335 ContextConfig = 33, 336 337 //PageMask = 40, //Bank 6: 40 - 47 338 PageGrain = 41, 339 340 Wired = 48, //Bank 7:48 - 55 341 SRSConf0 = 49, 342 SRSConf1 = 50, 343 SRSConf2 = 51, 344 SRSConf3 = 52, 345 SRSConf4 = 53, 346 BadVAddr = 54, 347 348 HWRena = 56,//Bank 8:56 - 63 349 350 Count = 64, //Bank 9:64 - 71 351 352 EntryHi = 72,//Bank 10:72 - 79 353 354 Compare = 80,//Bank 11:80 - 87 355 356 Status = 88,//Bank 12:88 - 96 //12-0 Processor status and control 357 IntCtl = 89, //12-1 Interrupt system status and control 358 SRSCtl = 90, //12-2 Shadow register set status and control 359 SRSMap = 91, //12-3 Shadow set IPL mapping 360 361 Cause = 97,//97-104 //13-0 Cause of last general exception 362 363 EPC = 105,//105-112 //14-0 Program counter at last exception 364 365 PRId = 113,//113-120, //15-0 Processor identification and revision 366 EBase = 114, //15-1 Exception vector base register 367 368 Config = 121,//Bank 16: 121-128 369 Config1 = 122, 370 Config2 = 123, 371 Config3 = 124, 372 Config6 = 127, 373 Config7 = 128, 374 375 376 LLAddr = 129,//Bank 17: 129-136 377 378 WatchLo0 = 137,//Bank 18: 137-144 379 WatchLo1 = 138, 380 WatchLo2 = 139, 381 WatchLo3 = 140, 382 WatchLo4 = 141, 383 WatchLo5 = 142, 384 WatchLo6 = 143, 385 WatchLo7 = 144, 386 387 WatchHi0 = 145,//Bank 19: 145-152 388 WatchHi1 = 146, 389 WatchHi2 = 147, 390 WatchHi3 = 148, 391 WatchHi4 = 149, 392 WatchHi5 = 150, 393 WatchHi6 = 151, 394 WatchHi7 = 152, 395 396 XCContext64 = 153,//Bank 20: 153-160 397 398 //Bank 21: 161-168 399 400 //Bank 22: 169-176 401 402 Debug = 177, //Bank 23: 177-184 403 TraceControl1 = 178, 404 TraceControl2 = 179, 405 UserTraceData = 180, 406 TraceBPC = 181, 407 408 DEPC = 185,//Bank 24: 185-192 409 410 PerfCnt0 = 193,//Bank 25: 193 - 200 411 PerfCnt1 = 194, 412 PerfCnt2 = 195, 413 PerfCnt3 = 196, 414 PerfCnt4 = 197, 415 PerfCnt5 = 198, 416 PerfCnt6 = 199, 417 PerfCnt7 = 200, 418 419 ErrCtl = 201, //Bank 26: 201 - 208 420 421 CacheErr0 = 209, //Bank 27: 209 - 216 422 CacheErr1 = 210, 423 CacheErr2 = 211, 424 CacheErr3 = 212, 425 426 TagLo0 = 217,//Bank 28: 217 - 224 427 DataLo1 = 218, 428 TagLo2 = 219, 429 DataLo3 = 220, 430 TagLo4 = 221, 431 DataLo5 = 222, 432 TagLo6 = 223, 433 DataLo7 = 234, 434 435 TagHi0 = 233,//Bank 29: 233 - 240 436 DataHi1 = 234, 437 TagHi2 = 235, 438 DataHi3 = 236, 439 TagHi4 = 237, 440 DataHi5 = 238, 441 TagHi6 = 239, 442 DataHi7 = 240, 443 444 445 ErrorEPC = 249,//Bank 30: 241 - 248 446 447 DESAVE = 257,//Bank 31: 249-256 448 449 //More Misc. Regs 450 Hi, 451 Lo, 452 FCSR, 453 FPCR, 454 455 //Alpha Regs, but here now, for 456 //compiling sake 457 UNIQ, 458 LockAddr, 459 LockFlag 460 }; 461 462extern const Addr PageShift; 463extern const Addr PageBytes; 464extern const Addr PageMask; 465extern const Addr PageOffset; 466 467#if FULL_SYSTEM 468 469 typedef uint64_t InternalProcReg; 470 471#include "arch/mips/isa_fullsys_traits.hh" 472 473#else 474 enum { 475 NumInternalProcRegs = 0 476 }; 477#endif 478 479 typedef union { 480 IntReg intreg; 481 FloatReg fpreg; 482 MiscReg ctrlreg; 483 } AnyReg; 484 485 struct RegFile { 486 IntRegFile intRegFile; // (signed) integer register file 487 FloatRegFile floatRegFile; // floating point register file 488 MiscRegFile miscRegs; // control register file 489 490 491 Addr pc; // program counter 492 Addr npc; // next-cycle program counter 493 Addr nnpc; // next-next-cycle program counter 494 // used to implement branch delay slot 495 // not real register 496 497 MiscReg hi; // MIPS HI Register 498 MiscReg lo; // MIPS LO Register 499 500 501#if FULL_SYSTEM 502 IntReg palregs[NumIntRegs]; // PAL shadow registers 503 InternalProcReg ipr[NumInternalProcRegs]; // internal processor regs 504 int intrflag; // interrupt flag 505 bool pal_shadow; // using pal_shadow registers 506 inline int instAsid() { return MIPS34K::ITB_ASN_ASN(ipr[IPR_ITB_ASN]); } 507 inline int dataAsid() { return MIPS34K::DTB_ASN_ASN(ipr[IPR_DTB_ASN]); } 508#endif // FULL_SYSTEM 509 510 //void initCP0Regs(); 511 void serialize(std::ostream &os); 512 void unserialize(Checkpoint *cp, const std::string §ion); 513 514 void createCP0Regs(); 515 void coldReset(); 516 }; 517 518 StaticInstPtr decodeInst(ExtMachInst); 519 520 // return a no-op instruction... used for instruction fetch faults 521 extern const MachInst NoopMachInst; 522 523 enum annotes { 524 ANNOTE_NONE = 0, 525 // An impossible number for instruction annotations 526 ITOUCH_ANNOTE = 0xffffffff, 527 }; 528 529//void getMiscRegIdx(int reg_name,int &idx, int &sel); 530 531 static inline ExtMachInst 532 makeExtMI(MachInst inst, const uint64_t &pc) { 533#if FULL_SYSTEM 534 ExtMachInst ext_inst = inst; 535 if (pc && 0x1) 536 return ext_inst|=(static_cast<ExtMachInst>(pc & 0x1) << 32); 537 else 538 return ext_inst; 539#else 540 return ExtMachInst(inst); 541#endif 542 } 543 544 static inline bool isCallerSaveIntegerRegister(unsigned int reg) { 545 panic("register classification not implemented"); 546 return (reg >= 1 && reg <= 8 || reg >= 22 && reg <= 25 || reg == 27); 547 } 548 549 static inline bool isCalleeSaveIntegerRegister(unsigned int reg) { 550 panic("register classification not implemented"); 551 return (reg >= 9 && reg <= 15); 552 } 553 554 static inline bool isCallerSaveFloatRegister(unsigned int reg) { 555 panic("register classification not implemented"); 556 return false; 557 } 558 559 static inline bool isCalleeSaveFloatRegister(unsigned int reg) { 560 panic("register classification not implemented"); 561 return false; 562 } 563 564 static inline Addr alignAddress(const Addr &addr, 565 unsigned int nbytes) { 566 return (addr & ~(nbytes - 1)); 567 } 568 569 // Instruction address compression hooks 570 static inline Addr realPCToFetchPC(const Addr &addr) { 571 return addr; 572 } 573 574 static inline Addr fetchPCToRealPC(const Addr &addr) { 575 return addr; 576 } 577 578 // the size of "fetched" instructions (not necessarily the size 579 // of real instructions for PISA) 580 static inline size_t fetchInstSize() { 581 return sizeof(MachInst); 582 } 583 584 static inline MachInst makeRegisterCopy(int dest, int src) { 585 panic("makeRegisterCopy not implemented"); 586 return 0; 587 } 588 589 static inline void setSyscallReturn(SyscallReturn return_value, RegFile *regs) 590 { 591 panic("Returning from syscall\n"); 592 } 593 594 // Machine operations 595 596 void saveMachineReg(AnyReg &savereg, const RegFile ®_file, 597 int regnum); 598 599 void restoreMachineReg(RegFile ®s, const AnyReg ®, 600 int regnum); 601 602#if 0 603 static void serializeSpecialRegs(const Serializable::Proxy &proxy, 604 const RegFile ®s); 605 606 static void unserializeSpecialRegs(const IniFile *db, 607 const std::string &category, 608 ConfigNode *node, 609 RegFile ®s); 610#endif 611 612 /** 613 * Function to insure ISA semantics about 0 registers. 614 * @param xc The execution context. 615 */ 616 template <class XC> 617 void zeroRegisters(XC *xc); 618 619 const Addr MaxAddr = (Addr)-1; 620}; 621 622#if FULL_SYSTEM 623//typedef TheISA::InternalProcReg InternalProcReg; 624//const int NumInternalProcRegs = TheISA::NumInternalProcRegs; 625//const int NumInterruptLevels = TheISA::NumInterruptLevels; 626 627#include "arch/mips/mips34k.hh" 628#endif 629 630using namespace MipsISA; 631 632#endif // __ARCH_MIPS_ISA_TRAITS_HH__ 633