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