Introduction to Operating Systems

04 Jun 2019

What is an Operating System?

An operating system is a layer of software between many applications and diverse hardware that:

  1. Provides a hardware abstraction so an application doesn’t have to know details about the hardware. Otherwise an application saving a file to disk would have to know how the disk operates for example.

  2. Arbitrates access to resources among multiple applications:
    • Sharing of resources.
    • Isolation protects apps from each other.
  3. Provides protections:
    • Isolation protects apps from each other.
    • Isolation also protects the OS from apps.
    • Isolation limits resource consumption by any one app.

A PC operating system consists of multiple components:

  • scheduler
  • virtual memory system
  • file system
  • device management
  • other…

Different OS flavors have different design goals.

  • Linux is a monolithic kernel: complex, contains many components
  • Mach OS is a microkernel: only contains scheduler, memory manager, and inter-processes communication (messaging)

Protection in Operating Systems

  1. Prevents applications from writing into privileged memory. -e.g. of another app or OS kernel.

  2. Prevents applications from invoking privileged functions. -e.g. OS kernel functions.

Privileged Instructions Examples

  • Memory address mapping
  • Flush or invalidate data cache
  • Invalidate TLB (Transition Lookaside Buffer) entries
  • Load and read system registers
  • Change processor modes from K to U
  • Change the voltage and frequency of processors
  • Halt/reset processor
  • Perform I/O operations

What is a unit of work for an OS?

  • Application
  • Task
    • Code -> placed into memory
    • Data -> stored in memory
    • OS data for task -> task descriptors
  • Job
  • Process

How can we access the OS functionality?

The Problem: If a task is protected from getting into the OS code and data, OS functionality is restricted from these tasks.

  • How does the CPU know if a certain instruction should be allowed?
  • How does the OS grant a task access to certain OS data structures, but not others?
  • How can we switch from running the task’s code to running the OS’s code?

The Answer: We need to use a hardware assistant called the mode bit.

Kernel Mode vs. User Mode

Processors include a hardware mode bit that identifies whether the system is in user mode or supervisor/kernel mode. This requires extra support from the CPU hardware for this OS feature.

  • Supervisor or kernel mode (mode bit = 0)
    • Can execute all the machine instructions, including privileged instructions.
    • Can reference all memory locations.
    • Kernel executes in this mode.
  • User mode (mode bit = 1)
    • Can only execute a subset of non-privileged instructions.
    • Can only reference a subset of memory locations.
    • All applications run in user mode.

Multiple Rings/Modes of Privilege

  • Intel x86 cPUs support four modes or rinds of privilege.
  • Common configuration:
    • OS like Linux or Windows runs in ring 0 (highest privilege), apps run in ring 3, and rings 1-2 are unused.
  • Virtual machines are another possible configuration.
    • VM’s hypervisor runs in ring 0, guest OS runs in ring 1 or 2, and apps run in ring 3.
Top