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:
parent
6a3a85ca5a
commit
e554754e79
@ -35,10 +35,8 @@
|
|||||||
### interrupt/consts
|
### interrupt/consts
|
||||||
|
|
||||||
- fn is_page_fault(trap: usize):是否缺页
|
- fn is_page_fault(trap: usize):是否缺页
|
||||||
- IrqMin:中断的最小 trap
|
- fn is_syscall(trap: usize):是否系统调用
|
||||||
- IrqMax:中断的最大 trap
|
- fn is_intr(trap: usize):是否中断
|
||||||
- Syscall:系统调用的 trap
|
|
||||||
- Timer:时钟中断的 trap
|
|
||||||
|
|
||||||
### interrupt/handler
|
### interrupt/handler
|
||||||
|
|
||||||
|
@ -28,3 +28,11 @@ pub const Timer: usize = 0x10002;
|
|||||||
|
|
||||||
// from el0, sync
|
// from el0, sync
|
||||||
pub const Syscall: usize = 0x00002;
|
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
|
||||||
|
}
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
use mips::registers::cp0;
|
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 {
|
pub fn is_page_fault(trap: usize) -> bool {
|
||||||
use cp0::cause::Exception as E;
|
use cp0::cause::Exception as E;
|
||||||
let cause = cp0::cause::Cause { bits: trap as u32 };
|
let cause = cp0::cause::Cause { bits: trap as u32 };
|
||||||
@ -16,3 +10,21 @@ pub fn is_page_fault(trap: usize) -> bool {
|
|||||||
_ => false,
|
_ => 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -64,7 +64,7 @@ pub extern "C" fn trap_handler(tf: &mut TrapFrame) {
|
|||||||
let cause = cp0::cause::Cause {
|
let cause = cp0::cause::Cause {
|
||||||
bits: tf.cause as u32,
|
bits: tf.cause as u32,
|
||||||
};
|
};
|
||||||
trace!("Exception @ CPU{}: {:?} ", 0, cause.cause());
|
debug!("Exception @ CPU{}: {:?} ", 0, cause.cause());
|
||||||
match cause.cause() {
|
match cause.cause() {
|
||||||
E::Interrupt => interrupt_dispatcher(tf),
|
E::Interrupt => interrupt_dispatcher(tf),
|
||||||
E::Syscall => syscall(tf),
|
E::Syscall => syscall(tf),
|
||||||
|
@ -13,3 +13,11 @@ pub const SupervisorExternal: usize = usize::MAX / 2 + 1 + 8;
|
|||||||
pub fn is_page_fault(trap: usize) -> bool {
|
pub fn is_page_fault(trap: usize) -> bool {
|
||||||
trap == InstructionPageFault || trap == LoadPageFault || trap == StorePageFault
|
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
|
||||||
|
}
|
||||||
|
@ -49,3 +49,11 @@ pub const IPIFuncCall: usize = 0xfc;
|
|||||||
pub fn is_page_fault(trap: usize) -> bool {
|
pub fn is_page_fault(trap: usize) -> bool {
|
||||||
trap == PageFault
|
trap == PageFault
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_syscall(trap: usize) -> bool {
|
||||||
|
trap == Syscall
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_intr(trap: usize) -> bool {
|
||||||
|
IrqMin <= trap && trap <= IrqMax
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ use super::{
|
|||||||
abi::{self, ProcInitInfo},
|
abi::{self, ProcInitInfo},
|
||||||
add_to_process_table, Pid, Process, PROCESSORS,
|
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::interrupt::{get_trap_num, handle_user_page_fault};
|
||||||
use crate::arch::{
|
use crate::arch::{
|
||||||
cpu,
|
cpu,
|
||||||
@ -516,13 +516,10 @@ pub fn spawn(thread: Arc<Thread>) {
|
|||||||
panic!("page fault handle failed");
|
panic!("page fault handle failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Syscall => exit = handle_syscall(&thread, cx).await,
|
_ if is_syscall(trap_num) => exit = handle_syscall(&thread, cx).await,
|
||||||
IrqMin..=IrqMax => {
|
_ if is_intr(trap_num) => {
|
||||||
crate::arch::interrupt::ack(trap_num);
|
crate::arch::interrupt::ack(trap_num);
|
||||||
trace!("handle irq {:#x}", 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));
|
IRQ_MANAGER.read().try_handle_interrupt(Some(trap_num));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -56,11 +56,17 @@ pub async fn handle_syscall(thread: &Arc<Thread>, context: &mut UserContext) ->
|
|||||||
let regs = &context.general;
|
let regs = &context.general;
|
||||||
let num = context.get_syscall_num();
|
let num = context.get_syscall_num();
|
||||||
let args = context.get_syscall_args();
|
let args = context.get_syscall_args();
|
||||||
|
|
||||||
// add before fork
|
// add before fork
|
||||||
#[cfg(riscv)]
|
#[cfg(riscv)]
|
||||||
{
|
{
|
||||||
context.sepc = context.sepc + 4;
|
context.sepc = context.sepc + 4;
|
||||||
}
|
}
|
||||||
|
#[cfg(mips)]
|
||||||
|
{
|
||||||
|
context.epc = context.epc + 4;
|
||||||
|
}
|
||||||
|
|
||||||
let mut syscall = Syscall {
|
let mut syscall = Syscall {
|
||||||
thread,
|
thread,
|
||||||
context,
|
context,
|
||||||
@ -505,14 +511,7 @@ impl Syscall<'_> {
|
|||||||
SYS_FCNTL64 => self.unimplemented("fcntl64", Ok(0)),
|
SYS_FCNTL64 => self.unimplemented("fcntl64", Ok(0)),
|
||||||
SYS_SET_THREAD_AREA => {
|
SYS_SET_THREAD_AREA => {
|
||||||
info!("set_thread_area: tls: 0x{:x}", args[0]);
|
info!("set_thread_area: tls: 0x{:x}", args[0]);
|
||||||
extern "C" {
|
self.context.tls = args[0];
|
||||||
fn _cur_tls();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
llvm_asm!("mtc0 $0, $$4, 2": :"r"(args[0]));
|
|
||||||
*(_cur_tls as *mut usize) = args[0];
|
|
||||||
}
|
|
||||||
Ok(0)
|
Ok(0)
|
||||||
}
|
}
|
||||||
SYS_IPC => match args[0] {
|
SYS_IPC => match args[0] {
|
||||||
|
Loading…
Reference in New Issue
Block a user