#no-std #kernel #interrupts #apic

nightly no-std x2apic

A Rust interface to the x2apic interrupt architecture

7 unstable releases (3 breaking)

0.4.0 Oct 11, 2021
0.3.0 Jun 23, 2021
0.2.0 Jun 22, 2021
0.1.3 May 24, 2021
0.1.0 Jun 25, 2019

#72 in No standard library

25 downloads per month


912 lines


A Rust interface to the x2apic interrupt architecture.

This crate is in its early stages and has only been tested in QEMU; code contributions and bug reports are welcome.

It will use x2APIC mode if supported by the CPU, otherwise it falls back to xAPIC mode.


The local APIC is initialized like so:

use x2apic::lapic::{LocalApic, LocalApicBuilder, xapic_base};

let apic_physical_address: u64 = unsafe { xapic_base() };
let apic_virtual_address: u64 = <convert from physical address>

let lapic = LocalApicBuilder::new()
    .unwrap_or_else(|err| panic!("{}", err));

unsafe {

This initializes and enables the local APIC timer with a default configuration. The timer can be configured with the builder or directly on the APIC.

The IOAPIC is initialized like so:

use x2apic::ioapic::{IoApic, IrqFlags, IrqMode, RedirectionTableEntry};

// !!! Map the IOAPIC's MMIO address `addr` here !!!

unsafe {
    let ioapic = IoApic::new(addr);


    let mut entry = RedirectionTableEntry::default();
    entry.set_flags(IrqFlags::LEVEL_TRIGGERED | IrqFlags::LOW_ACTIVE | IrqFlags::MASKED);
    entry.set_dest(dest); // CPU(s)
    ioapic.set_table_entry(irq_number, entry);


Please refer to the documentation for more details.


~16K SLoC