gem5  v20.1.0.0
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:
56  std::bitset<NumInterruptTypes> ip;
57  std::bitset<NumInterruptTypes> ie;
58 
59  public:
60  typedef RiscvInterruptsParams Params;
61 
62  const Params *
63  params() const
64  {
65  return dynamic_cast<const Params *>(_params);
66  }
67 
68  Interrupts(Params * p) : BaseInterrupts(p), ip(0), ie(0) {}
69 
70  std::bitset<NumInterruptTypes>
71  globalMask() const
72  {
73  INTERRUPT mask = 0;
75  if (status.mie)
76  mask.mei = mask.mti = mask.msi = 1;
77  if (status.sie)
78  mask.sei = mask.sti = mask.ssi = 1;
79  if (status.uie)
80  mask.uei = mask.uti = mask.usi = 1;
81  return std::bitset<NumInterruptTypes>(mask);
82  }
83 
84  bool checkInterrupt(int num) const { return ip[num] && ie[num]; }
85  bool checkInterrupts() const
86  {
87  return (ip & ie & globalMask()).any();
88  }
89 
90  Fault
92  {
93  assert(checkInterrupts());
94  std::bitset<NumInterruptTypes> mask = globalMask();
95  for (int c = 0; c < NumInterruptTypes; c++)
96  if (checkInterrupt(c) && mask[c])
97  return std::make_shared<InterruptFault>(c);
98  return NoFault;
99  }
100 
101  void updateIntrInfo() {}
102 
103  void
104  post(int int_num, int index)
105  {
106  DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
107  ip[int_num] = true;
108  }
109 
110  void
111  clear(int int_num, int index)
112  {
113  DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
114  ip[int_num] = false;
115  }
116 
117  void
119  {
120  DPRINTF(Interrupt, "All interrupts cleared\n");
121  ip = 0;
122  }
123 
124  uint64_t readIP() const { return (uint64_t)ip.to_ulong(); }
125  uint64_t readIE() const { return (uint64_t)ie.to_ulong(); }
126  void setIP(const uint64_t& val) { ip = val; }
127  void setIE(const uint64_t& val) { ie = val; }
128 
129  void
131  {
132  unsigned long ip_ulong = ip.to_ulong();
133  unsigned long ie_ulong = ie.to_ulong();
134  SERIALIZE_SCALAR(ip_ulong);
135  SERIALIZE_SCALAR(ie_ulong);
136  }
137 
138  void
140  {
141  unsigned long ip_ulong;
142  unsigned long ie_ulong;
143  UNSERIALIZE_SCALAR(ip_ulong);
144  ip = ip_ulong;
145  UNSERIALIZE_SCALAR(ie_ulong);
146  ie = ie_ulong;
147  }
148 };
149 
150 } // namespace RiscvISA
151 
152 #endif // __ARCH_RISCV_INTERRUPT_HH__
ArmISA::status
Bitfield< 5, 0 > status
Definition: miscregs_types.hh:417
RiscvISA::Interrupts::unserialize
void unserialize(CheckpointIn &cp)
Unserialize an object.
Definition: interrupts.hh:139
RiscvISA::Interrupts::clear
void clear(int int_num, int index)
Definition: interrupts.hh:111
RiscvISA::Interrupts::setIE
void setIE(const uint64_t &val)
Definition: interrupts.hh:127
faults.hh
RiscvISA::c
Bitfield< 5, 3 > c
Definition: pra_constants.hh:56
UNSERIALIZE_SCALAR
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:797
RiscvISA::Interrupts::readIP
uint64_t readIP() const
Definition: interrupts.hh:124
RiscvISA::Interrupts::updateIntrInfo
void updateIntrInfo()
Definition: interrupts.hh:101
RiscvISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
RiscvISA::NumInterruptTypes
@ NumInterruptTypes
Definition: faults.hh:89
RiscvISA::MISCREG_STATUS
@ MISCREG_STATUS
Definition: registers.hh:135
RiscvISA
Definition: fs_workload.cc:36
RiscvISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:44
RiscvISA::Interrupts::checkInterrupts
bool checkInterrupts() const
Definition: interrupts.hh:85
cp
Definition: cprintf.cc:40
RiscvISA::Interrupts::clearAll
void clearAll()
Definition: interrupts.hh:118
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
RiscvISA::Interrupts::Interrupts
Interrupts(Params *p)
Definition: interrupts.hh:68
sim_object.hh
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
RiscvISA::Interrupts::globalMask
std::bitset< NumInterruptTypes > globalMask() const
Definition: interrupts.hh:71
RiscvISA::Interrupts::readIE
uint64_t readIE() const
Definition: interrupts.hh:125
RiscvISA::Interrupts::setIP
void setIP(const uint64_t &val)
Definition: interrupts.hh:126
BaseInterrupts::Params
BaseInterruptsParams Params
Definition: interrupts.hh:43
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:245
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
RiscvISA::Interrupts::getInterrupt
Fault getInterrupt()
Definition: interrupts.hh:91
registers.hh
BaseCPU
Definition: cpu_dummy.hh:43
RiscvISA::mask
mask
Definition: pra_constants.hh:70
SimObject::_params
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
RiscvISA::Interrupts::post
void post(int int_num, int index)
Definition: interrupts.hh:104
ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
interrupts.hh
RiscvISA::Interrupts::params
const Params * params() const
Definition: interrupts.hh:63
RiscvISA::Interrupts::ip
std::bitset< NumInterruptTypes > ip
Definition: interrupts.hh:56
RiscvISA::Interrupts::checkInterrupt
bool checkInterrupt(int num) const
Definition: interrupts.hh:84
logging.hh
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
RiscvISA::Interrupts::Params
RiscvInterruptsParams Params
Definition: interrupts.hh:60
RiscvISA::Interrupts::serialize
void serialize(CheckpointOut &cp) const
Serialize an object.
Definition: interrupts.hh:130
RiscvISA::Interrupts
Definition: interrupts.hh:53
BaseInterrupts
Definition: interrupts.hh:37
BaseInterrupts::tc
ThreadContext * tc
Definition: interrupts.hh:40
CheckpointIn
Definition: serialize.hh:67
thread_context.hh
RiscvISA::Interrupts::ie
std::bitset< NumInterruptTypes > ie
Definition: interrupts.hh:57

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