Efficiency / Convenience Tradeoff: Efficient systems are often not convenient
(e.g. smart phone optimize convenience vs. embedded system optimize efficiency)
OS Definition
Virtualization: Physical device → general form, share resources
- Limited Direct Execution: Physical CPU directly execute user instructions with limited priv.
- Virtual CPU + Virtual Memory: Illusion that each program owns the whole machine
- Abstraction: Process (a running program)
- Protected Domains: OS is allowed specific instructions that user processes cannot use
- Mode-bit (CPL): Either user mode or system (supervisor / privileged) mode
Illegal access cause protection fault
- Exceptions: Software signal or error
- Interrupts: Hardware signal for CPU to jump to a predefined interrupt handler instruction
- Hardware interrupts: Device events
- Timer: Periodic interrupt
- Useful for OS to regain control when the user process fail
Concurrency: Coordinate multiple activities
Persistence: Survive crashes
Implementing Interrupts
OS fill in Interrupt Table & IDTR (pointer to IT) at boot
When interrupt occur:
- CPU change to privileged mode, disable interrupts
- Save interrupted PC address
- Set PC = address at (IDTR + interrupt number) to run handler
- Continue execution
Bootstrapping
BIOS: Basic Input Output System
- BIOS load the OS boot-loader from disk
- Boot-loader load and run OS
OS Initialization
- Initialize machine-dependent operations
- Create init process (id=1)
- Switch to user mode, start running first process
- OS wait for interrupt or exception to happen