gem5 v24.0.0.0
Loading...
Searching...
No Matches
interrupts.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 */
28
29#ifndef __ARCH_SPARC_INTERRUPT_HH__
30#define __ARCH_SPARC_INTERRUPT_HH__
31
33#include "arch/sparc/faults.hh"
35#include "cpu/thread_context.hh"
36#include "debug/Interrupt.hh"
37#include "params/SparcInterrupts.hh"
38#include "sim/sim_object.hh"
39
40namespace gem5
41{
42
43namespace SparcISA
44{
45
57
59{
60 private:
62 uint64_t intStatus;
63
64 public:
65
66 using Params = SparcInterruptsParams;
67
69 {
70 clearAll();
71 }
72
73 int
74 InterruptLevel(uint64_t softint)
75 {
76 if (softint & 0x10000 || softint & 0x1)
77 return 14;
78
79 int level = 15;
80 while (level > 0 && !(1 << level & softint))
81 level--;
82 if (1 << level & softint)
83 return level;
84 return 0;
85 }
86
87 void
88 post(int int_num, int index) override
89 {
90 DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
91 assert(int_num >= 0 && int_num < NumInterruptTypes);
92 assert(index >= 0 && index < 64);
93
94 interrupts[int_num] |= 1ULL << index;
95 intStatus |= 1ULL << int_num;
96 }
97
98 void
99 clear(int int_num, int index) override
100 {
101 DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
102 assert(int_num >= 0 && int_num < NumInterruptTypes);
103 assert(index >= 0 && index < 64);
104
105 interrupts[int_num] &= ~(1ULL << index);
106 if (!interrupts[int_num])
107 intStatus &= ~(1ULL << int_num);
108 }
109
110 void
111 clearAll() override
112 {
113 for (int i = 0; i < NumInterruptTypes; ++i) {
114 interrupts[i] = 0;
115 }
116 intStatus = 0;
117 }
118
119 bool
120 checkInterrupts() const override
121 {
122 if (!intStatus)
123 return false;
124
125 HPSTATE hpstate = tc->readMiscRegNoEffect(MISCREG_HPSTATE);
126 PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
127
128 // THESE ARE IN ORDER OF PRIORITY
129 // since there are early returns, and the highest
130 // priority interrupts should get serviced,
131 // it is v. important that new interrupts are inserted
132 // in the right order of processing
133 if (hpstate.hpriv) {
134 if (pstate.ie) {
135 if (interrupts[IT_HINTP]) {
136 // This will be cleaned by a HINTP write
137 return true;
138 }
139 if (interrupts[IT_INT_VEC]) {
140 // this will be cleared by an ASI read (or write)
141 return true;
142 }
143 }
144 } else {
146 // this is cleared by deasserting HPSTATE::tlz
147 return true;
148 }
149 // HStick matches always happen in priv mode (ie doesn't matter)
150 if (interrupts[IT_HINTP]) {
151 return true;
152 }
153 if (interrupts[IT_INT_VEC]) {
154 // this will be cleared by an ASI read (or write)
155 return true;
156 }
157 if (pstate.ie) {
159 return true;
160 }
162 return true;
163 }
164 if (interrupts[IT_SOFT_INT]) {
165 return true;
166 }
167
169 return true;
170 }
171 } // !hpriv && pstate.ie
172 } // !hpriv
173
174 return false;
175 }
176
177 Fault
178 getInterrupt() override
179 {
180 assert(checkInterrupts());
181
182 HPSTATE hpstate = tc->readMiscRegNoEffect(MISCREG_HPSTATE);
183 PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
184
185 // THESE ARE IN ORDER OF PRIORITY
186 // since there are early returns, and the highest
187 // priority interrupts should get serviced,
188 // it is v. important that new interrupts are inserted
189 // in the right order of processing
190 if (hpstate.hpriv) {
191 if (pstate.ie) {
192 if (interrupts[IT_HINTP]) {
193 // This will be cleaned by a HINTP write
194 return std::make_shared<HstickMatch>();
195 }
196 if (interrupts[IT_INT_VEC]) {
197 // this will be cleared by an ASI read (or write)
198 return std::make_shared<InterruptVector>();
199 }
200 }
201 } else {
203 // this is cleared by deasserting HPSTATE::tlz
204 return std::make_shared<TrapLevelZero>();
205 }
206 // HStick matches always happen in priv mode (ie doesn't matter)
207 if (interrupts[IT_HINTP]) {
208 return std::make_shared<HstickMatch>();
209 }
210 if (interrupts[IT_INT_VEC]) {
211 // this will be cleared by an ASI read (or write)
212 return std::make_shared<InterruptVector>();
213 }
214 if (pstate.ie) {
216 return std::make_shared<CpuMondo>();
217 }
219 return std::make_shared<DevMondo>();
220 }
221 if (interrupts[IT_SOFT_INT]) {
223 return std::make_shared<InterruptLevelN>(level);
224 }
225
227 return std::make_shared<ResumableError>();
228 }
229 } // !hpriv && pstate.ie
230 } // !hpriv
231 return NoFault;
232 }
233
234 void updateIntrInfo() override {}
235
236 uint64_t
237 get_vec(int int_num)
238 {
239 assert(int_num >= 0 && int_num < NumInterruptTypes);
240 return interrupts[int_num];
241 }
242
243 void
249
250 void
256};
257
258} // namespace SparcISA
259} // namespace gem5
260
261#endif // __ARCH_SPARC_INTERRUPT_HH__
#define DPRINTF(x,...)
Definition trace.hh:210
ThreadContext * tc
Definition interrupts.hh:44
uint64_t get_vec(int int_num)
void post(int int_num, int index) override
Definition interrupts.hh:88
bool checkInterrupts() const override
int InterruptLevel(uint64_t softint)
Definition interrupts.hh:74
void serialize(CheckpointOut &cp) const override
Serialize an object.
SparcInterruptsParams Params
Definition interrupts.hh:66
void updateIntrInfo() override
uint64_t interrupts[NumInterruptTypes]
Definition interrupts.hh:61
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Fault getInterrupt() override
void clear(int int_num, int index) override
Definition interrupts.hh:99
Interrupts(const Params &p)
Definition interrupts.hh:68
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
#define UNSERIALIZE_ARRAY(member, size)
Definition serialize.hh:618
#define SERIALIZE_ARRAY(member, size)
Definition serialize.hh:610
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 30, 0 > index
Bitfield< 0 > p
@ MISCREG_HPSTATE
Hyper privileged registers.
Definition misc.hh:79
@ MISCREG_PSTATE
Definition misc.hh:67
Bitfield< 20 > level
Definition intmessage.hh:51
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::ostream CheckpointOut
Definition serialize.hh:66
constexpr decltype(nullptr) NoFault
Definition types.hh:253
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0