2 * Copyright (c) 2006 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_REGFILE_FLOAT_REGFILE_HH__
30 #define __ARCH_MIPS_REGFILE_FLOAT_REGFILE_HH__
32 #include "arch/mips/types.hh"
33 #include "arch/mips/isa_traits.hh"
34 #include "base/misc.hh"
35 #include "base/bitfield.hh"
36 #include "sim/faults.hh"
44 static inline std::string getFloatRegName(RegIndex)
49 const uint32_t MIPS32_QNAN = 0x7fbfffff;
50 const uint64_t MIPS64_QNAN = ULL(0x7fbfffffffffffff);
52 enum FPControlRegNums {
53 FIR = NumFloatArchRegs,
75 const int SingleWidth = 32;
76 const int SingleBytes = SingleWidth / 4;
78 const int DoubleWidth = 64;
79 const int DoubleBytes = DoubleWidth / 4;
81 const int QuadWidth = 128;
82 const int QuadBytes = QuadWidth / 4;
87 FloatReg32 regs[NumFloatRegs];
91 void clear() { bzero(®s, sizeof(regs)); }
93 double readReg(int floatReg, int width, unsigned tid = 0)
99 void *float_ptr = ®s[floatReg];
100 return *(float *) float_ptr;
105 uint64_t double_val = (FloatReg64)regs[floatReg + 1] << 32 | regs[floatReg];
106 void *double_ptr = &double_val;
107 return *(double *) double_ptr;
111 panic("Attempted to read a %d bit floating point register!", width);
115 FloatRegBits readRegBits(int floatReg, int width, unsigned tid = 0)
117 if (floatReg < NumFloatArchRegs - 1) {
121 return regs[floatReg];
124 return (FloatReg64)regs[floatReg + 1] << 32 | regs[floatReg];
127 panic("Attempted to read a %d bit floating point register!", width);
130 if (width > SingleWidth)
131 assert("Control Regs are only 32 bits wide");
133 return regs[floatReg];
137 Fault setReg(int floatReg, const FloatRegVal &val, int width, unsigned tid = 0)
145 void *float_ptr = &temp;
146 regs[floatReg] = *(FloatReg32 *) float_ptr;
152 const void *double_ptr = &val;
153 FloatReg64 temp_double = *(FloatReg64 *) double_ptr;
154 regs[floatReg + 1] = bits(temp_double, 63, 32);
155 regs[floatReg] = bits(temp_double, 31, 0);
160 panic("Attempted to read a %d bit floating point register!", width);
166 Fault setRegBits(int floatReg, const FloatRegBits &val, int width, unsigned tid = 0)
173 regs[floatReg] = val;
177 regs[floatReg + 1] = bits(val, 63, 32);
178 regs[floatReg] = bits(val, 31, 0);
182 panic("Attempted to read a %d bit floating point register!", width);
187 void serialize(std::ostream &os);
189 void unserialize(Checkpoint *cp, const std::string §ion);
192 } // namespace MipsISA