Protected mode is an operational mode of x86-compatible CPUs, which provides advanced features like virtual memory, paging, and safe multi-tasking. Introduced with the Intel 80286 processor, it overcomes the limitations of real mode, such as the 1 MB memory limit and lack of protection mechanisms.
Key Features of Protected Mode
- Extended Memory Access: Access to 4 GB of memory using 32-bit addressing.
- Memory Protection: Isolates different processes to prevent them from interfering with each other.
- Hardware-Based Virtual Memory: Supports paging, allowing the use of disk space as additional RAM.
- Multitasking Support: Hardware support for task switching.
Segmentation in Protected Mode
Segmentation is a technique of memory management where memory is divided into different segments or chunks
- Segmentation works differently in protected mode that of real mode.
Segmentation in protected mode is an advanced memory management technique that expands upon the concepts used in real mode, offering enhanced capabilities and protection features. While in real mode, segmentation is primarily used to extend the addressable memory space beyond 64 KB by dividing memory into 64 KB segments, protected mode introduces protection to these segments.
- Every Segments has a set of permission and properties that we need to set in a data structure that is called a Global Descriptor Table (GDT).
Switching to Protected Mode
Transitioning from real mode to protected mode involves several steps:
Initialize the Global Descriptor Table (GDT):
- The GDT defines the memory segments used by the CPU.
- Each entry in the GDT describes the base address, limit, and access rights of a segment.
Load the GDT:
- Use the
lgdt
instruction to load the GDT descriptor into the GDTR register.
Enable the Protection Enable (PE) Bit:
- Set the PE bit in the Control Register CR0 to enable protected mode.
Jump to Protected Mode Code:
- Perform a far jump to flush the prefetch queue and start executing protected mode instructions.