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

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13