x86/interrupts/
mod.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2024.
4
5//! Facilities for handling interrupts and CPU exceptions
6
7mod handlers;
8mod idt;
9mod poller;
10
11pub use self::poller::InterruptPoller;
12
13#[cfg(target_arch = "x86")]
14mod handler_stubs;
15
16#[cfg(target_arch = "x86")]
17mod handler_entry;
18
19/// Total number of interrupt vectors.
20pub const NUM_VECTORS: usize = 256;
21
22/// Interrupt number used for Tock system calls on x86.
23pub const SYSCALL_VECTOR: u8 = 0x40;
24
25/// Number of exceptions reserved in the IDT by Intel.
26/// Reference: <https://en.wikipedia.org/wiki/Interrupt_descriptor_table#Common_IDT_layouts>
27pub const IDT_RESERVED_EXCEPTIONS: u8 = 32;
28
29/// Performs global initialization of interrupt handling.
30///
31/// After calling this function, [`InterruptPoller`] can be used to poll for and handle interrupts.
32///
33/// ## Safety
34///
35/// This function must never be executed more than once.
36///
37/// The kernel's segmentation must already be initialized (via [`segmentation::init`][crate::segmentation::init])
38/// prior to calling this function, and it must never be changed afterwards.
39///
40/// After this function returns, it is safe to enable interrupts. However, interrupts below number
41/// 32 ([`IDT_RESERVED_EXCEPTIONS`]) must **never** be generated except by the CPU itself (i.e. exceptions),
42/// as doing so would interfere with the internal handler stubs. This means that before enabling interrupts,
43/// the caller must ensure that any hardware delivering external interrupts (such as the PIC/APIC) is
44/// configured to use interrupt number 32 or above.
45pub(crate) unsafe fn init() {
46    unsafe {
47        idt::init();
48    }
49}