- user.h
- syscalls.h
- syscall.c
- usys.pl
Trap generates from system calls, device interrupts and illegal instructions.
- stvec points to uservec.
- uservec mapped in same address in user and kernel so that kernel can continue running insruction after switch.
- uservec switches satp to point to kernel page table.
- kernel set sscratch to point to user trapframe.
- uservec swaps a0 with sscratch. Now a0 contains the trapframe.
- uservec saves all the user registers in the trapframe including a0 which is saved from sscratch.
- trapframe holds kernel page table, pointer to process's kernel stack, current cpu's heart id and pointer to usertrap.
- uservec retrieve these values and set setp to kernel page table and then call usertrap.
- usertrap determines the cause of trap, process it and return.
- usertrap set stvec to kernelvec, saves sepc again as there might be a process switch in usertrap(?), calls syscall/devintr/kill the process (faulty)
- To return to userspace usertrapret is called.