2 * Copyright (c) 2006 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.
29 #include "arch/sparc/kernel_stats.hh"
30 #include "arch/sparc/miscregfile.hh"
31 #include "base/bitfield.hh"
32 #include "base/trace.hh"
33 #include "cpu/base.hh"
34 #include "cpu/thread_context.hh"
35 #include "sim/system.hh"
37 using namespace SparcISA
;
42 MiscRegFile::checkSoftInt(ThreadContext
*tc
)
44 BaseCPU
*cpu
= tc
->getCpuPtr();
46 // If PIL < 14, copy over the tm and sm bits
47 if (pil
< 14 && softint
& 0x10000)
48 cpu
->postInterrupt(IT_SOFT_INT
, 16);
50 cpu
->clearInterrupt(IT_SOFT_INT
, 16);
51 if (pil
< 14 && softint
& 0x1)
52 cpu
->postInterrupt(IT_SOFT_INT
, 0);
54 cpu
->clearInterrupt(IT_SOFT_INT
, 0);
56 // Copy over any of the other bits that are set
57 for (int bit
= 15; bit
> 0; --bit
) {
58 if (1 << bit
& softint
&& bit
> pil
)
59 cpu
->postInterrupt(IT_SOFT_INT
, bit
);
61 cpu
->clearInterrupt(IT_SOFT_INT
, bit
);
65 //These functions map register indices to names
67 getMiscRegName(RegIndex index
)
69 static string miscRegName
[NumMiscRegs
] =
70 {/*"y", "ccr",*/ "asi", "tick", "fprs", "pcr", "pic",
71 "gsr", "softint_set", "softint_clr", "softint", "tick_cmpr",
72 "stick", "stick_cmpr",
73 "tpc", "tnpc", "tstate", "tt", "privtick", "tba", "pstate", "tl",
74 "pil", "cwp", /*"cansave", "canrestore", "cleanwin", "otherwin",
76 "hpstate", "htstate", "hintp", "htba", "hver", "strand_sts_reg",
78 "fsr", "prictx", "secctx", "partId", "lsuCtrlReg",
79 "scratch0", "scratch1", "scratch2", "scratch3", "scratch4",
80 "scratch5", "scratch6", "scratch7", "cpuMondoHead", "cpuMondoTail",
81 "devMondoHead", "devMondoTail", "resErrorHead", "resErrorTail",
82 "nresErrorHead", "nresErrorTail", "TlbData" };
83 return miscRegName
[index
];
87 MiscRegFile::setFSReg(int miscReg
, const MiscReg
&val
, ThreadContext
*tc
)
89 BaseCPU
*cpu
= tc
->getCpuPtr();
93 /* Full system only ASRs */
95 setRegNoEffect(miscReg
, val
);;
98 case MISCREG_SOFTINT_CLR
:
99 return setReg(MISCREG_SOFTINT
, ~val
& softint
, tc
);
100 case MISCREG_SOFTINT_SET
:
101 return setReg(MISCREG_SOFTINT
, val
| softint
, tc
);
103 case MISCREG_TICK_CMPR
:
104 if (tickCompare
== NULL
)
105 tickCompare
= new TickCompareEvent(this, tc
);
106 setRegNoEffect(miscReg
, val
);
107 if ((tick_cmpr
& ~mask(63)) && tickCompare
->scheduled())
108 cpu
->deschedule(tickCompare
);
109 time
= (tick_cmpr
& mask(63)) - (tick
& mask(63));
110 if (!(tick_cmpr
& ~mask(63)) && time
> 0) {
111 if (tickCompare
->scheduled())
112 cpu
->deschedule(tickCompare
);
113 cpu
->schedule(tickCompare
, curTick
+ time
* cpu
->ticks(1));
115 panic("writing to TICK compare register %#X\n", val
);
118 case MISCREG_STICK_CMPR
:
119 if (sTickCompare
== NULL
)
120 sTickCompare
= new STickCompareEvent(this, tc
);
121 setRegNoEffect(miscReg
, val
);
122 if ((stick_cmpr
& ~mask(63)) && sTickCompare
->scheduled())
123 cpu
->deschedule(sTickCompare
);
124 time
= ((int64_t)(stick_cmpr
& mask(63)) - (int64_t)stick
) -
126 if (!(stick_cmpr
& ~mask(63)) && time
> 0) {
127 if (sTickCompare
->scheduled())
128 cpu
->deschedule(sTickCompare
);
129 cpu
->schedule(sTickCompare
, curTick
+ time
* cpu
->ticks(1));
131 DPRINTF(Timer
, "writing to sTICK compare register value %#X\n", val
);
135 setRegNoEffect(miscReg
, val
);
138 setRegNoEffect(miscReg
, val
);
143 panic("Shouldn't be writing HVER\n");
146 setRegNoEffect(miscReg
, val
);
148 cpu
->postInterrupt(IT_HINTP
, 0);
150 cpu
->clearInterrupt(IT_HINTP
, 0);
154 // clear lower 7 bits on writes.
155 setRegNoEffect(miscReg
, val
& ULL(~0x7FFF));
158 case MISCREG_QUEUE_CPU_MONDO_HEAD
:
159 case MISCREG_QUEUE_CPU_MONDO_TAIL
:
160 setRegNoEffect(miscReg
, val
);
161 if (cpu_mondo_head
!= cpu_mondo_tail
)
162 cpu
->postInterrupt(IT_CPU_MONDO
, 0);
164 cpu
->clearInterrupt(IT_CPU_MONDO
, 0);
166 case MISCREG_QUEUE_DEV_MONDO_HEAD
:
167 case MISCREG_QUEUE_DEV_MONDO_TAIL
:
168 setRegNoEffect(miscReg
, val
);
169 if (dev_mondo_head
!= dev_mondo_tail
)
170 cpu
->postInterrupt(IT_DEV_MONDO
, 0);
172 cpu
->clearInterrupt(IT_DEV_MONDO
, 0);
174 case MISCREG_QUEUE_RES_ERROR_HEAD
:
175 case MISCREG_QUEUE_RES_ERROR_TAIL
:
176 setRegNoEffect(miscReg
, val
);
177 if (res_error_head
!= res_error_tail
)
178 cpu
->postInterrupt(IT_RES_ERROR
, 0);
180 cpu
->clearInterrupt(IT_RES_ERROR
, 0);
182 case MISCREG_QUEUE_NRES_ERROR_HEAD
:
183 case MISCREG_QUEUE_NRES_ERROR_TAIL
:
184 setRegNoEffect(miscReg
, val
);
185 // This one doesn't have an interrupt to report to the guest OS
188 case MISCREG_HSTICK_CMPR
:
189 if (hSTickCompare
== NULL
)
190 hSTickCompare
= new HSTickCompareEvent(this, tc
);
191 setRegNoEffect(miscReg
, val
);
192 if ((hstick_cmpr
& ~mask(63)) && hSTickCompare
->scheduled())
193 cpu
->deschedule(hSTickCompare
);
194 time
= ((int64_t)(hstick_cmpr
& mask(63)) - (int64_t)stick
) -
196 if (!(hstick_cmpr
& ~mask(63)) && time
> 0) {
197 if (hSTickCompare
->scheduled())
198 cpu
->deschedule(hSTickCompare
);
199 cpu
->schedule(hSTickCompare
, curTick
+ time
* cpu
->ticks(1));
201 DPRINTF(Timer
, "writing to hsTICK compare register value %#X\n", val
);
204 case MISCREG_HPSTATE
:
205 // T1000 spec says impl. dependent val must always be 1
206 setRegNoEffect(miscReg
, val
| HPSTATE::id
);
208 if (hpstate
& HPSTATE::tlz
&& tl
== 0 && !(hpstate
& HPSTATE::hpriv
))
209 cpu
->postInterrupt(IT_TRAP_LEVEL_ZERO
, 0);
211 cpu
->clearInterrupt(IT_TRAP_LEVEL_ZERO
, 0);
214 case MISCREG_HTSTATE
:
215 setRegNoEffect(miscReg
, val
);
218 case MISCREG_STRAND_STS_REG
:
220 panic("No support for setting spec_en bit\n");
221 setRegNoEffect(miscReg
, bits(val
,0,0));
222 if (!bits(val
,0,0)) {
223 DPRINTF(Quiesce
, "Cpu executed quiescing instruction\n");
224 // Time to go to sleep
226 if (tc
->getKernelStats())
227 tc
->getKernelStats()->quiesce();
232 panic("Invalid write to FS misc register %s\n",
233 getMiscRegName(miscReg
));
238 MiscRegFile::readFSReg(int miscReg
, ThreadContext
* tc
)
243 /* Privileged registers. */
244 case MISCREG_QUEUE_CPU_MONDO_HEAD
:
245 case MISCREG_QUEUE_CPU_MONDO_TAIL
:
246 case MISCREG_QUEUE_DEV_MONDO_HEAD
:
247 case MISCREG_QUEUE_DEV_MONDO_TAIL
:
248 case MISCREG_QUEUE_RES_ERROR_HEAD
:
249 case MISCREG_QUEUE_RES_ERROR_TAIL
:
250 case MISCREG_QUEUE_NRES_ERROR_HEAD
:
251 case MISCREG_QUEUE_NRES_ERROR_TAIL
:
252 case MISCREG_SOFTINT
:
253 case MISCREG_TICK_CMPR
:
254 case MISCREG_STICK_CMPR
:
256 case MISCREG_HPSTATE
:
258 case MISCREG_HTSTATE
:
259 case MISCREG_HSTICK_CMPR
:
260 return readRegNoEffect(miscReg
) ;
263 return readRegNoEffect(miscReg
) & ULL(~0x7FFF);
265 // XXX set to match Legion
266 return ULL(0x3e) << 48 |
269 //MaxGL << 16 | XXX For some reason legion doesn't set GL
273 case MISCREG_STRAND_STS_REG
:
276 sys
= tc
->getSystemPtr();
278 temp
= readRegNoEffect(miscReg
) & (STS::active
| STS::speculative
);
279 // Check that the CPU array is fully populated
280 // (by calling getNumCPus())
281 assert(sys
->numContexts() > tc
->contextId());
283 temp
|= tc
->contextId() << STS::shft_id
;
285 for (x
= tc
->contextId() & ~3; x
< sys
->threadContexts
.size(); x
++) {
286 switch (sys
->threadContexts
[x
]->status()) {
287 case ThreadContext::Active
:
288 temp
|= STS::st_run
<< (STS::shft_fsm0
-
289 ((x
& 0x3) * (STS::shft_fsm0
-STS::shft_fsm1
)));
291 case ThreadContext::Suspended
:
292 // should this be idle?
293 temp
|= STS::st_idle
<< (STS::shft_fsm0
-
294 ((x
& 0x3) * (STS::shft_fsm0
-STS::shft_fsm1
)));
296 case ThreadContext::Halted
:
297 temp
|= STS::st_halt
<< (STS::shft_fsm0
-
298 ((x
& 0x3) * (STS::shft_fsm0
-STS::shft_fsm1
)));
301 panic("What state are we in?!\n");
307 panic("Invalid read to FS misc register\n");
312 MiscRegFile::processTickCompare(ThreadContext
*tc
)
314 panic("tick compare not implemented\n");
318 MiscRegFile::processSTickCompare(ThreadContext
*tc
)
320 BaseCPU
*cpu
= tc
->getCpuPtr();
322 // since our microcode instructions take two cycles we need to check if
323 // we're actually at the correct cycle or we need to wait a little while
326 ticks
= ((int64_t)(stick_cmpr
& mask(63)) - (int64_t)stick
) -
328 assert(ticks
>= 0 && "stick compare missed interrupt cycle");
330 if (ticks
== 0 || tc
->status() == ThreadContext::Suspended
) {
331 DPRINTF(Timer
, "STick compare cycle reached at %#x\n",
332 (stick_cmpr
& mask(63)));
333 if (!(tc
->readMiscRegNoEffect(MISCREG_STICK_CMPR
) & (ULL(1) << 63))) {
334 setReg(MISCREG_SOFTINT
, softint
| (ULL(1) << 16), tc
);
337 cpu
->schedule(sTickCompare
, curTick
+ ticks
* cpu
->ticks(1));
341 MiscRegFile::processHSTickCompare(ThreadContext
*tc
)
343 BaseCPU
*cpu
= tc
->getCpuPtr();
345 // since our microcode instructions take two cycles we need to check if
346 // we're actually at the correct cycle or we need to wait a little while
349 if ( tc
->status() == ThreadContext::Halted
)
352 ticks
= ((int64_t)(hstick_cmpr
& mask(63)) - (int64_t)stick
) -
354 assert(ticks
>= 0 && "hstick compare missed interrupt cycle");
356 if (ticks
== 0 || tc
->status() == ThreadContext::Suspended
) {
357 DPRINTF(Timer
, "HSTick compare cycle reached at %#x\n",
358 (stick_cmpr
& mask(63)));
359 if (!(tc
->readMiscRegNoEffect(MISCREG_HSTICK_CMPR
) & (ULL(1) << 63))) {
360 setReg(MISCREG_HINTP
, 1, tc
);
362 // Need to do something to cause interrupt to happen here !!! @todo
364 cpu
->schedule(hSTickCompare
, curTick
+ ticks
* cpu
->ticks(1));