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.
31 #include "arch/sparc/regfile.hh"
34 SparcISA::MiscRegFile::setFSRegWithEffect(int miscReg
, const MiscReg
&val
,
40 /* Full system only ASRs */
43 return new PrivilegedOpcode
;
44 // Check if we are going to interrupt because of something
45 int oldLevel
= InterruptLevel(softint
);
46 int newLevel
= InterruptLevel(val
);
48 if (newLevel
> oldLevel
)
49 ; // MUST DO SOMETHING HERE TO TELL CPU TO LOOK FOR INTERRUPTS XXX
50 //tc->getCpuPtr()->checkInterrupts = true;
53 case MISCREG_SOFTINT_CLR
:
54 return setRegWithEffect(miscReg
, ~val
& softint
, tc
);
55 case MISCREG_SOFTINT_SET
:
56 return setRegWithEffect(miscReg
, val
| softint
, tc
);
58 case MISCREG_TICK_CMPR
:
60 return new PrivilegedOpcode
;
61 if (tickCompare
== NULL
)
62 tickCompare
= new TickCompareEvent(this, tc
);
64 if (tick_cmprFields
.int_dis
&& tickCompare
.scheduled())
65 tickCompare
.deschedule();
66 time
= tick_cmprFields
.tick_cmpr
- tickFields
.counter
;
67 if (!tick_cmprFields
.int_dis
&& time
> 0)
68 tickCompare
.schedule(time
* tc
->getCpuPtr()->cycles(1));
73 return new PrivilegedOpcode
;
75 return new PrivilegedAction
;
76 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
78 sys
->sysTick
= curTick
/Clock::Int::ns
- val
& ~Bit64
;
79 stickFields
.npt
= val
& Bit64
? 1 : 0;
82 case MISCREG_STICK_CMPR
:
84 return new PrivilegedOpcode
;
85 if (sTickCompare
== NULL
)
86 sTickCompare
= new STickCompareEvent(this, tc
);
87 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
90 if (stick_cmprFields
.int_dis
&& sTickCompare
.scheduled())
91 sTickCompare
.deschedule();
92 time
= stick_cmprFields
.tick_cmpr
- sys
->sysTick
;
93 if (!stick_cmprFields
.int_dis
&& time
> 0)
94 sTickCompare
.schedule(time
* Clock::Int::ns
);
97 /* Fullsystem only Priv registers. */
100 setReg(miscReg
, val
);
101 //tc->getCpuPtr()->checkInterrupts;
102 // MUST DO SOMETHING HERE TO TELL CPU TO LOOK FOR INTERRUPTS XXX
105 panic("PIL not implemented for syscall emulation\n");
107 /* Hyper privileged registers */
108 case MISCREG_HPSTATE
:
110 setReg(miscReg
, val
);
112 case MISCREG_HTSTATE
:
114 return new IllegalInstruction
;
115 setReg(miscReg
, val
);
119 // clear lower 7 bits on writes.
120 setReg(miscReg
, val
& ULL(~0x7FFF));
123 case MISCREG_STRAND_STS_REG
:
124 setReg(miscReg
, strandStatusReg
);
126 case MISCREG_HSTICK_CMPR
:
128 return new PrivilegedOpcode
;
129 if (hSTickCompare
== NULL
)
130 hSTickCompare
= new HSTickCompareEvent(this, tc
);
131 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
133 setReg(miscReg
, val
);
134 if (hstick_cmprFields
.int_dis
&& hSTickCompare
.scheduled())
135 hSTickCompare
.deschedule();
136 int64_t time
= hstick_cmprFields
.tick_cmpr
- sys
->sysTick
;
137 if (!hstick_cmprFields
.int_dis
&& time
> 0)
138 hSTickCompare
.schedule(time
* Clock::Int::ns
);
141 return new IllegalInstruction
;
146 MiscRegFile::readFSRegWithEffect(int miscReg
, Fault
&fault
, ThreadContext
* tc
)
150 /* Privileged registers. */
151 case MISCREG_SOFTINT
:
153 fault
= new PrivilegedOpcode
;
156 return readReg(miscReg
);
157 case MISCREG_TICK_CMPR
:
159 fault
= new PrivilegedOpcode
;
162 return readReg(miscReg
);
165 if (stickFields
.npt
&& !isNonPriv()) {
166 fault
= new PrivilegedAction
;
169 sys
= dynamic_cast<SparcSystem
*>(tc
->getSystemPtr());
171 return curTick
/Clock::Int::ns
- sys
->sysTick
| stickFields
.npt
<< 63;
172 case MISCREG_STICK_CMPR
:
174 fault
= new PrivilegedOpcode
;
177 return readReg(miscReg
);
180 /* Hyper privileged registers */
181 case MISCREG_HPSTATE
:
183 return readReg(miscReg
);
184 case MISCREG_HTSTATE
:
186 fault
= new IllegalInstruction
;
189 return readReg(miscReg
);
192 return readReg(miscReg
) & ULL(~0x7FFF);
194 return NWindows
| MaxTL
<< 8 | MaxGL
<< 16;
195 case MISCREG_STRAND_STS_REG
:
196 return strandStatusReg
;
197 case MISCREG_HSTICK_CMPR
:
201 fault
= new IllegalInstruction
;
207 MiscRegFile::processTickCompare(ThreadContext
*tc
)
209 panic("tick compare not implemented\n");
213 MiscRegFile::processSTickCompare(ThreadContext
*tc
)
215 panic("tick compare not implemented\n");
219 MiscRegFile::processHSTickCompare(ThreadContext
*tc
)
221 panic("tick compare not implemented\n");
224 }; // namespace SparcISA