I'm been walking through the code in OS/161 with respect to how systems calls are executed. From what I can see, a system call (e.g. reboot()
) is actually translated by the OS/161 kernel into a call to sys_reboot()
. Similarly, a call to fork()
would be translated to a call to sys_fork()
.
Is my understanding correct?
Thanks.
Each system call has a unique identifying number, in OS161 these system call numbers are defined in kern/include/kern/syscall.h:
#define SYS_reboot 119
The library procedure reboot() places the syscall number in a register (v0) and issues a trap to the OS, the syscall handler receives from the assembly-language exception handler a data structure called trapframe which contains, among other information, the system call number.
This number is used in a switch case statement to select the function:
void syscall(struct trapframe *tf)
...
callno = tf->tf_v0;
...
switch (callno) {
case SYS_reboot:
err = sys_reboot(tf->tf_a0);
break;