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/regfile.hh"
33 #include "cpu/thread_context.hh"
37 using namespace SparcISA
;
40 //RegFile class methods
41 Addr
RegFile::readPC()
46 void RegFile::setPC(Addr val
)
51 Addr
RegFile::readNextPC()
56 void RegFile::setNextPC(Addr val
)
61 Addr
RegFile::readNextNPC()
66 void RegFile::setNextNPC(Addr val
)
77 MiscReg
RegFile::readMiscReg(int miscReg
)
79 return miscRegFile
.readReg(miscReg
);
82 MiscReg
RegFile::readMiscRegWithEffect(int miscReg
, ThreadContext
*tc
)
84 return miscRegFile
.readRegWithEffect(miscReg
, tc
);
87 void RegFile::setMiscReg(int miscReg
, const MiscReg
&val
)
89 miscRegFile
.setReg(miscReg
, val
);
92 void RegFile::setMiscRegWithEffect(int miscReg
, const MiscReg
&val
,
95 miscRegFile
.setRegWithEffect(miscReg
, val
, tc
);
98 FloatReg
RegFile::readFloatReg(int floatReg
, int width
)
100 return floatRegFile
.readReg(floatReg
, width
);
103 FloatReg
RegFile::readFloatReg(int floatReg
)
105 //Use the "natural" width of a single float
106 return floatRegFile
.readReg(floatReg
, FloatRegFile::SingleWidth
);
109 FloatRegBits
RegFile::readFloatRegBits(int floatReg
, int width
)
111 return floatRegFile
.readRegBits(floatReg
, width
);
114 FloatRegBits
RegFile::readFloatRegBits(int floatReg
)
116 //Use the "natural" width of a single float
117 return floatRegFile
.readRegBits(floatReg
,
118 FloatRegFile::SingleWidth
);
121 void RegFile::setFloatReg(int floatReg
, const FloatReg
&val
, int width
)
123 floatRegFile
.setReg(floatReg
, val
, width
);
126 void RegFile::setFloatReg(int floatReg
, const FloatReg
&val
)
128 //Use the "natural" width of a single float
129 setFloatReg(floatReg
, val
, FloatRegFile::SingleWidth
);
132 void RegFile::setFloatRegBits(int floatReg
, const FloatRegBits
&val
, int width
)
134 floatRegFile
.setRegBits(floatReg
, val
, width
);
137 void RegFile::setFloatRegBits(int floatReg
, const FloatRegBits
&val
)
139 //Use the "natural" width of a single float
140 floatRegFile
.setRegBits(floatReg
, val
, FloatRegFile::SingleWidth
);
143 IntReg
RegFile::readIntReg(int intReg
)
145 return intRegFile
.readReg(intReg
);
148 void RegFile::setIntReg(int intReg
, const IntReg
&val
)
150 intRegFile
.setReg(intReg
, val
);
153 void RegFile::serialize(std::ostream
&os
)
155 intRegFile
.serialize(os
);
156 floatRegFile
.serialize(os
);
157 miscRegFile
.serialize(os
);
158 SERIALIZE_SCALAR(pc
);
159 SERIALIZE_SCALAR(npc
);
162 void RegFile::unserialize(Checkpoint
*cp
, const std::string
§ion
)
164 intRegFile
.unserialize(cp
, section
);
165 floatRegFile
.unserialize(cp
, section
);
166 miscRegFile
.unserialize(cp
, section
);
167 UNSERIALIZE_SCALAR(pc
);
168 UNSERIALIZE_SCALAR(npc
);
171 void RegFile::changeContext(RegContextParam param
, RegContextVal val
)
176 intRegFile
.setCWP(val
);
178 case CONTEXT_GLOBALS
:
179 intRegFile
.setGlobals(val
);
182 panic("Tried to set illegal context parameter in the SPARC regfile.\n");
186 int SparcISA::InterruptLevel(uint64_t softint
)
188 if (softint
& 0x10000 || softint
& 0x1)
192 while (level
>= 0 && !(1 << (level
+ 1) & softint
))
194 if (1 << (level
+ 1) & softint
)
199 void SparcISA::copyMiscRegs(ThreadContext
*src
, ThreadContext
*dest
)
202 uint8_t tl
= src
->readMiscReg(MISCREG_TL
);
204 // Read all the trap level dependent registers and save them off
205 for(int i
= 1; i
<= MaxTL
; i
++)
207 src
->setMiscReg(MISCREG_TL
, i
);
208 dest
->setMiscReg(MISCREG_TL
, i
);
210 dest
->setMiscReg(MISCREG_TT
, src
->readMiscReg(MISCREG_TT
));
211 dest
->setMiscReg(MISCREG_TPC
, src
->readMiscReg(MISCREG_TPC
));
212 dest
->setMiscReg(MISCREG_TNPC
, src
->readMiscReg(MISCREG_TNPC
));
213 dest
->setMiscReg(MISCREG_TSTATE
, src
->readMiscReg(MISCREG_TSTATE
));
216 // Save off the traplevel
217 dest
->setMiscReg(MISCREG_TL
, tl
);
218 src
->setMiscReg(MISCREG_TL
, tl
);
222 dest
->setMiscReg(MISCREG_Y
, src
->readMiscReg(MISCREG_Y
));
223 dest
->setMiscReg(MISCREG_CCR
, src
->readMiscReg(MISCREG_CCR
));
224 dest
->setMiscReg(MISCREG_ASI
, src
->readMiscReg(MISCREG_ASI
));
225 dest
->setMiscReg(MISCREG_TICK
, src
->readMiscReg(MISCREG_TICK
));
226 dest
->setMiscReg(MISCREG_FPRS
, src
->readMiscReg(MISCREG_FPRS
));
227 dest
->setMiscReg(MISCREG_SOFTINT
, src
->readMiscReg(MISCREG_SOFTINT
));
228 dest
->setMiscReg(MISCREG_TICK_CMPR
, src
->readMiscReg(MISCREG_TICK_CMPR
));
229 dest
->setMiscReg(MISCREG_STICK
, src
->readMiscReg(MISCREG_STICK
));
230 dest
->setMiscReg(MISCREG_STICK_CMPR
, src
->readMiscReg(MISCREG_STICK_CMPR
));
233 dest
->setMiscReg(MISCREG_TICK
, src
->readMiscReg(MISCREG_TICK
));
234 dest
->setMiscReg(MISCREG_TBA
, src
->readMiscReg(MISCREG_TBA
));
235 dest
->setMiscReg(MISCREG_PSTATE
, src
->readMiscReg(MISCREG_PSTATE
));
236 dest
->setMiscReg(MISCREG_PIL
, src
->readMiscReg(MISCREG_PIL
));
237 dest
->setMiscReg(MISCREG_CWP
, src
->readMiscReg(MISCREG_CWP
));
238 dest
->setMiscReg(MISCREG_CANSAVE
, src
->readMiscReg(MISCREG_CANSAVE
));
239 dest
->setMiscReg(MISCREG_CANRESTORE
, src
->readMiscReg(MISCREG_CANRESTORE
));
240 dest
->setMiscReg(MISCREG_OTHERWIN
, src
->readMiscReg(MISCREG_OTHERWIN
));
241 dest
->setMiscReg(MISCREG_CLEANWIN
, src
->readMiscReg(MISCREG_CLEANWIN
));
242 dest
->setMiscReg(MISCREG_WSTATE
, src
->readMiscReg(MISCREG_WSTATE
));
243 dest
->setMiscReg(MISCREG_GL
, src
->readMiscReg(MISCREG_GL
));
245 // Hyperprivilged registers
246 dest
->setMiscReg(MISCREG_HPSTATE
, src
->readMiscReg(MISCREG_HPSTATE
));
247 dest
->setMiscReg(MISCREG_HINTP
, src
->readMiscReg(MISCREG_HINTP
));
248 dest
->setMiscReg(MISCREG_HTBA
, src
->readMiscReg(MISCREG_HTBA
));
249 dest
->setMiscReg(MISCREG_STRAND_STS_REG
,
250 src
->readMiscReg(MISCREG_STRAND_STS_REG
));
251 dest
->setMiscReg(MISCREG_HSTICK_CMPR
,
252 src
->readMiscReg(MISCREG_HSTICK_CMPR
));
255 dest
->setMiscReg(MISCREG_FSR
, src
->readMiscReg(MISCREG_FSR
));
258 void SparcISA::copyRegs(ThreadContext
*src
, ThreadContext
*dest
)
260 // First loop through the integer registers.
261 for (int i
= 0; i
< TheISA::NumIntRegs
; ++i
) {
262 dest
->setIntReg(i
, src
->readIntReg(i
));
265 // Then loop through the floating point registers.
266 for (int i
= 0; i
< TheISA::NumFloatRegs
; ++i
) {
267 dest
->setFloatRegBits(i
, src
->readFloatRegBits(i
));
270 // Copy misc. registers
271 copyMiscRegs(src
, dest
);
273 // Lastly copy PC/NPC
274 dest
->setPC(src
->readPC());
275 dest
->setNextPC(src
->readNextPC());
276 dest
->setNextNPC(src
->readNextNPC());