gem5 v25.0.0.1
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
65 // added for H-extension
66 std::bitset<NumInterruptTypes> hvip;
67
69 protected:
71
72 public:
73 using Params = RiscvInterruptsParams;
74
75 Interrupts(const Params &p);
76
77 std::bitset<NumInterruptTypes> globalMask() const;
78
79 bool
81 {
82 return tc->readMiscReg(MISCREG_NMIP) & tc->readMiscReg(MISCREG_NMIE);
83 }
84
85 bool checkInterrupt(int num) const {
86 return (ip[num] || hvip[num]) && ie[num];
87 }
88
89 bool checkInterrupts() const override
90 {
91 ISA* isa = static_cast<ISA*>(tc->getIsaPtr());
92 if (isa->enableSmrnmi() && tc->readMiscReg(MISCREG_NMIE) == 0) {
93 return false;
94 }
96 ((ip | hvip) & ie & globalMask()).any();
97 }
98
99 Fault getInterrupt() override;
100
101 void updateIntrInfo() override {}
102
103 void post(int int_num, int index) override;
104
105 void clear(int int_num, int index) override;
106
107 void postNMI() { tc->setMiscReg(MISCREG_NMIP, 1); }
108 void clearNMI() { tc->setMiscReg(MISCREG_NMIP, 0); }
109
110 void clearAll() override;
111
112
113 bool isWakeUp() const override
114 {
115 return checkNonMaskableInterrupt() || ((ip | hvip) & ie).any();
116 }
117
118 uint64_t readIP() const { return (uint64_t)ip.to_ulong() | readHVIP(); }
119 uint64_t readIE() const { return (uint64_t)ie.to_ulong(); }
120 uint64_t readHVIP() const { return (uint64_t)hvip.to_ulong(); }
121
122 void setIP(const uint64_t& val) { ip = val; }
123 void setIE(const uint64_t& val) { ie = val; }
124 void setHVIP(const uint64_t& val) { hvip = val; }
125
126 void serialize(CheckpointOut &cp) const override;
127
128 void unserialize(CheckpointIn &cp) override;
129
130 Port &getPort(const std::string &if_name, PortID idx) override;
131
132 void raiseInterruptPin(uint32_t num);
133 void lowerInterruptPin(uint32_t num) {};
134};
135
136} // namespace RiscvISA
137} // namespace gem5
138
139#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:211
std::vector< gem5::IntSinkPin< Interrupts > * > localInterruptPins
Definition interrupts.hh:68
void setIP(const uint64_t &val)
void setHVIP(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:89
uint64_t readHVIP() const
bool checkNonMaskableInterrupt() const
Definition interrupts.hh:80
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.
std::bitset< NumInterruptTypes > hvip
Definition interrupts.hh:66
RiscvInterruptsParams Params
Definition interrupts.hh:73
void updateIntrInfo() override
bool isWakeUp() const override
std::bitset< NumInterruptTypes > globalMask() const
Definition interrupts.cc:60
std::bitset< NumInterruptTypes > ip
Definition interrupts.hh:62
bool checkInterrupt(int num) const
Definition interrupts.hh:85
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 Sat Oct 18 2025 08:06:40 for gem5 by doxygen 1.14.0