Risc-V Xv6 Syscall Procedure
Risc-V Xv6 Syscall Procedure
-
User syscall function loads corresponding syscall number into register
a7, then executeecall. -
What
ecalldoes in risc-v are basically 3 things:- Change user mode into super mode.
- Save program counter in
pcintosepc. - Load value in
stvecintopc. - Resume execution.
Through steps above, the next instruction which will be executed is what the address in
stvecpoints to. Usually, the first instruction whichstvecpoints to will be the start of procedure of saving all the 32 user registers(by using a extra registersscrath). -
Save all the user registers.
-
Set kernel page table, and other relavent info
-
Jump to the function in kernel which handles the trap.
-
Some settings to handle trap from kernel.
-
The function above will call corresponding syscall accroding to the syscall number.
-
Execute syscall, and put return value back to
a0. -
Restore the user register, and execute
sret. -
sretchanges mode to user mode, turns on interuption, and puts$sepcintopc. -
Resume execution.
Actually, xv6 saves all the user registers and a bunch of other infomation in trapframe, which is allocated per process. For other details, refer to xv6book chapter4
浙公网安备 33010602011771号