Windows protection mode

zhaozj2021-02-11  196

Windows protection mode

Sun Ximing

In general, 80x86 (80386, and each of the generations of CPUs) can operate in three modes: real mode, protection mode, V86 mode. The real mode is an old MS-DOS operating environment. Win95 is only used in two modes: protection mode and V86 mode.

Why enter protection mode

The protection model has many superiority. The most direct benefit is: Your program can take advantage of more memory!

Don't think that this is a big deal, I believe that every person who has written in MS-DOS has a distress: How to open a big enough array in the program? If you don't move, you will stack over, and you can't do it. Don't blame Turbo C, MS Fortran, Turbo Pascal, and they are also weak. These troubles are derived from "Your program is running in real mode." 16-bit programs running in real mode can only access 1M memory. You may ask: Is there 64M memory on my machine? Yes, if you are running the program under MS-DOS (or said in real mode), then you only use 1M memory, the rest of the memory is "laid", in this case, yours 386/486/586 / PII is only equivalent to a fast 8086 running.

But the protection model gives us a surprise. In theory, in protection mode, the CPU can address 4096M (ie 4GB) memory. That is to say, just compile your program into a 32-bit executable program (of course, you can make full use of memory in the program, the direct result of doing this is: You can no longer have to I can't eat it for the stack overflow or can't open the number of 5000 × 5000.

It is the implementation of 4GB memory access, so that the operating system has a more intelligent material basis, and the implementation of multitasking can be considered on the schedule.

More deeper

From the hardware structure, 386 controls the operation of the CPU by three registers CR0, CR1, CR2. For example, the 0th bit of CR0 is used to determine whether the current CPU is working in the protection mode or in real mode. People who have learned 8088/8086 assembly language must be familiar with the 16-bit registers of AX, BX, CX, DX, Si, Di, SP, BP. In 80386, these registers are extended to 32-bit, namely EAX, EBX, ECX. , EDX, ESI, EDI, ESP, EBP, if the CPU is running in real mode, then you can only use the top 16 bits of these 32-bit registers, while the 16 positions areted.

The concept of the paragraph is the key to understanding the protection model. In the real mode, the 16-bit segment address is stored in the segment register. At this time, the segment address is involved in addressing: 4 digits left the segment address, plus the offset address, is the 20-bit physical address. In the protection mode, the 16-bit segment selector is stored in the segment register. This value is not directly involved in addressing, but is just an index of the Segment Descriptor Table. Segment Descriptor (Segment Descriptor) is stored in Segment Descriptor Table. The segment descriptor is related to the description of the segment, such as: the position of the segment in memory, the size of the segment, the type of segment (is a data segment or code segment), and the like.

When the CPU runs in the protection mode, the memory often has at least three segment description tables: Global Descriptor Table, General Descriptor, LDT, Interrupt Descriptor Table (Interrupt Descriptor Table) , Referred to as IDT). Speaking here, I want to remind the reader to pay attention to: Remember the meaning of the three words of GDT, LDT, IDT, which will be used later. Segment description table is not more than 64K (why? If you can't answer, then look at the previous explanation), each paragraph descriptor (one of the paragraph descriptive tables) is 8Byte long, so, each A segment description table can only contain 8192 segment descriptors.

In the future "walking into the VXD World", we will further explain the segment description table, segment descriptor, and paging machine.

转载请注明原文地址:https://www.9cbs.com/read-3900.html

New Post(0)