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
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
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