Hardware
Hardware
Reading:
Silberschatz
chapter 2
Additional Reading:
Stallings
chapter 1, 2
EEL 602 1
Outline
Computer Hardware
CPU Components
Registers
Instruction Execution
Interrupt and Trap
Memory
Hierarchy
Cache
Dual Mode Operation
Protection
Hardware
Memory
CPU, I/O
EEL 602 2
Computer Hardware
¾ Why study hardware?
OS exploits hardware resources to provide set of services
¾ Key Elements
CPU or Processor
Main Memory
typically volatile
also referred as real memory or primary memory
I/O modules
secondary memory devices
communications equipment
terminals
System bus
communication among processors, memory, and I/O modules
EEL 602 3
CPU Components
EEL 602 5
User-Visible Registers
¾ Data registers
General purpose (programmers or machine)
May be dedicated (floating-point and integer operations)
¾ Address registers
Index
Involves adding an index to base value to get effective address
Segment pointer
When memory is divided into segments, memory is referenced
by a segment and an offset
Stack pointer
Points to top of stack
EEL 602 6
Control and Status Registers
Mostly not visible to user, organization is machine specific
¾ Program Counter
Contains the address of instruction to be fetched
¾ Instruction Register
Contains the instruction most recently fetched
EEL 602 7
Control and Status Registers
¾ Condition Codes or Flags
Bits set by the processor hardware as a result of
operations
Examples
Positive result
Negative result
Zero
Overflow
EEL 602 8
Instruction Execution
¾ Instruction Cycle – processing required for single instruction
¾ Two step processing in simplest form
Processor reads instructions from memory one at time
Fetches
Processor executes each instruction
EEL 602 9
Instruction Fetch and Execute
¾ The processor fetches the instruction from
memory
¾ Program counter (PC) holds address of the
instruction to be fetched next
¾ Processor increments the PC after each fetch
EEL 602 10
Instruction Register
¾ Fetched instruction is loaded in IR
¾ Instruction categories
Processor-memory
Transfer data between processor and memory
Processor-I/O
Data transferred to or from a peripheral device
Data processing
Arithmetic or logic operation on data
Control
Alter sequence of execution
EEL 602 11
Interrupts
¾ Common Class of Interrupts
Program
Result of instruction execution, e.g. arithmetic overflow,
division by zero or illegal memory reference
Timer
Processors timer, functions on regular basis
I/O
Generated by I/O controller, signal or error
Hardware Failure
Power failure or memory parity error
EEL 602 12
Interrupt and Trap
Mechanisms to interrupt the normal processing of processor
¾ Trap
Trap is the notification of an internal event, highest priority
Traps are immediate and occur synchronously with the current
activity of processor (result of program execution)
¾ Interrupt
Interrupt is the notification of an external event
Occur asynchronously with the current activity of processor
EEL 602 13
Program Flow of Control
(a) No Interrupts (b) Interrupts; short I/O wait (c) Interrupts; long I/O wait
EEL 602 14
Interrupts
EEL 602 16
Multiple Interrupts
¾ Disadvantages of sequential interrupt processing
Does not account for relative priority or time critical needs
I/O device may fill and overflow
EEL 602 18
Memory Hierarchy
¾ Design Constraints
How much?
Open ended, large capacity
How fast?
Mach the processor, do not wish to wait
How expensive?
Reasonable relationship to other components
EEL 602 19
Memory Hierarchy
EEL 602 21
Caching
Cache size
Replacement policy
EEL 602 23
Hardware Protection
¾ Sharing of Resources → Utilization and Problems
¾ Hardware Protection
Dual-Mode Operation
I/O Protection
Memory Protection
CPU Protection
EEL 602 24
Dual-Mode Operation
¾ Provide hardware support to differentiate
between at least two modes of operations
EEL 602 25
Dual-Mode Operation
¾ Mode bit added to computer hardware to indicate current mode:
Monitor (0) or User (1)
¾ When an interrupt or fault occurs hardware switches to monitor
mode
Interrupt/fault
Monitor User
set user mode
EEL 602 26
I/O Protection
¾ All I/O instructions → privileged instructions
EEL 602 27
I/O Protection
EEL 602 29
Memory Protection
EEL 602 31
Hardware Protection
¾ The load instructions for the base and limit
registers are privileged instructions
EEL 602 32
CPU Protection
¾ Prevent user program from struck in infinite loop
or never returning control to OS
¾ Timer – interrupts computer after specified
period to ensure OS system maintains control
Timer is decremented every clock tick
When timer reaches the value 0, an interrupt occurs
EEL 602 33