Limited direct execution: programs run on the real hardware but the OS can regain control

For the OS to run a user program on real hardware, we need to:

  1. Put the CPU into user mode
  2. Jump to the user program code in memory
  3. Ensure that it eventually somehow jumps back to the OS

For example, on Intel CPUs, the iret instruction performs the first two. The third one depends on our scheduler:

  • A preemptive scheduler would use a timer interrupt that fires periodically
  • A cooperative scheduler would rely on the program doing I/O or yielding

Any interrupt will put the CPU into kernel mode and jump into the OS:

  • Timer interrupt: hardware interrupt raised by programmable timer
  • Doing I/O or yielding: software interrupt / system call