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/miscregfile.hh"
33 #include "base/trace.hh"
34 #include "cpu/base.hh"
35 #include "cpu/thread_context.hh"
37 using namespace SparcISA
;
42 //These functions map register indices to names
43 string
SparcISA::getMiscRegName(RegIndex index
)
45 static::string miscRegName
[NumMiscRegs
] =
46 {"y", "ccr", "asi", "tick", "pc", "fprs", "pcr", "pic",
47 "gsr", "softint_set", "softint_clr", "softint", "tick_cmpr",
48 "stick", "stick_cmpr",
49 "tpc", "tnpc", "tstate", "tt", "privtick", "tba", "pstate", "tl",
50 "pil", "cwp", "cansave", "canrestore", "cleanwin", "otherwin",
52 "hpstate", "htstate", "hintp", "htba", "hver", "strand_sts_reg",
55 return miscRegName
[index
];
60 //XXX These need an implementation someplace
61 /** Fullsystem only register version of ReadRegWithEffect() */
62 MiscReg
MiscRegFile::readFSRegWithEffect(int miscReg
, Fault
&fault
, ThreadContext
*tc
);
63 /** Fullsystem only register version of SetRegWithEffect() */
64 Fault
MiscRegFile::setFSRegWithEffect(int miscReg
, const MiscReg
&val
,
68 void MiscRegFile::reset()
70 pstateFields
.pef
= 0; //No FPU
71 //pstateFields.pef = 1; //FPU
73 //For SPARC, when a system is first started, there is a power
74 //on reset Trap which sets the processor into the following state.
75 //Bits that aren't set aren't defined on startup.
79 tickFields
.counter
= 0; //The TICK register is unreadable bya
80 tickFields
.npt
= 1; //The TICK register is unreadable by by !priv
82 softint
= 0; // Clear all the soft interrupt bits
83 tick_cmprFields
.int_dis
= 1; // disable timer compare interrupts
84 tick_cmprFields
.tick_cmpr
= 0; // Reset to 0 for pretty printing
85 stickFields
.npt
= 1; //The TICK register is unreadable by by !priv
86 stick_cmprFields
.int_dis
= 1; // disable timer compare interrupts
87 stick_cmprFields
.tick_cmpr
= 0; // Reset to 0 for pretty printing
90 tt
[tl
] = power_on_reset
;
91 pstate
= 0; // fields 0 but pef
95 hpstateFields
.red
= 1;
96 hpstateFields
.hpriv
= 1;
97 hpstateFields
.tlz
= 0; // this is a guess
98 hintp
= 0; // no interrupts pending
99 hstick_cmprFields
.int_dis
= 1; // disable timer compare interrupts
100 hstick_cmprFields
.tick_cmpr
= 0; // Reset to 0 for pretty printing
102 /* //This sets up the initial state of the processor for usermode processes
103 pstateFields.priv = 0; //Process runs in user mode
104 pstateFields.ie = 1; //Interrupts are enabled
105 fsrFields.rd = 0; //Round to nearest
106 fsrFields.tem = 0; //Floating point traps not enabled
107 fsrFields.ns = 0; //Non standard mode off
108 fsrFields.qne = 0; //Floating point queue is empty
109 fsrFields.aexc = 0; //No accrued exceptions
110 fsrFields.cexc = 0; //No current exceptions
112 //Register window management registers
113 otherwin = 0; //No windows contain info from other programs
114 canrestore = 0; //There are no windows to pop
115 cansave = MaxTL - 2; //All windows are available to save into
120 MiscReg
MiscRegFile::readReg(int miscReg
)
135 panic("ASR number %d not implemented\n", miscReg
- AsrStart
);
138 case MISCREG_SOFTINT
:
140 case MISCREG_TICK_CMPR
:
144 case MISCREG_STICK_CMPR
:
147 /** Privilged Registers */
156 case MISCREG_PRIVTICK
:
157 panic("Priviliged access to tick registers not implemented\n");
168 case MISCREG_CANSAVE
:
170 case MISCREG_CANRESTORE
:
172 case MISCREG_CLEANWIN
:
174 case MISCREG_OTHERWIN
:
181 /** Hyper privileged registers */
182 case MISCREG_HPSTATE
:
184 case MISCREG_HTSTATE
:
185 return htstate
[tl
-1];
187 panic("HINTP not implemented\n");
191 return NWindows
| MaxTL
<< 8 | MaxGL
<< 16;
192 case MISCREG_STRAND_STS_REG
:
193 return strandStatusReg
;
194 case MISCREG_HSTICK_CMPR
:
197 /** Floating Point Status Register */
201 panic("Miscellaneous register %d not implemented\n", miscReg
);
205 MiscReg
MiscRegFile::readRegWithEffect(int miscReg
, ThreadContext
* tc
)
209 case MISCREG_PRIVTICK
:
210 return tc
->getCpuPtr()->curCycle() - tickFields
.counter
|
211 tickFields
.npt
<< 63;
213 panic("FPU not implemented\n");
216 panic("Performance Instrumentation not impl\n");
218 /** Floating Point Status Register */
220 panic("Floating Point not implemented\n");
222 return readReg(miscReg
);
225 void MiscRegFile::setReg(int miscReg
, const MiscReg
&val
)
245 panic("ASR number %d not implemented\n", miscReg
- AsrStart
);
249 case MISCREG_SOFTINT
:
252 case MISCREG_TICK_CMPR
:
258 case MISCREG_STICK_CMPR
:
262 /** Privilged Registers */
275 case MISCREG_PRIVTICK
:
276 panic("Priviliged access to tick regesiters not implemented\n");
278 // clear lower 7 bits on writes.
279 tba
= val
& ULL(~0x7FFF);
293 case MISCREG_CANSAVE
:
296 case MISCREG_CANRESTORE
:
299 case MISCREG_CLEANWIN
:
302 case MISCREG_OTHERWIN
:
312 /** Hyper privileged registers */
313 case MISCREG_HPSTATE
:
316 case MISCREG_HTSTATE
:
320 panic("HINTP not implemented\n");
324 case MISCREG_STRAND_STS_REG
:
325 strandStatusReg
= val
;
327 case MISCREG_HSTICK_CMPR
:
331 /** Floating Point Status Register */
336 panic("Miscellaneous register %d not implemented\n", miscReg
);
340 void MiscRegFile::setRegWithEffect(int miscReg
,
341 const MiscReg
&val
, ThreadContext
* tc
)
343 const uint64_t Bit64
= (1ULL << 63);
346 tickFields
.counter
= tc
->getCpuPtr()->curCycle() - val
& ~Bit64
;
347 tickFields
.npt
= val
& Bit64
? 1 : 0;
350 //Configure the fpu based on the fprs
353 //Set up performance counting based on pcr value
356 tc
->changeRegFileContext(CONTEXT_CWP
, val
);
359 tc
->changeRegFileContext(CONTEXT_GLOBALS
, val
);
362 setReg(miscReg
, val
);
365 void MiscRegFile::serialize(std::ostream
& os
)
367 SERIALIZE_SCALAR(pstate
);
368 SERIALIZE_SCALAR(tba
);
370 SERIALIZE_SCALAR(pil
);
371 SERIALIZE_SCALAR(gl
);
372 SERIALIZE_SCALAR(cwp
);
373 SERIALIZE_ARRAY(tt
, MaxTL
);
374 SERIALIZE_SCALAR(ccr
);
375 SERIALIZE_SCALAR(asi
);
376 SERIALIZE_SCALAR(tl
);
377 SERIALIZE_ARRAY(tpc
, MaxTL
);
378 SERIALIZE_ARRAY(tnpc
, MaxTL
);
379 SERIALIZE_ARRAY(tstate
, MaxTL
);
380 SERIALIZE_SCALAR(tick
);
381 SERIALIZE_SCALAR(cansave
);
382 SERIALIZE_SCALAR(canrestore
);
383 SERIALIZE_SCALAR(otherwin
);
384 SERIALIZE_SCALAR(cleanwin
);
385 SERIALIZE_SCALAR(wstate
);
386 SERIALIZE_SCALAR(fsr
);
387 SERIALIZE_SCALAR(fprs
);
388 SERIALIZE_SCALAR(hpstate
);
389 SERIALIZE_ARRAY(htstate
, MaxTL
);
390 SERIALIZE_SCALAR(htba
);
391 SERIALIZE_SCALAR(hstick_cmpr
);
394 void MiscRegFile::unserialize(Checkpoint
* cp
, const std::string
& section
)
396 UNSERIALIZE_SCALAR(pstate
);
397 UNSERIALIZE_SCALAR(tba
);
398 UNSERIALIZE_SCALAR(y
);
399 UNSERIALIZE_SCALAR(pil
);
400 UNSERIALIZE_SCALAR(gl
);
401 UNSERIALIZE_SCALAR(cwp
);
402 UNSERIALIZE_ARRAY(tt
, MaxTL
);
403 UNSERIALIZE_SCALAR(ccr
);
404 UNSERIALIZE_SCALAR(asi
);
405 UNSERIALIZE_SCALAR(tl
);
406 UNSERIALIZE_ARRAY(tpc
, MaxTL
);
407 UNSERIALIZE_ARRAY(tnpc
, MaxTL
);
408 UNSERIALIZE_ARRAY(tstate
, MaxTL
);
409 UNSERIALIZE_SCALAR(tick
);
410 UNSERIALIZE_SCALAR(cansave
);
411 UNSERIALIZE_SCALAR(canrestore
);
412 UNSERIALIZE_SCALAR(otherwin
);
413 UNSERIALIZE_SCALAR(cleanwin
);
414 UNSERIALIZE_SCALAR(wstate
);
415 UNSERIALIZE_SCALAR(fsr
);
416 UNSERIALIZE_SCALAR(fprs
);
417 UNSERIALIZE_SCALAR(hpstate
);
418 UNSERIALIZE_ARRAY(htstate
, MaxTL
);
419 UNSERIALIZE_SCALAR(htba
);
420 UNSERIALIZE_SCALAR(hstick_cmpr
);