2 * Copyright (c) 2004-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.
32 #ifndef __CPU_O3_REGFILE_HH__
33 #define __CPU_O3_REGFILE_HH__
35 #include "arch/isa_traits.hh"
36 #include "arch/types.hh"
37 #include "base/trace.hh"
38 #include "config/full_system.hh"
39 #include "cpu/o3/comm.hh"
42 #include "kern/kernel_stats.hh"
49 * Simple physical register file class.
50 * Right now this is specific to Alpha until we decide if/how to make things
51 * generic enough to support other ISAs.
57 typedef TheISA::IntReg IntReg;
58 typedef TheISA::FloatReg FloatReg;
59 typedef TheISA::FloatRegBits FloatRegBits;
60 typedef TheISA::MiscRegFile MiscRegFile;
61 typedef TheISA::MiscReg MiscReg;
68 // Note that most of the definitions of the IntReg, FloatReg, etc. exist
69 // within the Impl/ISA class and not within this PhysRegFile class.
71 // Will make these registers public for now, but they probably should
72 // be private eventually with some accessor functions.
74 typedef typename Impl::O3CPU O3CPU;
77 * Constructs a physical register file with the specified amount of
78 * integer and floating point registers.
80 PhysRegFile(unsigned _numPhysicalIntRegs,
81 unsigned _numPhysicalFloatRegs);
83 //Everything below should be pretty well identical to the normal
84 //register file that exists within AlphaISA class.
85 //The duplication is unfortunate but it's better than having
86 //different ways to access certain registers.
88 /** Reads an integer register. */
89 uint64_t readIntReg(PhysRegIndex reg_idx)
91 assert(reg_idx < numPhysicalIntRegs);
93 DPRINTF(IEW, "RegFile: Access to int register %i, has data "
94 "%#x\n", int(reg_idx), intRegFile[reg_idx]);
95 return intRegFile[reg_idx];
98 FloatReg readFloatReg(PhysRegIndex reg_idx, int width)
100 // Remove the base Float reg dependency.
101 reg_idx = reg_idx - numPhysicalIntRegs;
103 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
105 FloatReg floatReg = floatRegFile[reg_idx].d;
107 DPRINTF(IEW, "RegFile: Access to %d byte float register %i, has "
108 "data %#x\n", int(reg_idx), floatRegFile[reg_idx].q);
113 /** Reads a floating point register (double precision). */
114 FloatReg readFloatReg(PhysRegIndex reg_idx)
116 // Remove the base Float reg dependency.
117 reg_idx = reg_idx - numPhysicalIntRegs;
119 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
121 FloatReg floatReg = floatRegFile[reg_idx].d;
123 DPRINTF(IEW, "RegFile: Access to float register %i, has "
124 "data %#x\n", int(reg_idx), floatRegFile[reg_idx].q);
129 /** Reads a floating point register as an integer. */
130 FloatRegBits readFloatRegBits(PhysRegIndex reg_idx, int width)
132 // Remove the base Float reg dependency.
133 reg_idx = reg_idx - numPhysicalIntRegs;
135 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
137 FloatRegBits floatRegBits = floatRegFile[reg_idx].q;
139 DPRINTF(IEW, "RegFile: Access to float register %i as int, "
140 "has data %#x\n", int(reg_idx), (uint64_t)floatRegBits);
145 FloatRegBits readFloatRegBits(PhysRegIndex reg_idx)
147 // Remove the base Float reg dependency.
148 reg_idx = reg_idx - numPhysicalIntRegs;
150 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
152 FloatRegBits floatRegBits = floatRegFile[reg_idx].q;
154 DPRINTF(IEW, "RegFile: Access to float register %i as int, "
155 "has data %#x\n", int(reg_idx), (uint64_t)floatRegBits);
160 /** Sets an integer register to the given value. */
161 void setIntReg(PhysRegIndex reg_idx, uint64_t val)
163 assert(reg_idx < numPhysicalIntRegs);
165 DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n",
168 if (reg_idx != TheISA::ZeroReg)
169 intRegFile[reg_idx] = val;
172 /** Sets a single precision floating point register to the given value. */
173 void setFloatReg(PhysRegIndex reg_idx, FloatReg val, int width)
175 // Remove the base Float reg dependency.
176 reg_idx = reg_idx - numPhysicalIntRegs;
178 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
180 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
181 int(reg_idx), (uint64_t)val);
183 if (reg_idx != TheISA::ZeroReg)
184 floatRegFile[reg_idx].d = val;
187 /** Sets a double precision floating point register to the given value. */
188 void setFloatReg(PhysRegIndex reg_idx, FloatReg val)
190 // Remove the base Float reg dependency.
191 reg_idx = reg_idx - numPhysicalIntRegs;
193 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
195 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
196 int(reg_idx), (uint64_t)val);
198 if (reg_idx != TheISA::ZeroReg)
199 floatRegFile[reg_idx].d = val;
202 /** Sets a floating point register to the given integer value. */
203 void setFloatRegBits(PhysRegIndex reg_idx, FloatRegBits val, int width)
205 // Remove the base Float reg dependency.
206 reg_idx = reg_idx - numPhysicalIntRegs;
208 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
210 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
211 int(reg_idx), (uint64_t)val);
213 floatRegFile[reg_idx].q = val;
216 void setFloatRegBits(PhysRegIndex reg_idx, FloatRegBits val)
218 // Remove the base Float reg dependency.
219 reg_idx = reg_idx - numPhysicalIntRegs;
221 assert(reg_idx < numPhysicalFloatRegs + numPhysicalIntRegs);
223 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
224 int(reg_idx), (uint64_t)val);
226 floatRegFile[reg_idx].q = val;
229 MiscReg readMiscReg(int misc_reg, unsigned thread_id)
231 return miscRegs[thread_id].readReg(misc_reg);
234 MiscReg readMiscRegWithEffect(int misc_reg, unsigned thread_id)
236 return miscRegs[thread_id].readRegWithEffect(misc_reg,
237 cpu->tcBase(thread_id));
240 void setMiscReg(int misc_reg, const MiscReg &val, unsigned thread_id)
242 miscRegs[thread_id].setReg(misc_reg, val);
245 void setMiscRegWithEffect(int misc_reg, const MiscReg &val,
248 miscRegs[thread_id].setRegWithEffect(misc_reg, val,
249 cpu->tcBase(thread_id));
253 /** (signed) integer register file. */
256 /** Floating point register file. */
257 PhysFloatReg *floatRegFile;
259 /** Miscellaneous register file. */
260 MiscRegFile miscRegs[Impl::MaxThreads];
264 int intrflag; // interrupt flag
272 /** Sets the CPU pointer. */
273 void setCPU(O3CPU *cpu_ptr) { cpu = cpu_ptr; }
275 /** Number of physical integer registers. */
276 unsigned numPhysicalIntRegs;
277 /** Number of physical floating point registers. */
278 unsigned numPhysicalFloatRegs;
281 template <class Impl>
282 PhysRegFile<Impl>::PhysRegFile(unsigned _numPhysicalIntRegs,
283 unsigned _numPhysicalFloatRegs)
284 : numPhysicalIntRegs(_numPhysicalIntRegs),
285 numPhysicalFloatRegs(_numPhysicalFloatRegs)
287 intRegFile = new IntReg[numPhysicalIntRegs];
288 floatRegFile = new PhysFloatReg[numPhysicalFloatRegs];
290 for (int i = 0; i < Impl::MaxThreads; ++i) {
294 memset(intRegFile, 0, sizeof(IntReg) * numPhysicalIntRegs);
295 memset(floatRegFile, 0, sizeof(PhysFloatReg) * numPhysicalFloatRegs);