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

Fix mipsel syscall handling

This commit is contained in:
Jiajie Chen 2020-07-07 16:57:37 +08:00
parent 6a3a85ca5a
commit e554754e79
8 changed files with 55 additions and 25 deletions

View File

@ -35,10 +35,8 @@
### interrupt/consts
- fn is_page_fault(trap: usize):是否缺页
- IrqMin中断的最小 trap
- IrqMax中断的最大 trap
- Syscall系统调用的 trap
- Timer时钟中断的 trap
- fn is_syscall(trap: usize):是否系统调用
- fn is_intr(trap: usize):是否中断
### interrupt/handler

View File

@ -28,3 +28,11 @@ pub const Timer: usize = 0x10002;
// from el0, sync
pub const Syscall: usize = 0x00002;
pub fn is_syscall(trap: usize) -> bool {
trap == Syscall
}
pub fn is_intr(trap: usize) -> bool {
IrqMin <= trap && trap <= IrqMax
}

View File

@ -1,11 +1,5 @@
use mips::registers::cp0;
pub const IrqMin: usize = 0x20;
pub const IrqMax: usize = 0x3f;
pub const Syscall: usize = 0x100;
pub const Timer: usize = IrqMin + 0;
pub fn is_page_fault(trap: usize) -> bool {
use cp0::cause::Exception as E;
let cause = cp0::cause::Cause { bits: trap as u32 };
@ -16,3 +10,21 @@ pub fn is_page_fault(trap: usize) -> bool {
_ => false,
}
}
pub fn is_syscall(trap: usize) -> bool {
use cp0::cause::Exception as E;
let cause = cp0::cause::Cause { bits: trap as u32 };
match cause.cause() {
E::Syscall => true,
_ => false,
}
}
pub fn is_intr(trap: usize) -> bool {
use cp0::cause::Exception as E;
let cause = cp0::cause::Cause { bits: trap as u32 };
match cause.cause() {
E::Interrupt => true,
_ => false,
}
}

View File

@ -64,7 +64,7 @@ pub extern "C" fn trap_handler(tf: &mut TrapFrame) {
let cause = cp0::cause::Cause {
bits: tf.cause as u32,
};
trace!("Exception @ CPU{}: {:?} ", 0, cause.cause());
debug!("Exception @ CPU{}: {:?} ", 0, cause.cause());
match cause.cause() {
E::Interrupt => interrupt_dispatcher(tf),
E::Syscall => syscall(tf),

View File

@ -13,3 +13,11 @@ pub const SupervisorExternal: usize = usize::MAX / 2 + 1 + 8;
pub fn is_page_fault(trap: usize) -> bool {
trap == InstructionPageFault || trap == LoadPageFault || trap == StorePageFault
}
pub fn is_syscall(trap: usize) -> bool {
trap == Syscall
}
pub fn is_intr(trap: usize) -> bool {
IrqMin <= trap && trap <= IrqMax
}

View File

@ -49,3 +49,11 @@ pub const IPIFuncCall: usize = 0xfc;
pub fn is_page_fault(trap: usize) -> bool {
trap == PageFault
}
pub fn is_syscall(trap: usize) -> bool {
trap == Syscall
}
pub fn is_intr(trap: usize) -> bool {
IrqMin <= trap && trap <= IrqMax
}

View File

@ -2,7 +2,7 @@ use super::{
abi::{self, ProcInitInfo},
add_to_process_table, Pid, Process, PROCESSORS,
};
use crate::arch::interrupt::consts::{is_page_fault, IrqMax, IrqMin, Syscall, Timer};
use crate::arch::interrupt::consts::{is_intr, is_page_fault, is_syscall};
use crate::arch::interrupt::{get_trap_num, handle_user_page_fault};
use crate::arch::{
cpu,
@ -516,13 +516,10 @@ pub fn spawn(thread: Arc<Thread>) {
panic!("page fault handle failed");
}
}
Syscall => exit = handle_syscall(&thread, cx).await,
IrqMin..=IrqMax => {
_ if is_syscall(trap_num) => exit = handle_syscall(&thread, cx).await,
_ if is_intr(trap_num) => {
crate::arch::interrupt::ack(trap_num);
trace!("handle irq {:#x}", trap_num);
if trap_num == Timer {
//crate::arch::interrupt::timer();
}
IRQ_MANAGER.read().try_handle_interrupt(Some(trap_num));
}
_ => {

View File

@ -56,11 +56,17 @@ pub async fn handle_syscall(thread: &Arc<Thread>, context: &mut UserContext) ->
let regs = &context.general;
let num = context.get_syscall_num();
let args = context.get_syscall_args();
// add before fork
#[cfg(riscv)]
{
context.sepc = context.sepc + 4;
}
#[cfg(mips)]
{
context.epc = context.epc + 4;
}
let mut syscall = Syscall {
thread,
context,
@ -505,14 +511,7 @@ impl Syscall<'_> {
SYS_FCNTL64 => self.unimplemented("fcntl64", Ok(0)),
SYS_SET_THREAD_AREA => {
info!("set_thread_area: tls: 0x{:x}", args[0]);
extern "C" {
fn _cur_tls();
}
unsafe {
llvm_asm!("mtc0 $0, $$4, 2": :"r"(args[0]));
*(_cur_tls as *mut usize) = args[0];
}
self.context.tls = args[0];
Ok(0)
}
SYS_IPC => match args[0] {