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
//! 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::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.
#[allow(unused)]
pub const TIMER_MS: usize = 50;

/// 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,
    Syscall = 0x80,
    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);

    // TODO: BSB A2 - Initialize the IOAPIC and configure the keyboard

    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);

    // TODO: BSB A5 - Initialize the timer for the scheduler
}

/// Notify the end of the interrupt handling.
#[allow(unused)]
fn eoi(_vector: u8) {
    LAPIC.eoi();
}