gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
interrupts.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Google
3 * Copyright (c) 2024 University of Rostock
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef __ARCH_RISCV_INTERRUPT_HH__
31#define __ARCH_RISCV_INTERRUPT_HH__
32
33#include <bitset>
34#include <memory>
35
37#include "arch/riscv/faults.hh"
39#include "base/logging.hh"
40#include "cpu/base.hh"
41#include "cpu/thread_context.hh"
42#include "debug/Interrupt.hh"
43#include "dev/intpin.hh"
44#include "params/RiscvInterrupts.hh"
45#include "sim/sim_object.hh"
46
47namespace gem5
48{
49
50class BaseCPU;
51class ThreadContext;
52
53namespace RiscvISA {
54
55/*
56 * This is based on version 1.10 of the RISC-V privileged ISA reference,
57 * chapter 3.1.14.
58 */
60{
61 private:
62 std::bitset<NumInterruptTypes> ip;
63 std::bitset<NumInterruptTypes> ie;
64
66 protected:
68
69 public:
70 using Params = RiscvInterruptsParams;
71
72 Interrupts(const Params &p);
73
74 std::bitset<NumInterruptTypes> globalMask() const;
75
76 bool
78 {
79 return tc->readMiscReg(MISCREG_NMIP) & tc->readMiscReg(MISCREG_NMIE);
80 }
81
82 bool checkInterrupt(int num) const { return ip[num] && ie[num]; }
83 bool checkInterrupts() const override
84 {
85 ISA* isa = static_cast<ISA*>(tc->getIsaPtr());
86 if (isa->enableSmrnmi() && tc->readMiscReg(MISCREG_NMIE) == 0) {
87 return false;
88 }
89 return checkNonMaskableInterrupt() || (ip & ie & globalMask()).any();
90 }
91
92 Fault getInterrupt() override;
93
94 void updateIntrInfo() override {}
95
96 void post(int int_num, int index) override;
97
98 void clear(int int_num, int index) override;
99
100 void postNMI() { tc->setMiscReg(MISCREG_NMIP, 1); }
101 void clearNMI() { tc->setMiscReg(MISCREG_NMIP, 0); }
102
103 void clearAll() override;
104
105 bool isWakeUp() const override
106 {
107 return checkNonMaskableInterrupt() || (ip & ie).any();
108 }
109
110 uint64_t readIP() const { return (uint64_t)ip.to_ulong(); }
111 uint64_t readIE() const { return (uint64_t)ie.to_ulong(); }
112 void setIP(const uint64_t& val) { ip = val; }
113 void setIE(const uint64_t& val) { ie = val; }
114
115 void serialize(CheckpointOut &cp) const override;
116
117 void unserialize(CheckpointIn &cp) override;
118
119 Port &getPort(const std::string &if_name, PortID idx) override;
120
121 void raiseInterruptPin(uint32_t num);
122 void lowerInterruptPin(uint32_t num) {};
123};
124
125} // namespace RiscvISA
126} // namespace gem5
127
128#endif // __ARCH_RISCV_INTERRUPT_HH__
ThreadContext * tc
Definition interrupts.hh:44
BaseInterrupts(const Params &p)
Definition interrupts.hh:49
Ports are used to interface objects to each other.
Definition port.hh:62
bool enableSmrnmi()
Definition isa.hh:200
std::vector< gem5::IntSinkPin< Interrupts > * > localInterruptPins
Definition interrupts.hh:65
void setIP(const uint64_t &val)
void setIE(const uint64_t &val)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Interrupts(const Params &p)
Definition interrupts.cc:39
uint64_t readIE() const
void clear(int int_num, int index) override
bool checkInterrupts() const override
Definition interrupts.hh:83
bool checkNonMaskableInterrupt() const
Definition interrupts.hh:77
uint64_t readIP() const
void lowerInterruptPin(uint32_t num)
void post(int int_num, int index) override
void serialize(CheckpointOut &cp) const override
Serialize an object.
void raiseInterruptPin(uint32_t num)
Port & getPort(const std::string &if_name, PortID idx) override
Get a port with a given name and index.
RiscvInterruptsParams Params
Definition interrupts.hh:70
void updateIntrInfo() override
Definition interrupts.hh:94
bool isWakeUp() const override
std::bitset< NumInterruptTypes > globalMask() const
Definition interrupts.cc:59
std::bitset< NumInterruptTypes > ip
Definition interrupts.hh:62
bool checkInterrupt(int num) const
Definition interrupts.hh:82
Fault getInterrupt() override
std::bitset< NumInterruptTypes > ie
Definition interrupts.hh:63
ThreadContext is the external interface to all thread state for anything outside of the CPU.
STL vector class.
Definition stl.hh:37
Bitfield< 0 > p
Bitfield< 30, 0 > index
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::ostream CheckpointOut
Definition serialize.hh:66
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245

Generated on Mon May 26 2025 09:19:05 for gem5 by doxygen 1.13.2