Outline for Today

  • Last time: Discussed "What does an OS do?" and how the course is going to function.

  • Administrative Details:

  • Course communications: web is up, newsgroup, mailing list (TODO: subscribe), your homepage (TODO: create).

  • Assignments: reading Ch 1-4, Homework 1 out.

  • Review the tentative schedule. Comments welcome soon.

  • Photo opportunities.

  • Objective: CPU hw - OS kernel - User code interactions


    Basic Storyline

  • (Review) Computing from the (purely) architectural point of view: instruction cycle, register state, DMA I/O, interrupts.

  • Introduce execution of user programs into the picture and we want to restrict user code from having direct access to (at least) I/O -> protected instructions, kernel/user modes, system calls.

  • Add sharing among multiple users -> memory protection, timers, instructions to assist synchronization, process abstraction.


    I/O and Interrupts

  • Start an I/O operation (special instructions or memory-mapped I/O)

  • Device controller performs the operation asynchronously (in parallel with) CPU processing (between controller's buffer & device).

  • If DMA, data transferred between controller's buffer and memory without CPU involvement.

  • Interrupt signals I/O completion when device is done.

  • CPU handles interrupt


    User / Kernel Modes

  • Hardware support to differentiate between what we'll allow user code to do by itself ( user mode) and what we'll have the OS do ( kernel mode).

  • Mode indicated by status bit in protected processor register.

  • Privileged instructions can only be executed in kernel mode (I/O instructions).


    Crossing Protection Boundaries

  • For a user to do something "privileged", it must invoke an OS procedure providing that service. How?

  • System Calls

  • special trap instruction that causes an exception which vectors to a kernel handler

  • parameters indicate which system routine called


    OS Entry


    Multiple User Programs

  • Sharing system resources requires that we protect programs from other incorrect programs.

  • protect from a bad user program walking all over the memory space of the OS and other user programs (memory protection).

  • protect from runaway user programs never relinquishing the CPU (e.g., infinite loops) (timers).

  • preserving the illusion of non-interruptable instruction sequences (synchronization mechanisms - ability to disable/enable interrupts, special "atomic" instructions).


    Memory Protection

  • Simplest scheme uses base and limit registers, loaded by OS (privileged operation) before starting program.

  • Issuing an address out of range causes an exception.


    Timer Operation

  • Timer set to generate an interrupt in a given time.

  • OS uses it to regain control from user code.

  • Sets timer before transferring to user code.

  • when time expires, the executing program is interrupted and the OS is back in control.

  • Setting timer is privileged.


    The Basics of Processes

  • Processes are the OS-provided abstraction of multiple tasks (including user programs) executing concurrently.

  • One instance of a program (which is only a passive set of bits) in execution (implying an execution context - register state, memory resources, etc.)

  • OS schedules processes to share CPU.


    Process State Transitions


    Context Switching

  • When a process is running, its program counter, register values, stack pointer, etc. are contained in the hardware registers of the CPU. The process has direct control of the CPU hardware for now.

  • When a process is not the one currently running, its current register values are saved in a process descriptor data structure (PCB - process control block)

  • Context switching involves moving state between CPU and various processes' PCBs by the OS.