gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
interrupts.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 2012-2013, 2016, 2023 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __ARCH_ARM_INTERRUPT_HH__
42#define __ARCH_ARM_INTERRUPT_HH__
43
44#include "arch/arm/faults.hh"
45#include "arch/arm/regs/misc.hh"
46#include "arch/arm/utility.hh"
48#include "cpu/thread_context.hh"
49#include "debug/Interrupt.hh"
50#include "enums/ArmExtension.hh"
51
52namespace gem5
53{
54
55struct ArmInterruptsParams;
56
57namespace ArmISA
58{
59
61{
66 INT_SEV, // Special interrupt for recieving SEV's
70 // Cannot be raised by an external signal
71 // (for now) from the IC so we don't instantiate a
72 // interrupt entry in the state array
74};
75
77{
78 private:
80 uint64_t intStatus;
81
82 public:
83 using Params = ArmInterruptsParams;
84
85 Interrupts(const Params &p);
86
87 void
88 post(int int_num, int index) override
89 {
90 DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
91
92 if (int_num < 0 || int_num >= NumInterruptTypes)
93 panic("int_num out of bounds\n");
94
95 if (index != 0)
96 panic("No support for other interrupt indexes\n");
97
98 interrupts[int_num] = true;
99 intStatus |= 1ULL << 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
107 if (int_num < 0 || int_num >= NumInterruptTypes)
108 panic("int_num out of bounds\n");
109
110 if (index != 0)
111 panic("No support for other interrupt indexes\n");
112
113 interrupts[int_num] = false;
114 intStatus &= ~(1ULL << int_num);
115 }
116
117 void
118 clearAll() override
119 {
120 DPRINTF(Interrupt, "Interrupts all cleared\n");
121 intStatus = 0;
122 memset(interrupts, 0, sizeof(interrupts));
123 }
124
126 {
127 INT_MASK_M, // masked (subject to PSTATE.{A,I,F} mask bit
128 INT_MASK_T, // taken regardless of mask
129 INT_MASK_P // pending
130 };
131
132 bool takeInt(InterruptTypes int_type) const;
133 bool takeInt32(InterruptTypes int_type) const;
134 bool takeInt64(InterruptTypes int_type) const;
135
136 bool takeVirtualInt(InterruptTypes int_type) const;
137 bool takeVirtualInt32(InterruptTypes int_type) const;
138 bool takeVirtualInt64(InterruptTypes int_type) const;
139
140 bool
141 checkInterrupts() const override
142 {
143 HCR hcr = tc->readMiscReg(MISCREG_HCR_EL2);
144
145 if (!(intStatus || hcr.va || hcr.vi || hcr.vf))
146 return false;
147
148 return ((interrupts[INT_IRQ] && takeInt(INT_IRQ)) ||
151 ((interrupts[INT_VIRT_IRQ] || hcr.vi) &&
153 ((interrupts[INT_VIRT_FIQ] || hcr.vf) &&
155 (hcr.va && takeVirtualInt(INT_VIRT_ABT)) ||
156 (interrupts[INT_RST]) ||
158 );
159 }
160
166 bool
167 checkWfiWake(HCR hcr, CPSR cpsr, SCR scr) const
168 {
169 uint64_t masked_int_status;
170 bool virt_wake;
171
172 masked_int_status = intStatus & ~((1 << INT_VIRT_IRQ) |
173 (1 << INT_VIRT_FIQ));
174 virt_wake = (hcr.vi || interrupts[INT_VIRT_IRQ]) && hcr.imo;
175 virt_wake |= (hcr.vf || interrupts[INT_VIRT_FIQ]) && hcr.fmo;
176 virt_wake |= hcr.va && hcr.amo;
177 virt_wake &= currEL(cpsr) < EL2 && EL2Enabled(tc);
178 return masked_int_status || virt_wake;
179 }
180
181 uint32_t
182 getISR(HCR hcr, CPSR cpsr, SCR scr)
183 {
184 bool use_hcr_mux = currEL(cpsr) < EL2 && EL2Enabled(tc);
185 ISR isr = 0;
186
187 isr.i = (use_hcr_mux & hcr.imo) ? (interrupts[INT_VIRT_IRQ] || hcr.vi)
189 isr.f = (use_hcr_mux & hcr.fmo) ? (interrupts[INT_VIRT_FIQ] || hcr.vf)
191 isr.a = (use_hcr_mux & hcr.amo) ? hcr.va : interrupts[INT_ABT];
192 return isr;
193 }
194
205 bool
206 checkRaw(InterruptTypes interrupt) const
207 {
208 if (interrupt >= NumInterruptTypes)
209 panic("Interrupt number out of range.\n");
210
211 return interrupts[interrupt];
212 }
213
214 Fault
215 getInterrupt() override
216 {
217 assert(checkInterrupts());
218
219 HCR hcr = tc->readMiscReg(MISCREG_HCR_EL2);
220
222 return std::make_shared<Interrupt>();
223 if ((interrupts[INT_VIRT_IRQ] || hcr.vi) &&
225 return std::make_shared<VirtualInterrupt>();
227 return std::make_shared<FastInterrupt>();
228 if ((interrupts[INT_VIRT_FIQ] || hcr.vf) &&
230 return std::make_shared<VirtualFastInterrupt>();
232 return std::make_shared<SystemError>();
233 if (hcr.va && takeVirtualInt(INT_VIRT_ABT))
234 return std::make_shared<VirtualDataAbort>(
235 0, DomainType::NoAccess, false,
237 if (interrupts[INT_RST])
238 return std::make_shared<Reset>();
239 if (interrupts[INT_SEV])
240 return std::make_shared<ArmSev>();
241
242 panic("intStatus and interrupts not in sync\n");
243 }
244
245 void updateIntrInfo() override {} // nothing to do
246
247 void
253
254 void
260};
261
262} // namespace ARM_ISA
263} // namespace gem5
264
265#endif // __ARCH_ARM_INTERRUPT_HH__
#define DPRINTF(x,...)
Definition trace.hh:209
void clearAll() override
bool checkInterrupts() const override
uint32_t getISR(HCR hcr, CPSR cpsr, SCR scr)
bool takeInt64(InterruptTypes int_type) const
void updateIntrInfo() override
bool takeInt(InterruptTypes int_type) const
bool takeInt32(InterruptTypes int_type) const
Definition interrupts.cc:52
void clear(int int_num, int index) override
bool interrupts[NumInterruptTypes]
Definition interrupts.hh:79
bool takeVirtualInt64(InterruptTypes int_type) const
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void post(int int_num, int index) override
Definition interrupts.hh:88
bool takeVirtualInt(InterruptTypes int_type) const
bool checkRaw(InterruptTypes interrupt) const
Check the state of a particular interrupt, ignoring CPSR masks.
ArmInterruptsParams Params
Definition interrupts.hh:83
bool takeVirtualInt32(InterruptTypes int_type) const
bool checkWfiWake(HCR hcr, CPSR cpsr, SCR scr) const
This function is used to check if a wfi operation should sleep.
Fault getInterrupt() override
Interrupts(const Params &p)
Definition interrupts.cc:46
ThreadContext * tc
Definition interrupts.hh:44
BaseInterrupts(const Params &p)
Definition interrupts.hh:49
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
#define UNSERIALIZE_ARRAY(member, size)
Definition serialize.hh:618
#define SERIALIZE_ARRAY(member, size)
Definition serialize.hh:610
ExceptionLevel currEL(const ThreadContext *tc)
Returns the current Exception Level (EL) of the provided ThreadContext.
Definition utility.cc:134
bool EL2Enabled(ThreadContext *tc)
Definition utility.cc:268
@ MISCREG_HCR_EL2
Definition misc.hh:619
Bitfield< 30, 0 > index
Bitfield< 0 > p
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
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Mon Oct 27 2025 04:12:58 for gem5 by doxygen 1.14.0