How system calls get into/out of the kernel
What happens if the shell printing a prompt with write(2, “$ “, 2)?
Key Concepts
The overall trajectory
write()
trampoline / uservec
usertrap() in trap.c
syscall() in syscall.c
sys_write() in sysfile.c
usertrapret()
trampoline / userret
write()what’s the state of the machine at this point?
trapframe content, set up in advance by kernel
special RISC-V registers (many more, here are relevant ones)
C function calling convention on RISC-V
The flow
Phase 1(set up)
Phase 2(trampoline to kernel)
Phase 3 (Handle system call trap)
Phase 4 (Prepare to return to user space)
Phase 5 (Jump to user page table)
Phase 6 (Return to user mode and user PC)
Last updated