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/bitfield.hh"
34 #include "base/trace.hh"
35 #include "config/full_system.hh"
36 #include "cpu/base.hh"
37 #include "cpu/thread_context.hh"
40 #include "arch/sparc/system.hh"
43 using namespace SparcISA
;
48 //These functions map register indices to names
49 string
SparcISA::getMiscRegName(RegIndex index
)
51 static::string miscRegName
[NumMiscRegs
] =
52 {"y", "ccr", "asi", "tick", "pc", "fprs", "pcr", "pic",
53 "gsr", "softint_set", "softint_clr", "softint", "tick_cmpr",
54 "stick", "stick_cmpr",
55 "tpc", "tnpc", "tstate", "tt", "privtick", "tba", "pstate", "tl",
56 "pil", "cwp", "cansave", "canrestore", "cleanwin", "otherwin",
58 "hpstate", "htstate", "hintp", "htba", "hver", "strand_sts_reg",
61 return miscRegName
[index
];
64 void MiscRegFile::reset()
68 MiscReg
MiscRegFile::readReg(int miscReg
)
82 panic("PCR not implemented\n");
84 panic("PIC not implemented\n");
89 case MISCREG_TICK_CMPR
:
93 case MISCREG_STICK_CMPR
:
96 /** Privilged Registers */
105 case MISCREG_PRIVTICK
:
106 panic("Priviliged access to tick registers not implemented\n");
117 case MISCREG_CANSAVE
:
119 case MISCREG_CANRESTORE
:
121 case MISCREG_CLEANWIN
:
123 case MISCREG_OTHERWIN
:
130 /** Hyper privileged registers */
131 case MISCREG_HPSTATE
:
133 case MISCREG_HTSTATE
:
134 return htstate
[tl
-1];
136 panic("HINTP not implemented\n");
140 return NWindows
| MaxTL
<< 8 | MaxGL
<< 16;
141 case MISCREG_STRAND_STS_REG
:
142 return strandStatusReg
;
143 case MISCREG_HSTICK_CMPR
:
146 /** Floating Point Status Register */
150 panic("Miscellaneous register %d not implemented\n", miscReg
);
154 MiscReg
MiscRegFile::readRegWithEffect(int miscReg
, ThreadContext
* tc
)
158 case MISCREG_PRIVTICK
:
159 return tc
->getCpuPtr()->curCycle() - (tick
& mask(63)) |
160 (tick
& ~(mask(63))) << 63;
162 panic("FPU not implemented\n");
165 panic("Performance Instrumentation not impl\n");
166 /** Floating Point Status Register */
168 panic("Floating Point not implemented\n");
169 //We'll include this only in FS so we don't need the SparcSystem type around
174 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
176 return curTick
/Clock::Int::ns
- sys
->sysTick
| (stick
& ~(mask(63)));
179 return NWindows
| MaxTL
<< 8 | MaxGL
<< 16;
181 return readReg(miscReg
);
184 void MiscRegFile::setReg(int miscReg
, const MiscReg
&val
)
203 panic("PCR not implemented\n");
205 panic("PIC not implemented\n");
209 case MISCREG_SOFTINT
:
212 case MISCREG_TICK_CMPR
:
218 case MISCREG_STICK_CMPR
:
222 /** Privilged Registers */
235 case MISCREG_PRIVTICK
:
236 panic("Priviliged access to tick regesiters not implemented\n");
238 // clear lower 7 bits on writes.
239 tba
= val
& ULL(~0x7FFF);
253 case MISCREG_CANSAVE
:
256 case MISCREG_CANRESTORE
:
259 case MISCREG_CLEANWIN
:
262 case MISCREG_OTHERWIN
:
272 /** Hyper privileged registers */
273 case MISCREG_HPSTATE
:
276 case MISCREG_HTSTATE
:
280 panic("HINTP not implemented\n");
284 case MISCREG_STRAND_STS_REG
:
285 strandStatusReg
= val
;
287 case MISCREG_HSTICK_CMPR
:
291 /** Floating Point Status Register */
296 panic("Miscellaneous register %d not implemented\n", miscReg
);
300 inline void MiscRegFile::setImplicitAsis()
302 //The spec seems to use trap level to indicate the privilege level of the
303 //processor. It's unclear whether the implicit ASIs should directly depend
304 //on the trap level, or if they should really be based on the privelege
308 implicitInstAsi
= implicitDataAsi
=
309 (pstate
& (1 << 9)) ? ASI_PRIMARY_LITTLE
: ASI_PRIMARY
;
311 else if(tl
<= MaxPTL
)
313 implicitInstAsi
= ASI_NUCLEUS
;
314 implicitDataAsi
= (pstate
& (1 << 9)) ? ASI_NUCLEUS_LITTLE
: ASI_NUCLEUS
;
318 //This is supposed to force physical addresses to match the spec.
319 //It might not because of context values and partition values.
320 implicitInstAsi
= implicitDataAsi
= ASI_REAL
;
324 void MiscRegFile::setRegWithEffect(int miscReg
,
325 const MiscReg
&val
, ThreadContext
* tc
)
327 const uint64_t Bit64
= (1ULL << 63);
334 tick
= tc
->getCpuPtr()->curCycle() - val
& ~Bit64
;
338 //Configure the fpu based on the fprs
341 //Set up performance counting based on pcr value
352 tc
->changeRegFileContext(CONTEXT_CWP
, val
);
355 tc
->changeRegFileContext(CONTEXT_GLOBALS
, val
);
357 case MISCREG_SOFTINT
:
358 //We need to inject interrupts, and or notify the interrupt
359 //object that it needs to use a different interrupt level.
360 //Any newly appropriate interrupts will happen when the cpu gets
361 //around to checking for them. This might not be quite what we
364 case MISCREG_SOFTINT_CLR
:
365 //Do whatever this is supposed to do...
367 case MISCREG_SOFTINT_SET
:
368 //Do whatever this is supposed to do...
371 case MISCREG_TICK_CMPR
:
372 if (tickCompare
== NULL
)
373 tickCompare
= new TickCompareEvent(this, tc
);
374 setReg(miscReg
, val
);
375 if ((tick_cmpr
& mask(63)) && tickCompare
->scheduled())
376 tickCompare
->deschedule();
377 time
= (tick_cmpr
& mask(63)) - (tick
& mask(63));
378 if (!(tick_cmpr
& ~mask(63)) && time
> 0)
379 tickCompare
->schedule(time
* tc
->getCpuPtr()->cycles(1));
383 //We need to inject interrupts, and or notify the interrupt
384 //object that it needs to use a different interrupt level.
385 //Any newly appropriate interrupts will happen when the cpu gets
386 //around to checking for them. This might not be quite what we
389 //We'll include this only in FS so we don't need the SparcSystem type around
393 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
395 sys
->sysTick
= curTick
/Clock::Int::ns
- val
& ~Bit64
;
396 stick
|= val
& Bit64
;
398 case MISCREG_STICK_CMPR
:
399 if (sTickCompare
== NULL
)
400 sTickCompare
= new STickCompareEvent(this, tc
);
401 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
403 if ((stick_cmpr
& ~mask(63)) && sTickCompare
->scheduled())
404 sTickCompare
->deschedule();
405 time
= (stick_cmpr
& mask(63)) - sys
->sysTick
;
406 if (!(stick_cmpr
& ~mask(63)) && time
> 0)
407 sTickCompare
->schedule(time
* Clock::Int::ns
);
409 case MISCREG_HSTICK_CMPR
:
410 if (hSTickCompare
== NULL
)
411 hSTickCompare
= new HSTickCompareEvent(this, tc
);
412 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
414 if ((hstick_cmpr
& ~mask(63)) && hSTickCompare
->scheduled())
415 hSTickCompare
->deschedule();
416 int64_t time
= (hstick_cmpr
& mask(63)) - sys
->sysTick
;
417 if (!(hstick_cmpr
& ~mask(63)) && time
> 0)
418 hSTickCompare
->schedule(time
* Clock::Int::ns
);
422 setReg(miscReg
, val
);
425 void MiscRegFile::serialize(std::ostream
& os
)
427 SERIALIZE_SCALAR(pstate
);
428 SERIALIZE_SCALAR(tba
);
430 SERIALIZE_SCALAR(pil
);
431 SERIALIZE_SCALAR(gl
);
432 SERIALIZE_SCALAR(cwp
);
433 SERIALIZE_ARRAY(tt
, MaxTL
);
434 SERIALIZE_SCALAR(ccr
);
435 SERIALIZE_SCALAR(asi
);
436 SERIALIZE_SCALAR(tl
);
437 SERIALIZE_ARRAY(tpc
, MaxTL
);
438 SERIALIZE_ARRAY(tnpc
, MaxTL
);
439 SERIALIZE_ARRAY(tstate
, MaxTL
);
440 SERIALIZE_SCALAR(tick
);
441 SERIALIZE_SCALAR(cansave
);
442 SERIALIZE_SCALAR(canrestore
);
443 SERIALIZE_SCALAR(otherwin
);
444 SERIALIZE_SCALAR(cleanwin
);
445 SERIALIZE_SCALAR(wstate
);
446 SERIALIZE_SCALAR(fsr
);
447 SERIALIZE_SCALAR(fprs
);
448 SERIALIZE_SCALAR(hpstate
);
449 SERIALIZE_ARRAY(htstate
, MaxTL
);
450 SERIALIZE_SCALAR(htba
);
451 SERIALIZE_SCALAR(hstick_cmpr
);
452 SERIALIZE_SCALAR((int)implicitInstAsi
);
453 SERIALIZE_SCALAR((int)implicitDataAsi
);
456 void MiscRegFile::unserialize(Checkpoint
* cp
, const std::string
& section
)
458 UNSERIALIZE_SCALAR(pstate
);
459 UNSERIALIZE_SCALAR(tba
);
460 UNSERIALIZE_SCALAR(y
);
461 UNSERIALIZE_SCALAR(pil
);
462 UNSERIALIZE_SCALAR(gl
);
463 UNSERIALIZE_SCALAR(cwp
);
464 UNSERIALIZE_ARRAY(tt
, MaxTL
);
465 UNSERIALIZE_SCALAR(ccr
);
466 UNSERIALIZE_SCALAR(asi
);
467 UNSERIALIZE_SCALAR(tl
);
468 UNSERIALIZE_ARRAY(tpc
, MaxTL
);
469 UNSERIALIZE_ARRAY(tnpc
, MaxTL
);
470 UNSERIALIZE_ARRAY(tstate
, MaxTL
);
471 UNSERIALIZE_SCALAR(tick
);
472 UNSERIALIZE_SCALAR(cansave
);
473 UNSERIALIZE_SCALAR(canrestore
);
474 UNSERIALIZE_SCALAR(otherwin
);
475 UNSERIALIZE_SCALAR(cleanwin
);
476 UNSERIALIZE_SCALAR(wstate
);
477 UNSERIALIZE_SCALAR(fsr
);
478 UNSERIALIZE_SCALAR(fprs
);
479 UNSERIALIZE_SCALAR(hpstate
);
480 UNSERIALIZE_ARRAY(htstate
, MaxTL
);
481 UNSERIALIZE_SCALAR(htba
);
482 UNSERIALIZE_SCALAR(hstick_cmpr
);
484 UNSERIALIZE_SCALAR(temp
);
485 implicitInstAsi
= (ASI
)temp
;
486 UNSERIALIZE_SCALAR(temp
);
487 implicitDataAsi
= (ASI
)temp
;
492 MiscRegFile::processTickCompare(ThreadContext
*tc
)
494 panic("tick compare not implemented\n");
498 MiscRegFile::processSTickCompare(ThreadContext
*tc
)
500 panic("tick compare not implemented\n");
504 MiscRegFile::processHSTickCompare(ThreadContext
*tc
)
506 panic("tick compare not implemented\n");