Magic to make interrupt functions easy to write
This commit is contained in:
parent
2730144e2a
commit
b130f9a860
|
@ -1,10 +0,0 @@
|
||||||
//! # IRQ handling
|
|
||||||
//!
|
|
||||||
//! This module defines IRQ handling functions. These functions should all be #[naked],
|
|
||||||
//! unsafe, extern, and end in `iretq`
|
|
||||||
|
|
||||||
/// Interupt Request handler.
|
|
||||||
#[naked]
|
|
||||||
pub unsafe extern fn irq() {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! Architecture support for x86_64
|
//! Architecture support for x86_64
|
||||||
|
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
|
#![feature(concat_idents)]
|
||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(naked_functions)]
|
#![feature(naked_functions)]
|
||||||
|
@ -25,6 +26,47 @@ macro_rules! println {
|
||||||
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create an interrupt function that can safely run rust code
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! interrupt {
|
||||||
|
($name:ident, $func:block) => {
|
||||||
|
#[naked]
|
||||||
|
pub unsafe extern fn $name () {
|
||||||
|
unsafe fn inner() {
|
||||||
|
$func
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push scratch registers
|
||||||
|
asm!("push rax
|
||||||
|
push rcx
|
||||||
|
push rdx
|
||||||
|
push rdi
|
||||||
|
push rsi
|
||||||
|
push r8
|
||||||
|
push r9
|
||||||
|
push r10
|
||||||
|
push r11"
|
||||||
|
: : : : "intel", "volatile");
|
||||||
|
|
||||||
|
// Call inner rust function
|
||||||
|
inner();
|
||||||
|
|
||||||
|
// Pop scratch registers and return
|
||||||
|
asm!("pop r11
|
||||||
|
pop r10
|
||||||
|
pop r9
|
||||||
|
pop r8
|
||||||
|
pop rsi
|
||||||
|
pop rdi
|
||||||
|
pop rdx
|
||||||
|
pop rcx
|
||||||
|
pop rax
|
||||||
|
iretq"
|
||||||
|
: : : : "intel", "volatile");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Global descriptor table
|
/// Global descriptor table
|
||||||
pub mod gdt;
|
pub mod gdt;
|
||||||
|
|
||||||
|
@ -34,9 +76,6 @@ pub mod idt;
|
||||||
/// IO Handling
|
/// IO Handling
|
||||||
pub mod io;
|
pub mod io;
|
||||||
|
|
||||||
/// IRQ Handling
|
|
||||||
pub mod irq;
|
|
||||||
|
|
||||||
/// Interrupt instructions
|
/// Interrupt instructions
|
||||||
pub mod interrupt;
|
pub mod interrupt;
|
||||||
|
|
||||||
|
|
|
@ -71,8 +71,6 @@ pub unsafe extern fn kstart() -> ! {
|
||||||
kmain();
|
kmain();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[naked]
|
interrupt!(blank, {
|
||||||
pub unsafe extern fn blank() {
|
println!("INTERRUPT");
|
||||||
asm!("xchg bx, bx" : : : : "intel", "volatile");
|
});
|
||||||
asm!("iretq" : : : : "intel", "volatile");
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue