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
,
206 Fault
&fault
, ThreadContext
* tc
)
213 return readReg(miscReg
);
216 case MISCREG_PRIVTICK
:
217 // Check for reading privilege
218 if (tickFields
.npt
&& !isNonPriv()) {
219 fault
= new PrivilegedAction
;
222 return tc
->getCpuPtr()->curCycle() - tickFields
.counter
|
223 tickFields
.npt
<< 63;
227 fault
= new UnimpFault("FPU not implemented\n");
230 fault
= new UnimpFault("Performance Instrumentation not impl\n");
233 fault
= new UnimpFault("Performance Instrumentation not impl\n");
236 return readReg(miscReg
);
238 /** Privilged Registers */
244 fault
= new IllegalInstruction
;
246 } // NOTE THE FALL THROUGH!
249 return readReg(miscReg
);
252 return readReg(miscReg
) & ULL(~0x7FFF);
257 case MISCREG_CANSAVE
:
258 case MISCREG_CANRESTORE
:
259 case MISCREG_CLEANWIN
:
260 case MISCREG_OTHERWIN
:
263 return readReg(miscReg
);
265 /** Floating Point Status Register */
267 panic("Floating Point not implemented\n");
270 return readFSRegWithEffect(miscReg
, fault
, tc
);
272 fault
= new IllegalInstruction
;
278 Fault
MiscRegFile::setReg(int miscReg
, const MiscReg
&val
)
298 panic("ASR number %d not implemented\n", miscReg
- AsrStart
);
301 case MISCREG_SOFTINT
:
304 case MISCREG_TICK_CMPR
:
310 case MISCREG_STICK_CMPR
:
314 /** Privilged Registers */
327 case MISCREG_PRIVTICK
:
328 panic("Priviliged access to tick regesiters not implemented\n");
344 case MISCREG_CANSAVE
:
347 case MISCREG_CANRESTORE
:
350 case MISCREG_CLEANWIN
:
353 case MISCREG_OTHERWIN
:
363 /** Hyper privileged registers */
364 case MISCREG_HPSTATE
:
367 case MISCREG_HTSTATE
:
371 panic("HINTP not implemented\n");
375 case MISCREG_STRAND_STS_REG
:
376 strandStatusReg
= val
;
378 case MISCREG_HSTICK_CMPR
:
382 /** Floating Point Status Register */
387 panic("Miscellaneous register %d not implemented\n", miscReg
);
391 Fault
MiscRegFile::setRegWithEffect(int miscReg
,
392 const MiscReg
&val
, ThreadContext
* tc
)
394 const uint64_t Bit64
= (1ULL << 63);
399 setReg(miscReg
, val
);
401 case MISCREG_PRIVTICK
:
404 return new PrivilegedOpcode
;
406 return new PrivilegedAction
;
407 tickFields
.counter
= tc
->getCpuPtr()->curCycle() - val
& ~Bit64
;
408 tickFields
.npt
= val
& Bit64
? 1 : 0;
411 return new IllegalInstruction
;
413 return new UnimpFault("FPU not implemented\n");
415 return new UnimpFault("Performance Instrumentation not impl\n");
417 return new UnimpFault("Performance Instrumentation not impl\n");
419 return setReg(miscReg
, val
);
421 /** Privilged Registers */
427 return new IllegalInstruction
;
428 setReg(miscReg
, val
);
432 // clear lower 7 bits on writes.
433 setReg(miscReg
, val
& ULL(~0x7FFF));
437 setReg(miscReg
, val
);
441 if (isHyperPriv() && val
> MaxTL
)
442 setReg(miscReg
, MaxTL
);
443 else if (isPriv() && !isHyperPriv() && val
> MaxPTL
)
444 setReg(miscReg
, MaxPTL
);
446 setReg(miscReg
, val
);
450 tc
->changeRegFileContext(CONTEXT_CWP
, val
);
451 case MISCREG_CANSAVE
:
452 case MISCREG_CANRESTORE
:
453 case MISCREG_CLEANWIN
:
454 case MISCREG_OTHERWIN
:
456 setReg(miscReg
, val
);
461 if (isHyperPriv() && val
> MaxGL
)
463 else if (isPriv() && !isHyperPriv() && val
> MaxPGL
)
467 tc
->changeRegFileContext(CONTEXT_GLOBALS
, newval
);
468 setReg(miscReg
, newval
);
471 /** Floating Point Status Register */
473 panic("Floating Point not implemented\n");
476 setFSRegWithEffect(miscReg
, val
, tc
);
478 return new IllegalInstruction
;
483 void MiscRegFile::serialize(std::ostream
& os
)
485 SERIALIZE_SCALAR(pstate
);
486 SERIALIZE_SCALAR(tba
);
488 SERIALIZE_SCALAR(pil
);
489 SERIALIZE_SCALAR(gl
);
490 SERIALIZE_SCALAR(cwp
);
491 SERIALIZE_ARRAY(tt
, MaxTL
);
492 SERIALIZE_SCALAR(ccr
);
493 SERIALIZE_SCALAR(asi
);
494 SERIALIZE_SCALAR(tl
);
495 SERIALIZE_ARRAY(tpc
, MaxTL
);
496 SERIALIZE_ARRAY(tnpc
, MaxTL
);
497 SERIALIZE_ARRAY(tstate
, MaxTL
);
498 SERIALIZE_SCALAR(tick
);
499 SERIALIZE_SCALAR(cansave
);
500 SERIALIZE_SCALAR(canrestore
);
501 SERIALIZE_SCALAR(otherwin
);
502 SERIALIZE_SCALAR(cleanwin
);
503 SERIALIZE_SCALAR(wstate
);
504 SERIALIZE_SCALAR(fsr
);
505 SERIALIZE_SCALAR(fprs
);
506 SERIALIZE_SCALAR(hpstate
);
507 SERIALIZE_ARRAY(htstate
, MaxTL
);
508 SERIALIZE_SCALAR(htba
);
509 SERIALIZE_SCALAR(hstick_cmpr
);
512 void MiscRegFile::unserialize(Checkpoint
* cp
, const std::string
& section
)
514 UNSERIALIZE_SCALAR(pstate
);
515 UNSERIALIZE_SCALAR(tba
);
516 UNSERIALIZE_SCALAR(y
);
517 UNSERIALIZE_SCALAR(pil
);
518 UNSERIALIZE_SCALAR(gl
);
519 UNSERIALIZE_SCALAR(cwp
);
520 UNSERIALIZE_ARRAY(tt
, MaxTL
);
521 UNSERIALIZE_SCALAR(ccr
);
522 UNSERIALIZE_SCALAR(asi
);
523 UNSERIALIZE_SCALAR(tl
);
524 UNSERIALIZE_ARRAY(tpc
, MaxTL
);
525 UNSERIALIZE_ARRAY(tnpc
, MaxTL
);
526 UNSERIALIZE_ARRAY(tstate
, MaxTL
);
527 UNSERIALIZE_SCALAR(tick
);
528 UNSERIALIZE_SCALAR(cansave
);
529 UNSERIALIZE_SCALAR(canrestore
);
530 UNSERIALIZE_SCALAR(otherwin
);
531 UNSERIALIZE_SCALAR(cleanwin
);
532 UNSERIALIZE_SCALAR(wstate
);
533 UNSERIALIZE_SCALAR(fsr
);
534 UNSERIALIZE_SCALAR(fprs
);
535 UNSERIALIZE_SCALAR(hpstate
);
536 UNSERIALIZE_ARRAY(htstate
, MaxTL
);
537 UNSERIALIZE_SCALAR(htba
);
538 UNSERIALIZE_SCALAR(hstick_cmpr
);