1. 程式人生 > 其它 >Risc-V Xv6 Syscall Procedure

Risc-V Xv6 Syscall Procedure

Risc-V Xv6 Syscall Procedure

  1. User syscall function loads corresponding syscall number into register a7, then execute ecall.

  2. What ecall does in risc-v are basically 3 things:

    1. Change user mode into super mode.
    2. Save program counter in pc into sepc.
    3. Load value in stvec into pc.
    4. Resume execution.

    Through steps above, the next instruction which will be executed is what the address in stvec

    points to. Usually, the first instruction which stvec points to will be the start of procedure of saving all the 32 user registers(by using a extra register sscrath).

  3. Save all the user registers.

  4. Set kernel page table, and other relavent info

  5. Jump to the function in kernel which handles the trap.

  6. Some settings to handle trap from kernel.

  7. The function above will call corresponding syscall accroding to the syscall number.

  8. Execute syscall, and put return value back to a0.

  9. Restore the user register, and execute sret.

  10. sret changes mode to user mode, turns on interuption, and puts $sepc into pc

    .

  11. 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