1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 08:26:17 +04:00

support 'syscall' instruction by handling invalid opcode exception

This commit is contained in:
WangRunji 2019-02-18 22:34:44 +08:00
parent a6b0da0c2f
commit 8a1a38853e

View File

@ -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);
}