ACK for APIC IRQ

master
WangRunji 7 years ago
parent 156034c3d1
commit 3b792baf5b

@ -11,6 +11,7 @@ assembly_source_files := $(wildcard $(boot_src)/*.asm)
assembly_object_files := $(patsubst $(boot_src)/%.asm, \ assembly_object_files := $(patsubst $(boot_src)/%.asm, \
build/arch/$(arch)/boot/%.o, $(assembly_source_files)) build/arch/$(arch)/boot/%.o, $(assembly_source_files))
qemu_opts := -cdrom $(iso) -smp 2 -serial mon:stdio qemu_opts := -cdrom $(iso) -smp 2 -serial mon:stdio
features := use_apic
ifdef travis ifdef travis
test := 1 test := 1

@ -98,3 +98,11 @@ lapicinit(void)
// Enable interrupts on the APIC (but not on the processor). // Enable interrupts on the APIC (but not on the processor).
lapicw(TPR, 0); lapicw(TPR, 0);
} }
// Acknowledge interrupt.
void
lapiceoi(void)
{
if(lapic)
lapicw(EOI, 0);
}

@ -1,6 +1,7 @@
extern { extern {
static mut lapic: *const (); static mut lapic: *const ();
fn lapicinit(); // must set `lapic` first fn lapicinit(); // must set `lapic` first
fn lapiceoi(); // ack
} }
pub fn init(lapic_addr: *const ()) { pub fn init(lapic_addr: *const ()) {
@ -11,3 +12,9 @@ pub fn init(lapic_addr: *const ()) {
} }
debug!("lapic: init end"); debug!("lapic: init end");
} }
pub fn ack(_irq: u8) {
unsafe {
lapiceoi();
}
}

@ -1,4 +1,5 @@
pub use self::ioapic::IOAPIC; pub use self::ioapic::IOAPIC;
pub use self::lapic::ack;
mod lapic; mod lapic;
mod ioapic; mod ioapic;

@ -0,0 +1,9 @@
use x86_64;
pub fn enable() {
unsafe{ x86_64::instructions::interrupts::enable(); }
}
pub fn disable() {
unsafe{ x86_64::instructions::interrupts::disable(); }
}

@ -5,3 +5,4 @@ pub mod mp;
pub mod serial; pub mod serial;
pub mod pic; pub mod pic;
pub mod console; pub mod console;
pub mod interrupt;

@ -20,26 +20,30 @@ pub extern "x86-interrupt" fn page_fault_handler(
loop {} loop {}
} }
use arch::driver::pic; #[cfg(feature = "use_apic")]
use arch::driver::apic::ack;
#[cfg(not(feature = "use_apic"))]
use arch::driver::pic::ack;
use consts::irq::*; use consts::irq::*;
pub extern "x86-interrupt" fn keyboard_handler( pub extern "x86-interrupt" fn keyboard_handler(
stack_frame: &mut ExceptionStackFrame) stack_frame: &mut ExceptionStackFrame)
{ {
println!("\nInterupt: Keyboard \n{:#?}", stack_frame); println!("\nInterupt: Keyboard \n{:#?}", stack_frame);
pic::ack(IRQ_KBD); ack(IRQ_KBD);
} }
pub extern "x86-interrupt" fn serial_handler( pub extern "x86-interrupt" fn serial_handler(
stack_frame: &mut ExceptionStackFrame) stack_frame: &mut ExceptionStackFrame)
{ {
println!("\nInterupt: Serial \n{:#?}", stack_frame); println!("\nInterupt: Serial \n{:#?}", stack_frame);
pic::ack(IRQ_COM1); ack(IRQ_COM1);
} }
pub extern "x86-interrupt" fn timer_handler( pub extern "x86-interrupt" fn timer_handler(
stack_frame: &mut ExceptionStackFrame) stack_frame: &mut ExceptionStackFrame)
{ {
println!("\nInterupt: Timer \n{:#?}", stack_frame); println!("\nInterupt: Timer \n{:#?}", stack_frame);
pic::ack(IRQ_TIMER); ack(IRQ_TIMER);
} }

@ -85,7 +85,7 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) {
} else { } else {
arch::driver::pic::init(); arch::driver::pic::init();
} }
unsafe{ x86_64::instructions::interrupts::enable(); } arch::driver::interrupt::enable();
loop{} loop{}
test_end!(); test_end!();
} }

Loading…
Cancel
Save