diff --git a/arch/x86_64/src/irq.rs b/arch/x86_64/src/irq.rs deleted file mode 100644 index bbceaa7..0000000 --- a/arch/x86_64/src/irq.rs +++ /dev/null @@ -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() { - -} diff --git a/arch/x86_64/src/lib.rs b/arch/x86_64/src/lib.rs index c9e6a5b..3b03958 100644 --- a/arch/x86_64/src/lib.rs +++ b/arch/x86_64/src/lib.rs @@ -1,6 +1,7 @@ //! Architecture support for x86_64 #![feature(asm)] +#![feature(concat_idents)] #![feature(const_fn)] #![feature(core_intrinsics)] #![feature(naked_functions)] @@ -25,6 +26,47 @@ macro_rules! println { ($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 pub mod gdt; @@ -34,9 +76,6 @@ pub mod idt; /// IO Handling pub mod io; -/// IRQ Handling -pub mod irq; - /// Interrupt instructions pub mod interrupt; diff --git a/arch/x86_64/src/main.rs b/arch/x86_64/src/main.rs index ad9640a..a17d19c 100644 --- a/arch/x86_64/src/main.rs +++ b/arch/x86_64/src/main.rs @@ -71,8 +71,6 @@ pub unsafe extern fn kstart() -> ! { kmain(); } -#[naked] -pub unsafe extern fn blank() { - asm!("xchg bx, bx" : : : : "intel", "volatile"); - asm!("iretq" : : : : "intel", "volatile"); -} +interrupt!(blank, { + println!("INTERRUPT"); +});