Expand description
Trap handling functionality
For rCore, we have a single trap entry point, namely __alltraps
. At
initialization in init()
, we set the stvec
CSR to point to it.
All traps go through __alltraps
, which is defined in trap.S
. The
assembly language code does just enough work restore the kernel space
context, ensuring that Rust code safely runs, and transfers control to
trap_handler()
.
It then calls different functionality based on what exactly the exception
was. For example, timer interrupts trigger task preemption, and syscalls go
to syscall()
.
Modulesยง
- context ๐
- Implementation of
TrapContext
Structsยง
- Trap
Context - trap context structure containing sstatus, sepc and registers
Functionsยง
- enable_
timer_ interrupt - enable timer interrupt in sie CSR
- init
- initialize CSR
stvec
as the entry of__alltraps
- set_
kernel_ ๐trap_ entry - set_
user_ ๐trap_ entry - trap_
from_ kernel - Unimplement: traps/interrupts/exceptions from kernel mode Todo: Chapter 9: I/O device
- trap_
handler - handle an interrupt, exception, or system call from user space
- trap_
return - set the new addr of __restore asm function in TRAMPOLINE page, set the reg a0 = trap_cx_ptr, reg a1 = phy addr of usr page table, finally, jump to new addr of __restore asm function