Information Technology Reference
In-Depth Information
UNIX and kernel stacks
In the original implementation of UNIX, kernel memory was at a premium, because
main memory was roughly one million times more expensive per byte than it is today.
The initial system could run with only 50KB of main memory. Instead of allocating an
entire interrupt stack per process, UNIX allocated just enough memory in the process
control block to store the user-level registers saved on a mode switch. This way, UNIX
could suspend a user-level process with the minimal amount of memory. UNIX still
needed a few kernel stacks: one to run the interrupt handler and one for every system
call waiting for an I/O event to complete, but that is much less than one for every process.
Of course, now that memory is much cheaper, most systems keep things simple and
allocate a kernel stack per process or thread.
and not ignored. Once a corresponding enable interrupt instruction is executed,
any pending interrupts are delivered to the processor. The instructions to mask
and unmask interrupts must be privileged | otherwise, user code could inad-
vertently or maliciously disable the hardware timer, allowing the machine to
freeze.
If the processor is running in kernel-mode with interrupts enabled, then if
an interrupt occurs, it is safe to simply use the current stack pointer rather than
resetting it to the base of the exception stack. This approach can recursively
push a series of handlers' states onto the stack; then, as each one completes, its
state is popped from the stack and the earlier handler is resumed where it left
o.
Hardware support for saving and restoring registers
The interrupted process's registers must be saved before the handler changes any
of them so that the process can be restarted exactly as it left of This is tricky
because we have to save the registers without changing them in the process.
Typically, the hardware provides some support to help with this process.
To make this concrete, consider the x86 architecture. First, rather than
relying on the handler software to save all of the registers, when a context
switch occurs the x86 hardware:
If in user-mode, pushes the interrupted process's stack pointer onto the
kernel's exception stack, and switches to the kernel stack.
Pushes the interrupted process's instruction pointer.
Pushes the x86 processor status word. The processor status word includes
control bits such as whether the most recent arithmetic operation in the
Search WWH ::




Custom Search