Sync computers

This commit is contained in:
2026-03-01 15:41:36 +01:00
parent 783c76252a
commit 392af94345
16 changed files with 479 additions and 315 deletions

View File

@@ -13,7 +13,7 @@ use crate::{
process::{exit_process, sleep, ExecutionContext},
read_csr,
riscv::disable_interrupt,
scheduler::scheduler_without_ret,
scheduler::SCHEDULER,
set_csr, syscall,
time::{setup_next_timer_interrupt, IRQ_M_TIMER},
write_csr,
@@ -123,8 +123,14 @@ unsafe extern "C" fn supervisor_trap_handler(
match syscall {
SysCall::Open => {
let path = unsafe { str::from_raw_parts(a1 as *const u8, a2 as usize) };
let fd = syscall::open(path, false);
unsafe { (*interrupt_state).a[0] = fd.unwrap() };
let virtual_node = syscall::open(path, false).unwrap();
let mut scheduler = SCHEDULER.lock();
let current_process = scheduler.get_current_process();
let fd = current_process.next_fd;
current_process.fd_table.insert(fd, virtual_node);
current_process.next_fd += 1;
unsafe { (*interrupt_state).a[0] = fd };
}
SysCall::Alloc => {
let layout = Layout::from_size_align(a1 as usize, a2 as usize).unwrap();
@@ -168,7 +174,7 @@ unsafe extern "C" fn supervisor_trap_handler(
);
}
timer_interrupt();
scheduler_without_ret(&mut interrupt_state);
SCHEDULER.lock().schedule(&mut interrupt_state);
}
_ => {}
}
@@ -253,7 +259,7 @@ unsafe extern "C" fn _machine_mode_trap() {
/// This stub saves the full register state and forwards control to
/// `supervisor_trap_handler` implemented in Rust.
unsafe extern "C" fn _supervisor_mode_trap() {
naked_asm!(concat!(
naked_asm!(
"
// Store sp before it gets modified
sd sp, 8-264(sp)
@@ -304,14 +310,14 @@ unsafe extern "C" fn _supervisor_mode_trap() {
# Restore registers and sret
jal restore_context"
))
)
}
#[unsafe(naked)]
#[unsafe(no_mangle)]
/// Restore a saved execution context and perform `sret` to return to user code.
pub unsafe extern "C" fn restore_context(context: *const ExecutionContext) -> ! {
naked_asm!(concat!(
naked_asm!(
"
ld t0, 248(a0)
csrw sepc, t0
@@ -351,7 +357,7 @@ pub unsafe extern "C" fn restore_context(context: *const ExecutionContext) -> !
ld a0, 32(a0)
sret"
))
)
}
#[repr(C)]