Architectural
(hardware) Support for
Operating Systems
• Review of introduction
• Hardware overview
• A peek at Unix
• Hardware (architecture) support
• Summary
Review
• What are the two main responsibilities of OS?
• Manage hardware resources
• Provide a clean set of interface to programs
• Managing resources:
• Allocation
• Protection
• Reclamation
• Virtualization
• Questions?
Why Start With Hardware?
• Operating system functionality fundamentally depends
upon hardware
• Key goal of an OS is to manage hardware
• If done well, applications can be oblivious to HW details
• Hardware support can greatly simplify – or complicate –
OS tasks
• Early PC operating systems (DOS, MacOS) lacked virtual
memory in part because the hardware did not support it
So what is inside a computer
Why hardware has to support
User/Kernel mode?
17 CS317 Operating System
• Give the CPU to the user application
• Why: Performance and efficiency
• OS will not be executing
• Without hardware’s help, OS loses control of the machine!
• Analogy: give the car key to someone, how do you know if he will
return the car?
• This is the one of the most fundamental reasons why OS will
need hardware support --- not only for user/kernel mode
Hardware Features for OS
• Features that directly support the OS include
• Protection (kernel/user mode)
• Protected instructions
• Memory protection
• System calls
• Interrupts and exceptions
• Timer (clock)
• I/O control and operation
• Synchronization
Types of Hardware Support
• Manipulating privileged machine state
• Protected instructions
• Manipulate device registers, TLB entries, etc.
• Generating and handling “events”
• Interrupts, exceptions, system calls, etc.
• Respond to external events
• CPU requires software intervention to handle fault or trap
• Mechanisms to handle concurrency
• Interrupts, atomic instructions
Protected Instructions
• A subset of instructions of every CPU is restricted to use
only by the OS
• Known as protected (privileged) instructions
• Only the operating system can
• Directly access I/O devices (disks, printers, etc.)
• Security, fairness (why?)
• Manipulate memory management state
• Page table pointers, page protection, TLB management, etc.
• Manipulate protected control registers
• Kernel mode, interrupt level
• Halt instruction (why?)
OS Protection
• Hardware must support (at least) two modes of operation:
kernel mode and user mode
• Mode is indicated by a status bit in a protected control register
• User programs execute in user mode
• OS executes in kernel mode (OS == “kernel”)
• Protected instructions only execute in kernel mode
• CPU checks mode bit when protected instruction executes
• Setting mode bit must be a protected instruction
• Attempts to execute in user mode are detected and prevented
• x86: General Protection Fault
Memory Protection
• OS must be able to protect programs from each other
• OS must protect itself from user programs
• We need hardware support
• Again: once OS gives the CPU to the user programs, OS loses
control
• Memory management hardware provides memory
protection mechanisms
• Base and limit registers
• Page table pointers, page protection, TLB
• Virtual memory
• Segmentation
• Manipulating memory management hardware uses
protected (privileged) operations
Hardware Features for OS
• Features that directly support the OS include
• Protection (kernel/user mode)
• Protected instructions
• Memory protection
• System calls
• Interrupts and exceptions
• Timer (clock)
• I/O control and operation
• Synchronization
Events
• After the OS has booted, all entry to the kernel happens as the result
of an event
• event immediately stops current execution
• changes mode to kernel mode, event handler is called
• An event is an “unnatural” change in control flow
• Events immediately stop current execution
• Changes mode, context (machine state), or both
• The kernel defines a handler for each event type
• Event handlers always execute in kernel mode
• The specific types of events are defined by the machine
• In effect, the operating system is one big event handler
OS Control Flow
• When the processor receives an event of a given type, it
• transfers control to handler within the OS
• handler saves program state (PC, registers, etc.)
• handler functionality is invoked
• handler restores program state, returns to program