Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Syscalls

One way that the operating system can regain control from a user program is external interrupts from timers and I/O devices. These are “external” interrupts, because they are caused by entities outside the CPU. The operating system also deals with software exceptions, which are events that occur in program code. These can be errors such as a page fault or division by zero. Exceptions are also the means by which a user program can request system calls (syscalls) (i.e. services) from the operating system.

In the 80x86 architecture, the int instruction is the most commonly used means for invoking system calls. This instruction is handled in the same way as other software exceptions. In Pintos, user programs invoke int $0x30 to make a system call. The system call number and any additional arguments are expected to be pushed on the stack in the normal fashion before invoking the interrupt (see 80x86 Calling Convention).

Thus, when the system call handler syscall_handler gets control, the system call number is in the 32-bit word at the caller’s stack pointer, the first argument is in the 32-bit word at the next higher address, and so on. The caller’s stack pointer is accessible to syscall_handler as the esp member of the struct intr_frame passed to it. struct intr_frame is on the kernel stack.

The 80x86 convention for function return values is to place them in the eax register. System calls that return a value can do so by modifying the eax member of struct intr_frame.