gem5  v20.0.0.2
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) 2011 Google
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_RISCV_INTERRUPT_HH__
30 #define __ARCH_RISCV_INTERRUPT_HH__
31 
32 #include <bitset>
33 #include <memory>
34 
36 #include "arch/riscv/faults.hh"
37 #include "arch/riscv/registers.hh"
38 #include "base/logging.hh"
39 #include "cpu/thread_context.hh"
40 #include "debug/Interrupt.hh"
41 #include "params/RiscvInterrupts.hh"
42 #include "sim/sim_object.hh"
43 
44 class BaseCPU;
45 class ThreadContext;
46 
47 namespace RiscvISA {
48 
49 /*
50  * This is based on version 1.10 of the RISC-V privileged ISA reference,
51  * chapter 3.1.14.
52  */
53 class Interrupts : public BaseInterrupts
54 {
55  private:
57  std::bitset<NumInterruptTypes> ip;
58  std::bitset<NumInterruptTypes> ie;
59 
60  public:
61  typedef RiscvInterruptsParams Params;
62 
63  const Params *
64  params() const
65  {
66  return dynamic_cast<const Params *>(_params);
67  }
68 
69  Interrupts(Params * p) : BaseInterrupts(p), cpu(nullptr), ip(0), ie(0) {}
70 
71  void setCPU(BaseCPU * _cpu) { cpu = _cpu; }
72 
73  std::bitset<NumInterruptTypes>
75  {
76  INTERRUPT mask = 0;
77  STATUS status = tc->readMiscReg(MISCREG_STATUS);
78  if (status.mie)
79  mask.mei = mask.mti = mask.msi = 1;
80  if (status.sie)
81  mask.sei = mask.sti = mask.ssi = 1;
82  if (status.uie)
83  mask.uei = mask.uti = mask.usi = 1;
84  return std::bitset<NumInterruptTypes>(mask);
85  }
86 
87  bool checkInterrupt(int num) const { return ip[num] && ie[num]; }
89  {
90  return (ip & ie & globalMask(tc)).any();
91  }
92 
93  Fault
95  {
96  assert(checkInterrupts(tc));
97  std::bitset<NumInterruptTypes> mask = globalMask(tc);
98  for (int c = 0; c < NumInterruptTypes; c++)
99  if (checkInterrupt(c) && mask[c])
100  return std::make_shared<InterruptFault>(c);
101  return NoFault;
102  }
103 
105 
106  void
107  post(int int_num, int index)
108  {
109  DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
110  ip[int_num] = true;
111  }
112 
113  void
114  clear(int int_num, int index)
115  {
116  DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
117  ip[int_num] = false;
118  }
119 
120  void
122  {
123  DPRINTF(Interrupt, "All interrupts cleared\n");
124  ip = 0;
125  }
126 
127  uint64_t readIP() const { return (uint64_t)ip.to_ulong(); }
128  uint64_t readIE() const { return (uint64_t)ie.to_ulong(); }
129  void setIP(const uint64_t& val) { ip = val; }
130  void setIE(const uint64_t& val) { ie = val; }
131 
132  void
134  {
135  unsigned long ip_ulong = ip.to_ulong();
136  unsigned long ie_ulong = ie.to_ulong();
137  SERIALIZE_SCALAR(ip_ulong);
138  SERIALIZE_SCALAR(ie_ulong);
139  }
140 
141  void
143  {
144  unsigned long ip_ulong;
145  unsigned long ie_ulong;
146  UNSERIALIZE_SCALAR(ip_ulong);
147  ip = ip_ulong;
148  UNSERIALIZE_SCALAR(ie_ulong);
149  ie = ie_ulong;
150  }
151 };
152 
153 } // namespace RiscvISA
154 
155 #endif // __ARCH_RISCV_INTERRUPT_HH__
#define DPRINTF(x,...)
Definition: trace.hh:222
std::bitset< NumInterruptTypes > ie
Definition: interrupts.hh:58
decltype(nullptr) constexpr NoFault
Definition: types.hh:243
void updateIntrInfo(ThreadContext *tc)
Definition: interrupts.hh:104
Fault getInterrupt(ThreadContext *tc)
Definition: interrupts.hh:94
void clear(int int_num, int index)
Definition: interrupts.hh:114
Definition: cprintf.cc:40
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Bitfield< 0 > p
Bitfield< 30, 0 > index
Bitfield< 63 > val
Definition: misc.hh:769
bool checkInterrupt(int num) const
Definition: interrupts.hh:87
Bitfield< 5, 0 > status
Interrupts(Params *p)
Definition: interrupts.hh:69
uint64_t readIP() const
Definition: interrupts.hh:127
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:770
void setCPU(BaseCPU *_cpu)
Definition: interrupts.hh:71
RiscvInterruptsParams Params
Definition: interrupts.hh:61
void post(int int_num, int index)
Definition: interrupts.hh:107
void setIP(const uint64_t &val)
Definition: interrupts.hh:129
void serialize(CheckpointOut &cp) const
Serialize an object.
Definition: interrupts.hh:133
uint64_t readIE() const
Definition: interrupts.hh:128
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:763
std::bitset< NumInterruptTypes > globalMask(ThreadContext *tc) const
Definition: interrupts.hh:74
const Params * params() const
Definition: interrupts.hh:64
std::ostream CheckpointOut
Definition: serialize.hh:63
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
bool checkInterrupts(ThreadContext *tc) const
Definition: interrupts.hh:88
Bitfield< 5, 3 > c
void setIE(const uint64_t &val)
Definition: interrupts.hh:130
void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition: interrupts.hh:142
virtual RegVal readMiscReg(RegIndex misc_reg)=0
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
std::bitset< NumInterruptTypes > ip
Definition: interrupts.hh:57

Generated on Mon Jun 8 2020 15:34:39 for gem5 by doxygen 1.8.13