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.
32 #ifndef __ARCH_SPARC_INTERRUPT_HH__
33 #define __ARCH_SPARC_INTERRUPT_HH__
35 #include "arch/sparc/faults.hh"
36 #include "arch/sparc/isa_traits.hh"
37 #include "arch/sparc/registers.hh"
38 #include "cpu/thread_context.hh"
39 #include "debug/Interrupt.hh"
40 #include "params/SparcInterrupts.hh"
41 #include "sim/sim_object.hh"
46 class Interrupts : public SimObject
51 uint64_t interrupts[NumInterruptTypes];
57 setCPU(BaseCPU * _cpu)
62 typedef SparcInterruptsParams Params;
67 return dynamic_cast<const Params *>(_params);
70 Interrupts(Params * p) : SimObject(p), cpu(NULL)
76 InterruptLevel(uint64_t softint)
78 if (softint & 0x10000 || softint & 0x1)
82 while (level > 0 && !(1 << level & softint))
84 if (1 << level & softint)
90 post(int int_num, int index)
92 DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
93 assert(int_num >= 0 && int_num < NumInterruptTypes);
94 assert(index >= 0 && index < 64);
96 interrupts[int_num] |= ULL(1) << index;
97 intStatus |= ULL(1) << int_num;
101 clear(int int_num, int index)
103 DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
104 assert(int_num >= 0 && int_num < NumInterruptTypes);
105 assert(index >= 0 && index < 64);
107 interrupts[int_num] &= ~(ULL(1) << index);
108 if (!interrupts[int_num])
109 intStatus &= ~(ULL(1) << int_num);
115 for (int i = 0; i < NumInterruptTypes; ++i) {
122 checkInterrupts(ThreadContext *tc) const
127 HPSTATE hpstate = tc->readMiscRegNoEffect(MISCREG_HPSTATE);
128 PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
130 // THESE ARE IN ORDER OF PRIORITY
131 // since there are early returns, and the highest
132 // priority interrupts should get serviced,
133 // it is v. important that new interrupts are inserted
134 // in the right order of processing
137 if (interrupts[IT_HINTP]) {
138 // This will be cleaned by a HINTP write
141 if (interrupts[IT_INT_VEC]) {
142 // this will be cleared by an ASI read (or write)
147 if (interrupts[IT_TRAP_LEVEL_ZERO]) {
148 // this is cleared by deasserting HPSTATE::tlz
151 // HStick matches always happen in priv mode (ie doesn't matter)
152 if (interrupts[IT_HINTP]) {
155 if (interrupts[IT_INT_VEC]) {
156 // this will be cleared by an ASI read (or write)
160 if (interrupts[IT_CPU_MONDO]) {
163 if (interrupts[IT_DEV_MONDO]) {
166 if (interrupts[IT_SOFT_INT]) {
170 if (interrupts[IT_RES_ERROR]) {
173 } // !hpriv && pstate.ie
180 getInterrupt(ThreadContext *tc)
182 assert(checkInterrupts(tc));
184 HPSTATE hpstate = tc->readMiscRegNoEffect(MISCREG_HPSTATE);
185 PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
187 // THESE ARE IN ORDER OF PRIORITY
188 // since there are early returns, and the highest
189 // priority interrupts should get serviced,
190 // it is v. important that new interrupts are inserted
191 // in the right order of processing
194 if (interrupts[IT_HINTP]) {
195 // This will be cleaned by a HINTP write
196 return std::make_shared<HstickMatch>();
198 if (interrupts[IT_INT_VEC]) {
199 // this will be cleared by an ASI read (or write)
200 return std::make_shared<InterruptVector>();
204 if (interrupts[IT_TRAP_LEVEL_ZERO]) {
205 // this is cleared by deasserting HPSTATE::tlz
206 return std::make_shared<TrapLevelZero>();
208 // HStick matches always happen in priv mode (ie doesn't matter)
209 if (interrupts[IT_HINTP]) {
210 return std::make_shared<HstickMatch>();
212 if (interrupts[IT_INT_VEC]) {
213 // this will be cleared by an ASI read (or write)
214 return std::make_shared<InterruptVector>();
217 if (interrupts[IT_CPU_MONDO]) {
218 return std::make_shared<CpuMondo>();
220 if (interrupts[IT_DEV_MONDO]) {
221 return std::make_shared<DevMondo>();
223 if (interrupts[IT_SOFT_INT]) {
224 int level = InterruptLevel(interrupts[IT_SOFT_INT]);
225 return std::make_shared<InterruptLevelN>(level);
228 if (interrupts[IT_RES_ERROR]) {
229 return std::make_shared<ResumableError>();
231 } // !hpriv && pstate.ie
237 updateIntrInfo(ThreadContext *tc)
243 assert(int_num >= 0 && int_num < NumInterruptTypes);
244 return interrupts[int_num];
248 serialize(CheckpointOut &cp) const override
250 SERIALIZE_ARRAY(interrupts,NumInterruptTypes);
251 SERIALIZE_SCALAR(intStatus);
255 unserialize(CheckpointIn &cp) override
257 UNSERIALIZE_ARRAY(interrupts,NumInterruptTypes);
258 UNSERIALIZE_SCALAR(intStatus);
261 } // namespace SPARC_ISA
263 #endif // __ARCH_SPARC_INTERRUPT_HH__