80386 Protection
a day ago
- #VirtualMemory
- #80386
- #ProtectedMode
- The 80386 introduced significant improvements over the 80286's protected mode, including paging, a flat 32-bit address space, per-page User/Supervisor control, and Virtual 8086 mode.
- The x86 protection model is complex, featuring four privilege rings, segmentation, paging, call gates, task switches, and virtual 8086 mode.
- The 80386 uses a dedicated Protection Test Unit (PLA) to handle privilege checks efficiently, replacing what would otherwise require multiple conditional branches in microcode.
- Segmentation and paging work together to provide memory protection, with segmentation always active in protected mode and paging optional.
- The 386 supports four privilege rings, though most operating systems use only two: ring 0 for the kernel and ring 3 for user programs.
- Virtual 8086 mode allows real-mode DOS programs to run under protected mode, with the OS using paging to virtualize the 8086's 1 MB address space.
- The 386's TLB (Translation Lookaside Buffer) has 32 entries, covering 128 KB of memory, with a claimed 98% hit rate for typical workloads.
- Hardware page walks are handled by a dedicated state machine, running in parallel with microcode and requiring no microcode involvement.
- Virtual 8086 mode uses trap-and-emulate for IOPL-sensitive instructions, allowing the OS to virtualize hardware access and interrupt handling.
- The 386's protection architecture balances hardware and microcode to optimize performance, with dedicated hardware for fast paths and microcode for complex operations.