f577a1c94652637ecdaeb9cd207d20ba2a38f935
[gem5.git] / src / arch / mips / isa_traits.cc
1 /*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Gabe Black
29 * Korey Sewell
30 */
31
32 #include "arch/mips/isa_traits.hh"
33 #include "config/full_system.hh"
34 #include "cpu/static_inst.hh"
35 #include "sim/serialize.hh"
36 #include "base/bitfield.hh"
37
38 using namespace MipsISA;
39 using namespace std;
40
41
42 void
43 MipsISA::copyRegs(ExecContext *src, ExecContext *dest)
44 {
45 /*fpcr = xc->readMiscReg(MipsISA::Fpcr_DepTag);
46 uniq = xc->readMiscReg(MipsISA::Uniq_DepTag);
47 lock_flag = xc->readMiscReg(MipsISA::Lock_Flag_DepTag);
48 lock_addr = xc->readMiscReg(MipsISA::Lock_Addr_DepTag);
49
50 #if FULL_SYSTEM
51 copyIprs(xc);
52 #endif*/
53 }
54
55 void
56 MipsISA::MiscRegFile::copyMiscRegs(ExecContext *xc)
57 {
58 /*fpcr = xc->readMiscReg(MipsISA::Fpcr_DepTag);
59 uniq = xc->readMiscReg(MipsISA::Uniq_DepTag);
60 lock_flag = xc->readMiscReg(MipsISA::Lock_Flag_DepTag);
61 lock_addr = xc->readMiscReg(MipsISA::Lock_Addr_DepTag);
62
63 #endif*/
64 }
65
66 uint64_t
67 MipsISA::fpConvert(double fp_val, ConvertType cvt_type)
68 {
69
70 switch (cvt_type)
71 {
72 case SINGLE_TO_DOUBLE:
73 double sdouble_val = fp_val;
74 void *sdouble_ptr = &sdouble_val;
75 uint64_t sdp_bits = *(uint64_t *) sdouble_ptr;
76 return sdp_bits;
77
78 case SINGLE_TO_WORD:
79 int32_t sword_val = (int32_t) fp_val;
80 void *sword_ptr = &sword_val;
81 uint64_t sword_bits= *(uint32_t *) sword_ptr;
82 return sword_bits;
83
84 case WORD_TO_SINGLE:
85 float wfloat_val = fp_val;
86 void *wfloat_ptr = &wfloat_val;
87 uint64_t wfloat_bits = *(uint32_t *) wfloat_ptr;
88 return wfloat_bits;
89
90 case WORD_TO_DOUBLE:
91 double wdouble_val = fp_val;
92 void *wdouble_ptr = &wdouble_val;
93 uint64_t wdp_bits = *(uint64_t *) wdouble_ptr;
94 return wdp_bits;
95
96 default:
97 panic("Invalid Floating Point Conversion Type (%d). See \"types.hh\" for List of Conversions\n",cvt_type);
98 return 0;
99 }
100 }
101
102 double
103 MipsISA::roundFP(double val, int digits)
104 {
105 double digit_offset = pow(10.0,digits);
106 val = val * digit_offset;
107 val = val + 0.5;
108 val = floor(val);
109 val = val / digit_offset;
110 return val;
111 }
112
113 double
114 MipsISA::truncFP(double val)
115 {
116 int trunc_val = (int) val;
117 return (double) trunc_val;
118 }
119
120 bool
121 MipsISA::getFPConditionCode(uint32_t fcsr_reg, int cc)
122 {
123 //uint32_t cc_bits = xc->readFloatReg(35);
124 return false;//regFile.floatRegfile.getConditionCode(cc);
125 }
126
127 uint32_t
128 MipsISA::makeCCVector(uint32_t fcsr, int num, bool val)
129 {
130 int shift = (num == 0) ? 22 : num + 23;
131
132 fcsr = fcsr | (val << shift);
133
134 return fcsr;
135 }
136
137 #if FULL_SYSTEM
138
139 static inline Addr
140 TruncPage(Addr addr)
141 { return addr & ~(MipsISA::PageBytes - 1); }
142
143 static inline Addr
144 RoundPage(Addr addr)
145 { return (addr + MipsISA::PageBytes - 1) & ~(MipsISA::PageBytes - 1); }
146 #endif
147
148 void
149 IntRegFile::serialize(std::ostream &os)
150 {
151 SERIALIZE_ARRAY(regs, NumIntRegs);
152 }
153
154 void
155 IntRegFile::unserialize(Checkpoint *cp, const std::string &section)
156 {
157 UNSERIALIZE_ARRAY(regs, NumIntRegs);
158 }
159
160 void
161 RegFile::serialize(std::ostream &os)
162 {
163 intRegFile.serialize(os);
164 //SERIALIZE_ARRAY(floatRegFile.q, NumFloatRegs);
165 //SERIALIZE_SCALAR(miscRegs.fpcr);
166 //SERIALIZE_SCALAR(miscRegs.uniq);
167 //SERIALIZE_SCALAR(miscRegs.lock_flag);
168 //SERIALIZE_SCALAR(miscRegs.lock_addr);
169 SERIALIZE_SCALAR(pc);
170 SERIALIZE_SCALAR(npc);
171 SERIALIZE_SCALAR(nnpc);
172 #if FULL_SYSTEM
173 SERIALIZE_ARRAY(palregs, NumIntRegs);
174 SERIALIZE_ARRAY(ipr, NumInternalProcRegs);
175 SERIALIZE_SCALAR(intrflag);
176 SERIALIZE_SCALAR(pal_shadow);
177 #endif
178 }
179
180
181 void
182 RegFile::unserialize(Checkpoint *cp, const std::string &section)
183 {
184 intRegFile.unserialize(cp, section);
185 //UNSERIALIZE_ARRAY(floatRegFile.q, NumFloatRegs);
186 //UNSERIALIZE_SCALAR(miscRegs.fpcr);
187 //UNSERIALIZE_SCALAR(miscRegs.uniq);
188 //UNSERIALIZE_SCALAR(miscRegs.lock_flag);
189 //UNSERIALIZE_SCALAR(miscRegs.lock_addr);
190 UNSERIALIZE_SCALAR(pc);
191 UNSERIALIZE_SCALAR(npc);
192 UNSERIALIZE_SCALAR(nnpc);
193 #if FULL_SYSTEM
194 UNSERIALIZE_ARRAY(palregs, NumIntRegs);
195 UNSERIALIZE_ARRAY(ipr, NumInternalProcRegs);
196 UNSERIALIZE_SCALAR(intrflag);
197 UNSERIALIZE_SCALAR(pal_shadow);
198 #endif
199 }
200
201
202 #if FULL_SYSTEM
203 void
204 PTE::serialize(std::ostream &os)
205 {
206 SERIALIZE_SCALAR(tag);
207 SERIALIZE_SCALAR(ppn);
208 SERIALIZE_SCALAR(xre);
209 SERIALIZE_SCALAR(xwe);
210 SERIALIZE_SCALAR(asn);
211 SERIALIZE_SCALAR(asma);
212 SERIALIZE_SCALAR(fonr);
213 SERIALIZE_SCALAR(fonw);
214 SERIALIZE_SCALAR(valid);
215 }
216
217
218 void
219 PTE::unserialize(Checkpoint *cp, const std::string &section)
220 {
221 UNSERIALIZE_SCALAR(tag);
222 UNSERIALIZE_SCALAR(ppn);
223 UNSERIALIZE_SCALAR(xre);
224 UNSERIALIZE_SCALAR(xwe);
225 UNSERIALIZE_SCALAR(asn);
226 UNSERIALIZE_SCALAR(asma);
227 UNSERIALIZE_SCALAR(fonr);
228 UNSERIALIZE_SCALAR(fonw);
229 UNSERIALIZE_SCALAR(valid);
230 }
231
232 #endif //FULL_SYSTEM