System Call Traps
User code invokes kernel services by initiating system call traps.
- Programs in C, C++, etc. invoke system calls by linking to a standard library of procedures written in assembly language.
the library defines a stub or wrapper routine for each syscall
stub executes a special trap instruction (e.g., chmk or callsys)
syscall arguments/results passed in registers or user stack
read() in Unix libc.a library (executes in user mode):
#define SYSCALL_READ 27 # code for a read system call
move arg0…argn, a0…an # syscall args in registers A0..AN
move SYSCALL_READ, v0 # syscall dispatch code in V0
move r1, _errno # errno = return status