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

Generated on Wed Sep 30 2020 14:01:58 for gem5 by doxygen 1.8.17