A trap, in SPARC terms, is something that causes an immediate branch to kernel code ” an interruption of the normal stream of instructions. This interruption can be due to a user request (a system call) or some external event (a page fault, a disk interrupt, or a keystroke). In either case, the interrupt is processed by hardware and very low-level software, so understanding how traps work and how they are handled requires some understanding of the architecture of the system. The CPU hardware will identify the type of the trap and attempt to get to the right place to handle it; the kernel must set up some control registers to make sure the appropriate trap handling code can be reached. Once the system has started up and user processes are running, a trap is the only way the kernel will get control of the CPU from a user program. A trap is the means by which a user request is processed (the kernel is running on behalf of a user program) and the way a device is controlled (the kernel is running because of some external request). |