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.
32 #include "arch/sparc/floatregfile.hh"
33 #include "base/trace.hh"
34 #include "sim/byteswap.hh"
35 #include "sim/serialize.hh"
39 using namespace SparcISA
;
44 void FloatRegFile::clear()
46 memset(regSpace
, 0, sizeof(regSpace
));
49 FloatReg
FloatRegFile::readReg(int floatReg
, int width
)
51 //In each of these cases, we have to copy the value into a temporary
52 //variable. This is because we may otherwise try to access an
53 //unaligned portion of memory.
60 memcpy(&result32
, regSpace
+ 4 * floatReg
, sizeof(result32
));
61 result32
= htog(result32
);
62 memcpy(&fresult32
, &result32
, sizeof(result32
));
64 DPRINTF(FloatRegs
, "Read FP32 register %d = [%f]0x%x\n",
65 floatReg
, result
, result32
);
70 memcpy(&result64
, regSpace
+ 4 * floatReg
, sizeof(result64
));
71 result64
= htog(result64
);
72 memcpy(&fresult64
, &result64
, sizeof(result64
));
74 DPRINTF(FloatRegs
, "Read FP64 register %d = [%f]0x%x\n",
75 floatReg
, result
, result64
);
78 panic("Quad width FP not implemented.");
81 panic("Attempted to read a %d bit floating point register!", width
);
86 FloatRegBits
FloatRegFile::readRegBits(int floatReg
, int width
)
88 //In each of these cases, we have to copy the value into a temporary
89 //variable. This is because we may otherwise try to access an
90 //unaligned portion of memory.
96 memcpy(&result32
, regSpace
+ 4 * floatReg
, sizeof(result32
));
97 result
= htog(result32
);
98 DPRINTF(FloatRegs
, "Read FP32 bits register %d = 0x%x\n",
103 memcpy(&result64
, regSpace
+ 4 * floatReg
, sizeof(result64
));
104 result
= htog(result64
);
105 DPRINTF(FloatRegs
, "Read FP64 bits register %d = 0x%x\n",
109 panic("Quad width FP not implemented.");
112 panic("Attempted to read a %d bit floating point register!", width
);
117 Fault
FloatRegFile::setReg(int floatReg
, const FloatReg
&val
, int width
)
119 //In each of these cases, we have to copy the value into a temporary
120 //variable. This is because we may otherwise try to access an
121 //unaligned portion of memory.
131 memcpy(&result32
, &fresult32
, sizeof(result32
));
132 result32
= gtoh(result32
);
133 memcpy(regSpace
+ 4 * floatReg
, &result32
, sizeof(result32
));
134 DPRINTF(FloatRegs
, "Write FP64 register %d = 0x%x\n",
139 memcpy(&result64
, &fresult64
, sizeof(result64
));
140 result64
= gtoh(result64
);
141 memcpy(regSpace
+ 4 * floatReg
, &result64
, sizeof(result64
));
142 DPRINTF(FloatRegs
, "Write FP64 register %d = 0x%x\n",
146 panic("Quad width FP not implemented.");
149 panic("Attempted to read a %d bit floating point register!", width
);
154 Fault
FloatRegFile::setRegBits(int floatReg
, const FloatRegBits
&val
, int width
)
156 //In each of these cases, we have to copy the value into a temporary
157 //variable. This is because we may otherwise try to access an
158 //unaligned portion of memory.
164 result32
= gtoh((uint32_t)val
);
165 memcpy(regSpace
+ 4 * floatReg
, &result32
, sizeof(result32
));
166 DPRINTF(FloatRegs
, "Write FP64 bits register %d = 0x%x\n",
170 result64
= gtoh((uint64_t)val
);
171 memcpy(regSpace
+ 4 * floatReg
, &result64
, sizeof(result64
));
172 DPRINTF(FloatRegs
, "Write FP64 bits register %d = 0x%x\n",
176 panic("Quad width FP not implemented.");
179 panic("Attempted to read a %d bit floating point register!", width
);
184 void FloatRegFile::serialize(std::ostream
&os
)
186 uint8_t *float_reg
= (uint8_t*)regSpace
;
187 SERIALIZE_ARRAY(float_reg
,
188 SingleWidth
/ 8 * NumFloatRegs
);
191 void FloatRegFile::unserialize(Checkpoint
*cp
, const std::string
§ion
)
193 uint8_t *float_reg
= (uint8_t*)regSpace
;
194 UNSERIALIZE_ARRAY(float_reg
,
195 SingleWidth
/ 8 * NumFloatRegs
);