x86_q35/
interrupts.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
5use x86::InterruptPoller;
6
7use super::pic;
8
9/// Handler for external interrupts.
10///
11/// This function is called by the [`x86`] crate to handle interrupts from external devices.
12/// It calls [`InterruptPoller::set_pending`] to mark the interrupt as pending, masks the specific
13/// interrupt, then issues an EOI message to the system interrupt controller so that subsequent
14/// interrupts can be delivered.
15///
16/// ## Safety
17///
18/// This function must only be called when handling an interrupt. It should _never_ be called by
19/// other Rust code.
20// `allow(unsupported_calling_conventions)`: cdecl is not valid when testing
21// this code on an x86_64 machine. This avoids a warning until a more permanent
22// fix is decided. See: https://github.com/tock/tock/pull/4662
23#[allow(unsupported_calling_conventions)]
24#[no_mangle]
25unsafe extern "cdecl" fn handle_external_interrupt(num: u32) {
26    unsafe {
27        InterruptPoller::set_pending(num);
28        pic::mask(num);
29        pic::eoi(num);
30    }
31}