rstubs/interrupts/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Configures the interrupt handling.

use crate::arch::acpi::Acpi;
use crate::arch::cpu;
use crate::arch::int::apic::parse_apic_table;
use crate::arch::int::ioapic::{Device, IOAPIC};
use crate::arch::int::lapic::LAPIC;
use crate::arch::int::pic;

pub mod epilogue;
pub mod guard;
pub mod idt;

/// Time per cycle for the system timer in milliseconds.
pub const TIMER_MS: usize = 10;

/// Custom interrupt vectors.
///
/// These are defined and configured by us.
/// They have to be between 32 and 256.
#[derive(Debug, Clone, Copy)]
#[allow(unused)]
pub enum Vector {
    Timer = 32,
    Keyboard = 33,
    Serial = 34,
    Mouse = 44,
    Panic = 99,
    Assassin = 100,
    WakeUp = 101,
    Spurious = 0xff,
}

/// Initializes the shared interrupt controllers and return the number of local apic found.
pub fn setup_global(acpi: Acpi) -> usize {
    pic::init(pic::PicPort::new());

    let (ioapic_id, num_lapics) = parse_apic_table(acpi);

    IOAPIC.init(ioapic_id, Vector::Panic as u8 as _);
    IOAPIC.config(Device::Keyboard, Vector::Keyboard as u8, true);
    IOAPIC.enable(Device::Keyboard, true);

    num_lapics
}

/// Initialize the Interrupt Descriptor Table and Interrupt Controllers.
pub fn setup_local() {
    idt::load();

    let core_id = cpu::id();
    LAPIC.init(core_id as _);
    cpu::init(core_id);

    // Initialize the timer for the scheduler
    LAPIC.timer(TIMER_MS * 1000, Vector::Timer as _, true, false);
}

/// Notify the end of the interrupt handling.
fn eoi(_vector: u8) {
    LAPIC.eoi();
}