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) 2012 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) 2007 The Hewlett-Packard Development Company
15  * All rights reserved.
16  *
17  * The license below extends only to copyright in the software and shall
18  * not be construed as granting a license to any other intellectual
19  * property including but not limited to intellectual property relating
20  * to a hardware implementation of the functionality of the software
21  * licensed hereunder. You may use the software subject to the license
22  * terms below provided that you ensure that this notice is replicated
23  * unmodified and in its entirety in all distributions of the software,
24  * modified or unmodified, in source code or in binary form.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are
28  * met: redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer;
30  * redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution;
33  * neither the name of the copyright holders nor the names of its
34  * contributors may be used to endorse or promote products derived from
35  * this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  */
49 
50 #ifndef __ARCH_X86_INTERRUPTS_HH__
51 #define __ARCH_X86_INTERRUPTS_HH__
52 
54 #include "arch/x86/faults.hh"
55 #include "arch/x86/intmessage.hh"
56 #include "arch/x86/regs/apic.hh"
57 #include "base/bitfield.hh"
58 #include "cpu/thread_context.hh"
59 #include "dev/io_device.hh"
60 #include "dev/x86/intdev.hh"
61 #include "params/X86LocalApic.hh"
62 #include "sim/eventq.hh"
63 
64 class ThreadContext;
65 class BaseCPU;
66 
67 int divideFromConf(uint32_t conf);
68 
69 namespace X86ISA {
70 
72 
73 class Interrupts : public BaseInterrupts
74 {
75  protected:
78 
79  // Storage for the APIC registers
80  uint32_t regs[NUM_APIC_REGS];
81 
82  BitUnion32(LVTEntry)
83  Bitfield<7, 0> vector;
84  Bitfield<10, 8> deliveryMode;
85  Bitfield<12> status;
86  Bitfield<13> polarity;
87  Bitfield<14> remoteIRR;
88  Bitfield<15> trigger;
89  Bitfield<16> masked;
90  Bitfield<17> periodic;
91  EndBitUnion(LVTEntry)
92 
93  /*
94  * Timing related stuff.
95  */
96  EventFunctionWrapper apicTimerEvent;
97  void processApicTimerEvent();
98 
99  /*
100  * A set of variables to keep track of interrupts that don't go through
101  * the IRR.
102  */
104  uint8_t smiVector;
106  uint8_t nmiVector;
108  uint8_t extIntVector;
110  uint8_t initVector;
112  uint8_t startupVector;
113  bool startedUp;
114 
115  // This is a quick check whether any of the above (except ExtInt) are set.
117 
118  // A count of how many IPIs are in flight.
120 
121  /*
122  * IRR and ISR maintenance.
123  */
124  uint8_t IRRV;
125  uint8_t ISRV;
126 
127  int
129  {
130  int offset = 7;
131  do {
132  if (regs[base + offset] != 0) {
133  return offset * 32 + findMsbSet(regs[base + offset]);
134  }
135  } while (offset--);
136  return 0;
137  }
138 
139  void
141  {
143  }
144 
145  void
147  {
149  }
150 
151  void
153  {
154  regs[base + (vector / 32)] |= (1 << (vector % 32));
155  }
156 
157  void
159  {
160  regs[base + (vector / 32)] &= ~(1 << (vector % 32));
161  }
162 
163  bool
165  {
166  return bits(regs[base + (vector / 32)], vector % 32);
167  }
168 
169  Tick clockPeriod() const { return clockDomain.clockPeriod(); }
170 
171  void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level);
172 
174 
176 
177  // Ports for interrupts.
180 
181  // Port for memory mapped register accesses.
183 
186 
187  public:
188 
189  int getInitialApicId() { return initialApicId; }
190 
191  /*
192  * Params stuff.
193  */
194  typedef X86LocalApicParams Params;
195 
196  void setCPU(BaseCPU * newCPU) override;
197 
198  const Params *
199  params() const
200  {
201  return dynamic_cast<const Params *>(_params);
202  }
203 
204  /*
205  * Initialize this object by registering it with the IO APIC.
206  */
207  void init() override;
208 
209  /*
210  * Functions to interact with the interrupt port.
211  */
212  Tick read(PacketPtr pkt);
213  Tick write(PacketPtr pkt);
215  void completeIPI(PacketPtr pkt);
216 
217  bool
219  {
220  LVTEntry entry = regs[APIC_LVT_TIMER];
221  if (!entry.masked)
222  requestInterrupt(entry.vector, entry.deliveryMode, entry.trigger);
223  return entry.periodic;
224  }
225 
228 
229  Port &getPort(const std::string &if_name,
230  PortID idx=InvalidPortID) override
231  {
232  if (if_name == "int_master") {
233  return intMasterPort;
234  } else if (if_name == "int_slave") {
235  return intSlavePort;
236  } else if (if_name == "pio") {
237  return pioPort;
238  }
239  return SimObject::getPort(if_name, idx);
240  }
241 
242  /*
243  * Functions to access and manipulate the APIC's registers.
244  */
245 
246  uint32_t readReg(ApicRegIndex miscReg);
247  void setReg(ApicRegIndex reg, uint32_t val);
248  void
249  setRegNoEffect(ApicRegIndex reg, uint32_t val)
250  {
251  regs[reg] = val;
252  }
253 
254  /*
255  * Constructor.
256  */
257 
258  Interrupts(Params * p);
259 
260  /*
261  * Functions for retrieving interrupts for the CPU to handle.
262  */
263 
264  bool checkInterrupts(ThreadContext *tc) const override;
271  bool checkInterruptsRaw() const;
278  Fault getInterrupt(ThreadContext *tc) override;
279  void updateIntrInfo(ThreadContext *tc) override;
280 
281  /*
282  * Serialization.
283  */
284  void serialize(CheckpointOut &cp) const override;
285  void unserialize(CheckpointIn &cp) override;
286 
287  /*
288  * Old functions needed for compatability but which will be phased out
289  * eventually.
290  */
291  void
292  post(int int_num, int index) override
293  {
294  panic("Interrupts::post unimplemented!\n");
295  }
296 
297  void
298  clear(int int_num, int index) override
299  {
300  panic("Interrupts::clear unimplemented!\n");
301  }
302 
303  void
304  clearAll() override
305  {
306  panic("Interrupts::clearAll unimplemented!\n");
307  }
308 };
309 
310 } // namespace X86ISA
311 
312 #endif // __ARCH_X86_INTERRUPTS_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
Bitfield< 14 > remoteIRR
Definition: interrupts.hh:87
offset
Definition: misc.hh:1024
Ports are used to interface objects to each other.
Definition: port.hh:56
Bitfield< 5, 3 > reg
Definition: types.hh:87
void post(int int_num, int index) override
Definition: interrupts.hh:292
Bitfield< 17 > periodic
Definition: interrupts.hh:90
Bitfield< 5, 3 > index
Definition: types.hh:93
const Addr MaxAddr
Definition: types.hh:164
void setCPU(BaseCPU *newCPU) override
Definition: interrupts.cc:274
const PortID InvalidPortID
Definition: types.hh:236
IntMasterPort< Interrupts > intMasterPort
Definition: interrupts.hh:179
Bitfield< 10, 8 > deliveryMode
Definition: interrupts.hh:84
void completeIPI(PacketPtr pkt)
Definition: interrupts.cc:330
uint32_t readReg(ApicRegIndex miscReg)
Definition: interrupts.cc:365
int findRegArrayMSB(ApicRegIndex base)
Definition: interrupts.hh:128
void setRegNoEffect(ApicRegIndex reg, uint32_t val)
Definition: interrupts.hh:249
Bitfield< 16 > masked
Definition: interrupts.hh:89
void updateIntrInfo(ThreadContext *tc) override
Definition: interrupts.cc:685
void setReg(ApicRegIndex reg, uint32_t val)
Definition: interrupts.cc:403
Definition: system.hh:72
Definition: cprintf.cc:40
bool hasPendingUnmaskable() const
Check if there are pending unmaskable interrupts.
Definition: interrupts.hh:277
AddrRangeList getAddrRanges() const
Definition: interrupts.cc:344
ThreadContext is the external interface to all thread state for anything outside of the CPU...
BitUnion32(LVTEntry) Bitfield< 7
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: interrupts.cc:289
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: interrupts.hh:229
Bitfield< 63 > val
Definition: misc.hh:769
EndBitUnion(LVTEntry) EventFunctionWrapper apicTimerEvent
Bitfield< 13 > polarity
Definition: interrupts.hh:86
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:123
Interrupts(Params *p)
Definition: interrupts.cc:596
bool checkInterrupts(ThreadContext *tc) const override
Definition: interrupts.cc:621
X86LocalApicParams Params
Definition: interrupts.hh:194
Fault getInterrupt(ThreadContext *tc) override
Definition: interrupts.cc:651
void setRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:152
uint64_t Tick
Tick count type.
Definition: types.hh:61
bool getRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:164
PioPort< Interrupts > pioPort
Definition: interrupts.hh:182
void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level)
Definition: interrupts.cc:224
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
ApicRegIndex decodeAddr(Addr paddr)
Definition: interrupts.cc:81
uint32_t regs[NUM_APIC_REGS]
Definition: interrupts.hh:80
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
Tick recvMessage(PacketPtr pkt)
Definition: interrupts.cc:302
ApicRegIndex
Definition: apic.hh:36
Tick read(PacketPtr pkt)
Definition: interrupts.cc:190
Bitfield< 20 > level
Definition: intmessage.hh:47
bool checkInterruptsRaw() const
Check if there are pending interrupts without ignoring the interrupts disabled flag.
Definition: interrupts.cc:643
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: interrupts.cc:720
void clear(int int_num, int index) override
Definition: interrupts.hh:298
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain...
Definition: clock_domain.hh:68
std::ostream CheckpointOut
Definition: serialize.hh:63
int divideFromConf(uint32_t conf)
Definition: interrupts.cc:67
This is exposed globally, independent of the ISA.
Definition: acpi.hh:55
Tick write(PacketPtr pkt)
Definition: interrupts.cc:207
IntSlavePort< Interrupts > intSlavePort
Definition: interrupts.hh:178
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
Bitfield< 12 > status
Definition: interrupts.hh:85
int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:203
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:235
Bitfield< 0 > p
Definition: pagetable.hh:151
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: interrupts.cc:745
const Params * params() const
Definition: interrupts.hh:199
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:71
bool triggerTimerInterrupt()
Definition: interrupts.hh:218
The PioPort class is a programmed i/o port that all devices that are sensitive to an address range us...
Definition: io_device.hh:60
void processApicTimerEvent()
Definition: interrupts.cc:783
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
void clearAll() override
Definition: interrupts.hh:304
void clearRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:158
Bitfield< 15 > trigger
Definition: interrupts.hh:88
Tick clockPeriod() const
Definition: interrupts.hh:169
ClockDomain & clockDomain
Definition: interrupts.hh:77
Tick clockPeriod() const
Get the clock period.
AddrRangeList getIntAddrRange() const
Definition: interrupts.cc:354

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