From 8a1a38853e0e51dc42662b8bf75268500e409dbb Mon Sep 17 00:00:00 2001 From: WangRunji Date: Mon, 18 Feb 2019 22:34:44 +0800 Subject: [PATCH] support 'syscall' instruction by handling invalid opcode exception --- kernel/src/arch/x86_64/interrupt/handler.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/src/arch/x86_64/interrupt/handler.rs b/kernel/src/arch/x86_64/interrupt/handler.rs index 8be3700..44b64b8 100644 --- a/kernel/src/arch/x86_64/interrupt/handler.rs +++ b/kernel/src/arch/x86_64/interrupt/handler.rs @@ -96,7 +96,8 @@ pub extern fn rust_trap(tf: &mut TrapFrame) { SwitchToUser => to_user(tf), Syscall => syscall(tf), Syscall32 => syscall32(tf), - DivideError | GeneralProtectionFault | InvalidOpcode => error(tf), + InvalidOpcode => invalid_opcode(tf), + DivideError | GeneralProtectionFault => error(tf), _ => panic!("Unhandled interrupt {:x}", tf.trap_num), } } @@ -172,6 +173,18 @@ fn syscall32(tf: &mut TrapFrame) { tf.rax = ret as usize; } +/// Support `syscall` instruction +fn invalid_opcode(tf: &mut TrapFrame) { + let opcode = unsafe { (tf.rip as *mut u16).read() }; + const SYSCALL_OPCODE: u16 = 0x05_0f; + if opcode == SYSCALL_OPCODE { + syscall(tf); + tf.rip += 2; + } else { + crate::trap::error(tf); + } +} + fn error(tf: &TrapFrame) { crate::trap::error(tf); }