@@ -7,7 +7,10 @@ use core::sync::atomic::{AtomicUsize, Ordering};
77use lazy_static:: lazy_static;
88use testing:: { exit_qemu, serial_print, serial_println, QemuExitCode } ;
99
10+ use x86_64:: instructions:: interrupts;
11+
1012static BREAKPOINT_HANDLER_CALLED : AtomicUsize = AtomicUsize :: new ( 0 ) ;
13+ static INTERRUPT_HANDLER_CALLED : AtomicUsize = AtomicUsize :: new ( 0 ) ;
1114
1215#[ no_mangle]
1316pub extern "C" fn _start ( ) -> ! {
@@ -16,13 +19,10 @@ pub extern "C" fn _start() -> ! {
1619 init_test_idt ( ) ;
1720
1821 // invoke a breakpoint exception
19- x86_64 :: instructions :: interrupts:: int3 ( ) ;
22+ interrupts:: int3 ( ) ;
2023
2124 match BREAKPOINT_HANDLER_CALLED . load ( Ordering :: SeqCst ) {
22- 1 => {
23- serial_println ! ( "[ok]" ) ;
24- exit_qemu ( QemuExitCode :: Success ) ;
25- }
25+ 1 => { }
2626 0 => {
2727 serial_println ! ( "[failed]" ) ;
2828 serial_println ! ( " Breakpoint handler was not called." ) ;
@@ -35,6 +35,29 @@ pub extern "C" fn _start() -> ! {
3535 }
3636 }
3737
38+ serial_print ! ( "interrupt 42... " ) ;
39+ unsafe { interrupts:: software_interrupt :: < 42 > ( ) } ;
40+ serial_print ! ( "interrupt 77... " ) ;
41+ unsafe { interrupts:: software_interrupt :: < 77 > ( ) } ;
42+ serial_print ! ( "interrupt 42... " ) ;
43+ unsafe { interrupts:: software_interrupt :: < 42 > ( ) } ;
44+
45+ match INTERRUPT_HANDLER_CALLED . load ( Ordering :: SeqCst ) {
46+ 3 => { }
47+ 0 => {
48+ serial_println ! ( "[failed]" ) ;
49+ serial_println ! ( " Interrupt handler was not called." ) ;
50+ exit_qemu ( QemuExitCode :: Failed ) ;
51+ }
52+ other => {
53+ serial_println ! ( "[failed]" ) ;
54+ serial_println ! ( " Interrupt handler was called {} times" , other) ;
55+ exit_qemu ( QemuExitCode :: Failed ) ;
56+ }
57+ }
58+
59+ serial_println ! ( "[ok]" ) ;
60+ exit_qemu ( QemuExitCode :: Success ) ;
3861 loop { }
3962}
4063
@@ -49,6 +72,8 @@ lazy_static! {
4972 static ref TEST_IDT : InterruptDescriptorTable = {
5073 let mut idt = InterruptDescriptorTable :: new( ) ;
5174 idt. breakpoint. set_handler_fn( breakpoint_handler) ;
75+ idt[ 42 ] . set_handler_fn( interrupt_handler) ;
76+ idt[ 77 ] . set_handler_fn( interrupt_handler) ;
5277 idt
5378 } ;
5479}
@@ -60,3 +85,7 @@ pub fn init_test_idt() {
6085extern "x86-interrupt" fn breakpoint_handler ( _stack_frame : InterruptStackFrame ) {
6186 BREAKPOINT_HANDLER_CALLED . fetch_add ( 1 , Ordering :: SeqCst ) ;
6287}
88+
89+ extern "x86-interrupt" fn interrupt_handler ( _stack_frame : InterruptStackFrame ) {
90+ INTERRUPT_HANDLER_CALLED . fetch_add ( 1 , Ordering :: SeqCst ) ;
91+ }
0 commit comments