Limited direct execution

How the CPU runs a program at full speed while the operating system still keeps control, following the Mechanism: Limited Direct Execution chapter of OSTEP (Chapter 6). Walk through the four protocols one line at a time and watch the mode bit, the kernel stack and the saved registers change.

CPU

no mode bit
PC
—
registers
—

Trap table (set at boot, in kernel mode)

    Kernel stacks — saved by the hardware

    Process list — saved by the OS

     

    Keys: → next, ← back, space play or pause, 1–4 switch protocol.

    What to take away

      Reading the table

      • The OS column runs in kernel mode, with full privilege.
      • The hardware column happens by itself, with no software involved.
      • The program column runs in user mode, on the real CPU, at full speed.
      • The highlighted line is the one running now.

      Registers are saved twice on a switch: the hardware pushes them onto the kernel stack on every trap, and the OS copies them into the process structure when it decides to switch.