Windows protection mode

Source: Internet
Author: User
Windows protection mode
  
Sun Ximing

Generally, 80x86 (80386 and later generations of CPUs) can run in three modes: real mode, protection mode, and v86 mode. Real mode is the operating environment of the ancient MS-DOS. Win95 only uses two modes: protection mode and v86 mode.

Why do you want to enter the protection mode?

The protection mode has many advantages. The most direct benefit is that your program can use more memory!

Don't think that's a big deal, I believe that everyone who once writes a program under the MS-DOS has a distress: how to open a large enough array in the program? Stack Overflow occurs when the system does not move. Don't blame Turbo C, Ms Fortran, And Turbo Pascal. They are also insufficient. These troubles all come from "your program runs in real mode ". A 16-bit program running in real mode can only access 1 MB of memory at most. You may ask: Isn't there 64 M memory on my machine? Yes, if you are running the program in the MS-DOS (or the CPU is running in the real mode), then you only use 1 MB of memory, the rest of the memory is "laid off, in this case, your 386/486/586/P ⅱ is equivalent to only one 8086 that runs fast.

However, the protection mode surprised us. Theoretically, In the protection mode, the CPU can address 4096 M (4 GB) memory. That is to say, you only need to compile your program into a 32-bit executable program (with the 32-bit compiler of course), and you can make full use of the memory in the program, the direct result is that you don't have to worry about stack overflow or the 5000 × 5000 array.

It is the implementation of 4 GB memory access that gives the operating system a more intelligent material basis. The realization of multi-task can be mentioned on the agenda.

Further Exploration

In terms of hardware structure, 386 is controlled by three registers Cr0, CR1, and CR2. For example, The 0th bits of Cr0 are used to determine whether the current CPU is working in the protection mode or the real mode. Those who have learned 8088/8086 assembly languages must be familiar with 16-bit registers such as ax, BX, CX, dx, Si, Di, SP, and BP. In 80386, these registers are extended to 32 bits, namely, eax, EBX, ECx, EDX, ESI, EDI, ESP, and EBP. If the CPU is running in real mode, you can only use the first 16 bits of these 32-bit registers, and the last 16 bits are wasted.

The concept of section is the key to understanding the protection mode. In real mode, a 16-bit segment address is stored in the segment register. In this case, the segment address is involved in addressing: shift the segment address four places left, and add the offset address, it is a 20-bit physical address. In protection mode, the segment register stores a 16-bit segment selector, which is not directly involved in addressing, it is just an index pointing to the segment description table (segment descriptor table. The segment description table contains the segment descriptor ). Segment descriptors contain descriptions of segments, such as the location of segments in the memory, the size of segments, and the type of segments (data segments or segments.

When the CPU runs in protected mode, there are usually at least three segments in the memory: Global Descriptor Table (gdt) and Local Descriptor, (LDT), interrupt description table (Interrupt Descriptor Table, IDT ). Here, I would like to remind readers that the meanings of gdt, LDT, and IDT are often used later.

The segment description table cannot exceed 64 K (why? If the answer fails, let's look at the previous explanation. Each segment descriptor (that is, an item in the segment description table) is 8 bytes long. So, each segment description table can contain a maximum of 8192 segment descriptors.

In the future "going into the VxD world", we will further explain the section description table, segment descriptor, and page sharding machine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.