Last active
January 8, 2018 20:25
-
-
Save mark-i-m/b119d46f328b356aea9f36c9951fd5ce to your computer and use it in GitHub Desktop.
Trying out proposed inline asm syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub unsafe extern "C" fn irq0() { | |
asm!{ | |
" | |
push %rax | |
movq $0, %rax | |
", | |
// No inputs | |
// No outputs | |
clobber("rax", "rsp") | |
}; | |
irq_common() | |
} | |
#[naked] | |
#[inline] | |
unsafe fn irq_common() -> ! { | |
let irq: usize; | |
let context_ptr: *mut IrqContext; | |
// Save all registers | |
asm!{ | |
" | |
push %rbx | |
push %rcx | |
push %rdx | |
push %rsi | |
push %rdi | |
push %rbp | |
push %r8 | |
push %r9 | |
push %r10 | |
push %r11 | |
push %r12 | |
push %r13 | |
push %r14 | |
push %r15 | |
mov %cr2, %rbp | |
push %rbp | |
mov %rsp, {ctxp} | |
mov %rax, {irq_num} | |
", | |
// No inputs | |
ctxp = out(reg) context_ptr, | |
irq_num = out(reg) irq, | |
clobber("rbp", "rax", "rsp"), | |
}; | |
// Handle interrupt | |
pic_irq(irq, &mut *context_ptr); | |
// Pop arguments and iretq | |
asm!{ | |
" | |
pop %rbp | |
mov %rbp, %cr2 | |
pop %r15 | |
pop %r14 | |
pop %r13 | |
pop %r12 | |
pop %r11 | |
pop %r10 | |
pop %r9 | |
pop %r8 | |
pop %rbp | |
pop %rdi | |
pop %rsi | |
pop %rdx | |
pop %rcx | |
pop %rbx | |
pop %rax | |
iretq | |
", | |
// No inputs | |
// No outputs | |
clobber("rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "rsp", "r8", | |
"r9", "r10", "r11", "r12", "r13", "r14", "r15"), | |
flags("volatile") // Changes %cr2 and does iretq | |
}; | |
panic!("Should never get here!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment