MIT6.S081 Lecture6 Isolation and syscall
Lec6- Isolation and syscall
Supervisor registers
- stap – Store the page table’s base address
- stvec – Store the address of trap program –
trampolines, note that this address is mapped on user’s page table but withoutPTE_Uwhich means the user can’t modify it. - sepc – Store the address in the user mode when ecall happens
- sstrach – Store the address of
trapframewhich stores a frame useds to temporarily keep the user’s registers. Also used as swap “transfer station” register.- See the usage of
csrrw a0, sstrach, a0in the trampoline.S for some examples.
- See the usage of
Work Flow
1 | user_syscall() |
Some interesting features:
When user functions use ecall trying to enter kernel mode, what the RISCV actually does is just fetch the address at
stvecand jump to that address and execute.Ecall fetches the value from
stvecand saves thepcin thesepc.You shall see the page table haven’t been changed after ecall.
stvecregister keep the address oftrampolineThe last two line in the page table are exactly the kernel mode’s code, but mapped at user’s page table. Note PTE_U are not set, so user mode can’t access them.

trampolineare the two-direction bridge for both user and kernel, because its physical address for user and kernel are both map to the same virtual address.Based on above handy design, we could do
satpchange and save 32 register intotrapframe.Note that
sstrachinitially store the address oftrapframethen swap the content with a0.Finally load kernel stack pointer and usertrap address then jump to kernel c code.
trap.cchecks the reason of the trap and redirect the following trap to jump tpkernelvecinstead of trampoline. Then it analysis the cause number (in lecture’s example, we use syscall, so # is 8)- For syscall, what
usertrap()does is jump to syscall() function and syscall() will change the trapframe->a0’s value to make it received by user as the return value.
- For syscall, what

