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
,
83 Fault
&fault
, ThreadContext
*tc
)
86 return miscRegFile
.readRegWithEffect(miscReg
, tc
);
89 Fault
RegFile::setMiscReg(int miscReg
, const MiscReg
&val
)
91 miscRegFile
.setReg(miscReg
, val
);
95 Fault
RegFile::setMiscRegWithEffect(int miscReg
, const MiscReg
&val
,
98 miscRegFile
.setRegWithEffect(miscReg
, val
, tc
);
102 FloatReg
RegFile::readFloatReg(int floatReg
, int width
)
104 return floatRegFile
.readReg(floatReg
, width
);
107 FloatReg
RegFile::readFloatReg(int floatReg
)
109 //Use the "natural" width of a single float
110 return floatRegFile
.readReg(floatReg
, FloatRegFile::SingleWidth
);
113 FloatRegBits
RegFile::readFloatRegBits(int floatReg
, int width
)
115 return floatRegFile
.readRegBits(floatReg
, width
);
118 FloatRegBits
RegFile::readFloatRegBits(int floatReg
)
120 //Use the "natural" width of a single float
121 return floatRegFile
.readRegBits(floatReg
,
122 FloatRegFile::SingleWidth
);
125 Fault
RegFile::setFloatReg(int floatReg
, const FloatReg
&val
, int width
)
127 return floatRegFile
.setReg(floatReg
, val
, width
);
130 Fault
RegFile::setFloatReg(int floatReg
, const FloatReg
&val
)
132 //Use the "natural" width of a single float
133 return setFloatReg(floatReg
, val
, FloatRegFile::SingleWidth
);
136 Fault
RegFile::setFloatRegBits(int floatReg
, const FloatRegBits
&val
, int width
)
138 return floatRegFile
.setRegBits(floatReg
, val
, width
);
141 Fault
RegFile::setFloatRegBits(int floatReg
, const FloatRegBits
&val
)
143 //Use the "natural" width of a single float
144 return floatRegFile
.setRegBits(floatReg
, val
,
145 FloatRegFile::SingleWidth
);
148 IntReg
RegFile::readIntReg(int intReg
)
150 return intRegFile
.readReg(intReg
);
153 Fault
RegFile::setIntReg(int intReg
, const IntReg
&val
)
155 return intRegFile
.setReg(intReg
, val
);
158 void RegFile::serialize(std::ostream
&os
)
160 intRegFile
.serialize(os
);
161 floatRegFile
.serialize(os
);
162 miscRegFile
.serialize(os
);
163 SERIALIZE_SCALAR(pc
);
164 SERIALIZE_SCALAR(npc
);
167 void RegFile::unserialize(Checkpoint
*cp
, const std::string
§ion
)
169 intRegFile
.unserialize(cp
, section
);
170 floatRegFile
.unserialize(cp
, section
);
171 miscRegFile
.unserialize(cp
, section
);
172 UNSERIALIZE_SCALAR(pc
);
173 UNSERIALIZE_SCALAR(npc
);
176 void RegFile::changeContext(RegContextParam param
, RegContextVal val
)
181 intRegFile
.setCWP(val
);
183 case CONTEXT_GLOBALS
:
184 intRegFile
.setGlobals(val
);
187 panic("Tried to set illegal context parameter in the SPARC regfile.\n");
191 int SparcISA::InterruptLevel(uint64_t softint
)
193 if (softint
& 0x10000 || softint
& 0x1)
197 while (level
>= 0 && !(1 << (level
+ 1) & softint
))
199 if (1 << (level
+ 1) & softint
)
204 void SparcISA::copyMiscRegs(ThreadContext
*src
, ThreadContext
*dest
)
207 uint8_t tl
= src
->readMiscReg(MISCREG_TL
);
209 // Read all the trap level dependent registers and save them off
210 for(int i
= 1; i
<= MaxTL
; i
++)
212 src
->setMiscReg(MISCREG_TL
, i
);
213 dest
->setMiscReg(MISCREG_TL
, i
);
215 dest
->setMiscReg(MISCREG_TT
, src
->readMiscReg(MISCREG_TT
));
216 dest
->setMiscReg(MISCREG_TPC
, src
->readMiscReg(MISCREG_TPC
));
217 dest
->setMiscReg(MISCREG_TNPC
, src
->readMiscReg(MISCREG_TNPC
));
218 dest
->setMiscReg(MISCREG_TSTATE
, src
->readMiscReg(MISCREG_TSTATE
));
221 // Save off the traplevel
222 dest
->setMiscReg(MISCREG_TL
, tl
);
223 src
->setMiscReg(MISCREG_TL
, tl
);
227 dest
->setMiscReg(MISCREG_Y
, src
->readMiscReg(MISCREG_Y
));
228 dest
->setMiscReg(MISCREG_CCR
, src
->readMiscReg(MISCREG_CCR
));
229 dest
->setMiscReg(MISCREG_ASI
, src
->readMiscReg(MISCREG_ASI
));
230 dest
->setMiscReg(MISCREG_TICK
, src
->readMiscReg(MISCREG_TICK
));
231 dest
->setMiscReg(MISCREG_FPRS
, src
->readMiscReg(MISCREG_FPRS
));
232 dest
->setMiscReg(MISCREG_SOFTINT
, src
->readMiscReg(MISCREG_SOFTINT
));
233 dest
->setMiscReg(MISCREG_TICK_CMPR
, src
->readMiscReg(MISCREG_TICK_CMPR
));
234 dest
->setMiscReg(MISCREG_STICK
, src
->readMiscReg(MISCREG_STICK
));
235 dest
->setMiscReg(MISCREG_STICK_CMPR
, src
->readMiscReg(MISCREG_STICK_CMPR
));
238 dest
->setMiscReg(MISCREG_TICK
, src
->readMiscReg(MISCREG_TICK
));
239 dest
->setMiscReg(MISCREG_TBA
, src
->readMiscReg(MISCREG_TBA
));
240 dest
->setMiscReg(MISCREG_PSTATE
, src
->readMiscReg(MISCREG_PSTATE
));
241 dest
->setMiscReg(MISCREG_PIL
, src
->readMiscReg(MISCREG_PIL
));
242 dest
->setMiscReg(MISCREG_CWP
, src
->readMiscReg(MISCREG_CWP
));
243 dest
->setMiscReg(MISCREG_CANSAVE
, src
->readMiscReg(MISCREG_CANSAVE
));
244 dest
->setMiscReg(MISCREG_CANRESTORE
, src
->readMiscReg(MISCREG_CANRESTORE
));
245 dest
->setMiscReg(MISCREG_OTHERWIN
, src
->readMiscReg(MISCREG_OTHERWIN
));
246 dest
->setMiscReg(MISCREG_CLEANWIN
, src
->readMiscReg(MISCREG_CLEANWIN
));
247 dest
->setMiscReg(MISCREG_WSTATE
, src
->readMiscReg(MISCREG_WSTATE
));
248 dest
->setMiscReg(MISCREG_GL
, src
->readMiscReg(MISCREG_GL
));
250 // Hyperprivilged registers
251 dest
->setMiscReg(MISCREG_HPSTATE
, src
->readMiscReg(MISCREG_HPSTATE
));
252 dest
->setMiscReg(MISCREG_HINTP
, src
->readMiscReg(MISCREG_HINTP
));
253 dest
->setMiscReg(MISCREG_HTBA
, src
->readMiscReg(MISCREG_HTBA
));
254 dest
->setMiscReg(MISCREG_STRAND_STS_REG
,
255 src
->readMiscReg(MISCREG_STRAND_STS_REG
));
256 dest
->setMiscReg(MISCREG_HSTICK_CMPR
,
257 src
->readMiscReg(MISCREG_HSTICK_CMPR
));
260 dest
->setMiscReg(MISCREG_FSR
, src
->readMiscReg(MISCREG_FSR
));
263 void SparcISA::copyRegs(ThreadContext
*src
, ThreadContext
*dest
)
265 // First loop through the integer registers.
266 for (int i
= 0; i
< TheISA::NumIntRegs
; ++i
) {
267 dest
->setIntReg(i
, src
->readIntReg(i
));
270 // Then loop through the floating point registers.
271 for (int i
= 0; i
< TheISA::NumFloatRegs
; ++i
) {
272 dest
->setFloatRegBits(i
, src
->readFloatRegBits(i
));
275 // Copy misc. registers
276 copyMiscRegs(src
, dest
);
278 // Lastly copy PC/NPC
279 dest
->setPC(src
->readPC());
280 dest
->setNextPC(src
->readNextPC());
281 dest
->setNextNPC(src
->readNextNPC());