gem5  v20.0.0.3
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"
34 #include "arch/sparc/isa_traits.hh"
35 #include "arch/sparc/registers.hh"
36 #include "cpu/thread_context.hh"
37 #include "debug/Interrupt.hh"
38 #include "params/SparcInterrupts.hh"
39 #include "sim/sim_object.hh"
40 
41 namespace SparcISA
42 {
43 
45 {
54 };
55 
56 class Interrupts : public BaseInterrupts
57 {
58  private:
60 
62  uint64_t intStatus;
63 
64  public:
65 
66  void
67  setCPU(BaseCPU * _cpu) override
68  {
69  cpu = _cpu;
70  }
71 
72  typedef SparcInterruptsParams Params;
73 
74  const Params *
75  params() const
76  {
77  return dynamic_cast<const Params *>(_params);
78  }
79 
80  Interrupts(Params * p) : BaseInterrupts(p), cpu(NULL)
81  {
82  clearAll();
83  }
84 
85  int
86  InterruptLevel(uint64_t softint)
87  {
88  if (softint & 0x10000 || softint & 0x1)
89  return 14;
90 
91  int level = 15;
92  while (level > 0 && !(1 << level & softint))
93  level--;
94  if (1 << level & softint)
95  return level;
96  return 0;
97  }
98 
99  void
100  post(int int_num, int index) override
101  {
102  DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
103  assert(int_num >= 0 && int_num < NumInterruptTypes);
104  assert(index >= 0 && index < 64);
105 
106  interrupts[int_num] |= ULL(1) << index;
107  intStatus |= ULL(1) << int_num;
108  }
109 
110  void
111  clear(int int_num, int index) override
112  {
113  DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
114  assert(int_num >= 0 && int_num < NumInterruptTypes);
115  assert(index >= 0 && index < 64);
116 
117  interrupts[int_num] &= ~(ULL(1) << index);
118  if (!interrupts[int_num])
119  intStatus &= ~(ULL(1) << int_num);
120  }
121 
122  void
123  clearAll() override
124  {
125  for (int i = 0; i < NumInterruptTypes; ++i) {
126  interrupts[i] = 0;
127  }
128  intStatus = 0;
129  }
130 
131  bool
132  checkInterrupts(ThreadContext *tc) const override
133  {
134  if (!intStatus)
135  return false;
136 
137  HPSTATE hpstate = tc->readMiscRegNoEffect(MISCREG_HPSTATE);
138  PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
139 
140  // THESE ARE IN ORDER OF PRIORITY
141  // since there are early returns, and the highest
142  // priority interrupts should get serviced,
143  // it is v. important that new interrupts are inserted
144  // in the right order of processing
145  if (hpstate.hpriv) {
146  if (pstate.ie) {
147  if (interrupts[IT_HINTP]) {
148  // This will be cleaned by a HINTP write
149  return true;
150  }
151  if (interrupts[IT_INT_VEC]) {
152  // this will be cleared by an ASI read (or write)
153  return true;
154  }
155  }
156  } else {
157  if (interrupts[IT_TRAP_LEVEL_ZERO]) {
158  // this is cleared by deasserting HPSTATE::tlz
159  return true;
160  }
161  // HStick matches always happen in priv mode (ie doesn't matter)
162  if (interrupts[IT_HINTP]) {
163  return true;
164  }
165  if (interrupts[IT_INT_VEC]) {
166  // this will be cleared by an ASI read (or write)
167  return true;
168  }
169  if (pstate.ie) {
170  if (interrupts[IT_CPU_MONDO]) {
171  return true;
172  }
173  if (interrupts[IT_DEV_MONDO]) {
174  return true;
175  }
176  if (interrupts[IT_SOFT_INT]) {
177  return true;
178  }
179 
180  if (interrupts[IT_RES_ERROR]) {
181  return true;
182  }
183  } // !hpriv && pstate.ie
184  } // !hpriv
185 
186  return false;
187  }
188 
189  Fault
191  {
192  assert(checkInterrupts(tc));
193 
194  HPSTATE hpstate = tc->readMiscRegNoEffect(MISCREG_HPSTATE);
195  PSTATE pstate = tc->readMiscRegNoEffect(MISCREG_PSTATE);
196 
197  // THESE ARE IN ORDER OF PRIORITY
198  // since there are early returns, and the highest
199  // priority interrupts should get serviced,
200  // it is v. important that new interrupts are inserted
201  // in the right order of processing
202  if (hpstate.hpriv) {
203  if (pstate.ie) {
204  if (interrupts[IT_HINTP]) {
205  // This will be cleaned by a HINTP write
206  return std::make_shared<HstickMatch>();
207  }
208  if (interrupts[IT_INT_VEC]) {
209  // this will be cleared by an ASI read (or write)
210  return std::make_shared<InterruptVector>();
211  }
212  }
213  } else {
214  if (interrupts[IT_TRAP_LEVEL_ZERO]) {
215  // this is cleared by deasserting HPSTATE::tlz
216  return std::make_shared<TrapLevelZero>();
217  }
218  // HStick matches always happen in priv mode (ie doesn't matter)
219  if (interrupts[IT_HINTP]) {
220  return std::make_shared<HstickMatch>();
221  }
222  if (interrupts[IT_INT_VEC]) {
223  // this will be cleared by an ASI read (or write)
224  return std::make_shared<InterruptVector>();
225  }
226  if (pstate.ie) {
227  if (interrupts[IT_CPU_MONDO]) {
228  return std::make_shared<CpuMondo>();
229  }
230  if (interrupts[IT_DEV_MONDO]) {
231  return std::make_shared<DevMondo>();
232  }
233  if (interrupts[IT_SOFT_INT]) {
234  int level = InterruptLevel(interrupts[IT_SOFT_INT]);
235  return std::make_shared<InterruptLevelN>(level);
236  }
237 
238  if (interrupts[IT_RES_ERROR]) {
239  return std::make_shared<ResumableError>();
240  }
241  } // !hpriv && pstate.ie
242  } // !hpriv
243  return NoFault;
244  }
245 
246  void updateIntrInfo(ThreadContext *tc) override {}
247 
248  uint64_t
249  get_vec(int int_num)
250  {
251  assert(int_num >= 0 && int_num < NumInterruptTypes);
252  return interrupts[int_num];
253  }
254 
255  void
256  serialize(CheckpointOut &cp) const override
257  {
259  SERIALIZE_SCALAR(intStatus);
260  }
261 
262  void
264  {
266  UNSERIALIZE_SCALAR(intStatus);
267  }
268 };
269 } // namespace SPARC_ISA
270 
271 #endif // __ARCH_SPARC_INTERRUPT_HH__
#define DPRINTF(x,...)
Definition: trace.hh:225
Bitfield< 30, 0 > index
decltype(nullptr) constexpr NoFault
Definition: types.hh:243
Bitfield< 7 > i
void clear(int int_num, int index) override
Definition: interrupts.hh:111
SparcInterruptsParams Params
Definition: interrupts.hh:72
void post(int int_num, int index) override
Definition: interrupts.hh:100
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: interrupts.hh:263
Definition: cprintf.cc:40
ThreadContext is the external interface to all thread state for anything outside of the CPU...
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:770
bool checkInterrupts(ThreadContext *tc) const override
Definition: interrupts.hh:132
void updateIntrInfo(ThreadContext *tc) override
Definition: interrupts.hh:246
uint64_t get_vec(int int_num)
Definition: interrupts.hh:249
Hyper privileged registers.
Definition: miscregs.hh:74
Fault getInterrupt(ThreadContext *tc) override
Definition: interrupts.hh:190
uint64_t interrupts[NumInterruptTypes]
Definition: interrupts.hh:61
#define ULL(N)
uint64_t constant
Definition: types.hh:48
#define SERIALIZE_ARRAY(member, size)
Definition: serialize.hh:805
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:763
void setCPU(BaseCPU *_cpu) override
Definition: interrupts.hh:67
Bitfield< 20 > level
Definition: intmessage.hh:47
int InterruptLevel(uint64_t softint)
Definition: interrupts.hh:86
#define UNSERIALIZE_ARRAY(member, size)
Definition: serialize.hh:813
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
std::ostream CheckpointOut
Definition: serialize.hh:63
Definition: asi.cc:31
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:111
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: interrupts.hh:256
const Params * params() const
Definition: interrupts.hh:75
void clearAll() override
Definition: interrupts.hh:123
Interrupts(Params *p)
Definition: interrupts.hh:80
Bitfield< 0 > p
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238

Generated on Fri Jul 3 2020 15:42:39 for gem5 by doxygen 1.8.13