regfile.hh revision 2665
11689SN/A/* 21689SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 292665Ssaidi@eecs.umich.edu * Gabe Black 301689SN/A */ 311689SN/A 321755SN/A#ifndef __CPU_O3_CPU_REGFILE_HH__ 331755SN/A#define __CPU_O3_CPU_REGFILE_HH__ 341060SN/A 351060SN/A// @todo: Destructor 361060SN/A 372165SN/A#include "arch/isa_traits.hh" 382170SN/A#include "arch/faults.hh" 391681SN/A#include "base/trace.hh" 401858SN/A#include "config/full_system.hh" 411717SN/A#include "cpu/o3/comm.hh" 421060SN/A 431858SN/A#if FULL_SYSTEM 441681SN/A#include "kern/kernel_stats.hh" 451681SN/A 461681SN/A#endif 471063SN/A 481060SN/A// This really only depends on the ISA, and not the Impl. It might be nicer 491060SN/A// to see if I can make it depend on nothing... 501060SN/A// Things that are in the ifdef FULL_SYSTEM are pretty dependent on the ISA, 511060SN/A// and should go in the AlphaFullCPU. 521060SN/A 531061SN/Atemplate <class Impl> 541060SN/Aclass PhysRegFile 551060SN/A{ 562107SN/A protected: 572107SN/A typedef TheISA::IntReg IntReg; 582107SN/A typedef TheISA::FloatReg FloatReg; 592107SN/A typedef TheISA::MiscRegFile MiscRegFile; 602159SN/A typedef TheISA::MiscReg MiscReg; 612159SN/A 621060SN/A //Note that most of the definitions of the IntReg, FloatReg, etc. exist 631061SN/A //within the Impl/ISA class and not within this PhysRegFile class. 641060SN/A 651060SN/A //Will need some way to allow stuff like swap_palshadow to access the 661060SN/A //correct registers. Might require code changes to swap_palshadow and 671060SN/A //other execution contexts. 681060SN/A 691060SN/A //Will make these registers public for now, but they probably should 701060SN/A //be private eventually with some accessor functions. 711060SN/A public: 721681SN/A typedef typename Impl::FullCPU FullCPU; 731060SN/A 741060SN/A PhysRegFile(unsigned _numPhysicalIntRegs, 751060SN/A unsigned _numPhysicalFloatRegs); 761060SN/A 771060SN/A //Everything below should be pretty well identical to the normal 781060SN/A //register file that exists within AlphaISA class. 791060SN/A //The duplication is unfortunate but it's better than having 801060SN/A //different ways to access certain registers. 811060SN/A 821060SN/A //Add these in later when everything else is in place 831060SN/A// void serialize(std::ostream &os); 841060SN/A// void unserialize(Checkpoint *cp, const std::string §ion); 851060SN/A 861060SN/A uint64_t readIntReg(PhysRegIndex reg_idx) 871060SN/A { 881061SN/A assert(reg_idx < numPhysicalIntRegs); 891061SN/A 901060SN/A DPRINTF(IEW, "RegFile: Access to int register %i, has data " 911060SN/A "%i\n", int(reg_idx), intRegFile[reg_idx]); 921060SN/A return intRegFile[reg_idx]; 931060SN/A } 941060SN/A 952455SN/A FloatReg readFloatReg(PhysRegIndex reg_idx, int width) 961060SN/A { 971060SN/A // Remove the base Float reg dependency. 981060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 991060SN/A 1001062SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1011061SN/A 1022455SN/A FloatReg floatReg = floatRegFile.readReg(reg_idx, width); 1031060SN/A 1042455SN/A DPRINTF(IEW, "RegFile: Access to %d byte float register %i, has " 1052455SN/A "data %8.8d\n", int(reg_idx), (double)floatReg); 1062455SN/A 1072455SN/A return floatReg; 1081060SN/A } 1091060SN/A 1102455SN/A FloatReg readFloatReg(PhysRegIndex reg_idx) 1111060SN/A { 1121060SN/A // Remove the base Float reg dependency. 1131060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1141060SN/A 1151062SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1161061SN/A 1172455SN/A FloatReg floatReg = floatRegFile.readReg(reg_idx); 1181060SN/A 1192455SN/A DPRINTF(IEW, "RegFile: Access to float register %i, has " 1202455SN/A "data %8.8d\n", int(reg_idx), (double)floatReg); 1212455SN/A 1222455SN/A return floatReg; 1231060SN/A } 1241060SN/A 1252455SN/A FloatRegBits readFloatRegBits(PhysRegIndex reg_idx, int width) 1261060SN/A { 1271060SN/A // Remove the base Float reg dependency. 1281060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1291060SN/A 1301062SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1311061SN/A 1322455SN/A FloatRegBits floatRegBits = floatRegFile.readRegBits(reg_idx, width); 1331060SN/A 1342455SN/A DPRINTF(IEW, "RegFile: Access to %d byte float register %i as int, " 1352455SN/A "has data %lli\n", int(reg_idx), (uint64_t)floatRegBits); 1362455SN/A 1372455SN/A return floatRegBits; 1382455SN/A } 1392455SN/A 1402455SN/A FloatRegBits readFloatRegBits(PhysRegIndex reg_idx) 1412455SN/A { 1422455SN/A // Remove the base Float reg dependency. 1432455SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1442455SN/A 1452455SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1462455SN/A 1472455SN/A FloatRegBits floatRegBits = floatRegFile.readRegBits(reg_idx); 1482455SN/A 1492455SN/A DPRINTF(IEW, "RegFile: Access to float register %i as int, " 1502455SN/A "has data %lli\n", int(reg_idx), (uint64_t)floatRegBits); 1512455SN/A 1522455SN/A return floatRegBits; 1531060SN/A } 1541060SN/A 1551060SN/A void setIntReg(PhysRegIndex reg_idx, uint64_t val) 1561060SN/A { 1571061SN/A assert(reg_idx < numPhysicalIntRegs); 1581061SN/A 1591060SN/A DPRINTF(IEW, "RegFile: Setting int register %i to %lli\n", 1601060SN/A int(reg_idx), val); 1611060SN/A 1621060SN/A intRegFile[reg_idx] = val; 1631060SN/A } 1641060SN/A 1652455SN/A void setFloatReg(PhysRegIndex reg_idx, FloatReg val, int width) 1661060SN/A { 1671060SN/A // Remove the base Float reg dependency. 1681060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1691060SN/A 1701062SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1711061SN/A 1722455SN/A DPRINTF(IEW, "RegFile: Setting float register %i to %8.8d\n", 1732455SN/A int(reg_idx), (double)val); 1741060SN/A 1752455SN/A floatRegFile.setReg(reg_idx, val, width); 1761060SN/A } 1771060SN/A 1782455SN/A void setFloatReg(PhysRegIndex reg_idx, FloatReg val) 1791060SN/A { 1801060SN/A // Remove the base Float reg dependency. 1811060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1821060SN/A 1831062SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1841061SN/A 1852455SN/A DPRINTF(IEW, "RegFile: Setting float register %i to %8.8d\n", 1862455SN/A int(reg_idx), (double)val); 1871060SN/A 1882455SN/A floatRegFile.setReg(reg_idx, val); 1891060SN/A } 1901060SN/A 1912455SN/A void setFloatRegBits(PhysRegIndex reg_idx, FloatRegBits val, int width) 1921060SN/A { 1931060SN/A // Remove the base Float reg dependency. 1941060SN/A reg_idx = reg_idx - numPhysicalIntRegs; 1951060SN/A 1961062SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 1971061SN/A 1981060SN/A DPRINTF(IEW, "RegFile: Setting float register %i to %lli\n", 1992455SN/A int(reg_idx), (uint64_t)val); 2001060SN/A 2012455SN/A floatRegFile.setRegBits(reg_idx, val, width); 2022455SN/A } 2032455SN/A 2042455SN/A void setFloatRegBits(PhysRegIndex reg_idx, FloatRegBits val) 2052455SN/A { 2062455SN/A // Remove the base Float reg dependency. 2072455SN/A reg_idx = reg_idx - numPhysicalIntRegs; 2082455SN/A 2092455SN/A assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs); 2102455SN/A 2112455SN/A DPRINTF(IEW, "RegFile: Setting float register %i to %lli\n", 2122455SN/A int(reg_idx), (uint64_t)val); 2132455SN/A 2142455SN/A floatRegFile.setRegBits(reg_idx, val); 2151060SN/A } 2161060SN/A 2171060SN/A uint64_t readPC() 2181060SN/A { 2191060SN/A return pc; 2201060SN/A } 2211060SN/A 2221060SN/A void setPC(uint64_t val) 2231060SN/A { 2241060SN/A pc = val; 2251060SN/A } 2261060SN/A 2271060SN/A void setNextPC(uint64_t val) 2281060SN/A { 2291060SN/A npc = val; 2301060SN/A } 2311060SN/A 2321060SN/A //Consider leaving this stuff and below in some implementation specific 2331060SN/A //file as opposed to the general register file. Or have a derived class. 2342159SN/A MiscReg readMiscReg(int misc_reg) 2351060SN/A { 2362159SN/A // Dummy function for now. 2372159SN/A // @todo: Fix this once proxy XC is used. 2382159SN/A return 0; 2391060SN/A } 2401060SN/A 2412159SN/A Fault setMiscReg(int misc_reg, const MiscReg &val) 2421060SN/A { 2432159SN/A // Dummy function for now. 2442159SN/A // @todo: Fix this once proxy XC is used. 2452159SN/A return NoFault; 2461060SN/A } 2471060SN/A 2481858SN/A#if FULL_SYSTEM 2491060SN/A int readIntrFlag() { return intrflag; } 2501060SN/A void setIntrFlag(int val) { intrflag = val; } 2511060SN/A#endif 2521060SN/A 2531060SN/A // These should be private eventually, but will be public for now 2541060SN/A // so that I can hack around the initregs issue. 2551060SN/A public: 2561060SN/A /** (signed) integer register file. */ 2571060SN/A IntReg *intRegFile; 2581060SN/A 2591060SN/A /** Floating point register file. */ 2601060SN/A FloatReg *floatRegFile; 2611060SN/A 2621060SN/A /** Miscellaneous register file. */ 2631060SN/A MiscRegFile miscRegs; 2641060SN/A 2651684SN/A /** Program counter. */ 2661684SN/A Addr pc; 2671684SN/A 2681684SN/A /** Next-cycle program counter. */ 2691684SN/A Addr npc; 2701060SN/A 2711858SN/A#if FULL_SYSTEM 2721060SN/A private: 2731681SN/A // This is ISA specifc stuff; remove it eventually once ISAImpl is used 2742227SN/A// IntReg palregs[NumIntRegs]; // PAL shadow registers 2751681SN/A int intrflag; // interrupt flag 2761681SN/A bool pal_shadow; // using pal_shadow registers 2771681SN/A#endif 2781681SN/A 2791681SN/A private: 2801681SN/A FullCPU *cpu; 2811681SN/A 2821681SN/A public: 2831681SN/A void setCPU(FullCPU *cpu_ptr) { cpu = cpu_ptr; } 2841681SN/A 2851060SN/A unsigned numPhysicalIntRegs; 2861060SN/A unsigned numPhysicalFloatRegs; 2871060SN/A}; 2881060SN/A 2891061SN/Atemplate <class Impl> 2901060SN/APhysRegFile<Impl>::PhysRegFile(unsigned _numPhysicalIntRegs, 2911060SN/A unsigned _numPhysicalFloatRegs) 2921060SN/A : numPhysicalIntRegs(_numPhysicalIntRegs), 2931060SN/A numPhysicalFloatRegs(_numPhysicalFloatRegs) 2941060SN/A{ 2951060SN/A intRegFile = new IntReg[numPhysicalIntRegs]; 2961060SN/A floatRegFile = new FloatReg[numPhysicalFloatRegs]; 2971060SN/A 2981060SN/A memset(intRegFile, 0, sizeof(*intRegFile)); 2991060SN/A memset(floatRegFile, 0, sizeof(*floatRegFile)); 3001060SN/A} 3011060SN/A 3021755SN/A#endif // __CPU_O3_CPU_REGFILE_HH__ 303