Write operating system (vi) Practice mode and Protection mode contrast learning

Source: Internet
Author: User

By learning from the teachers and seniors, here is my summary of the real mode and protection model.

1. Real mode: Processor modes.

The code written earlier is bit 16 real mode

Characteristics:

(1) Memory address = (Segment address * + (decimal)) + Offset Physical Address = Segment Address *16+ shift address

(2) Limit 1MB of memory because address bus is 20 bits, so the addressing range is 1MB

(3) The maximum length of the limit segment is 64k because the offset address is given by the 16-bit register, so the addressing range is 64K

(4) No virtual storage/code protection due to the overlapped Segment in real mode, which is overlapping between segments, it is easy to cross the line

(5) The real mode is more than a single task, and due to the limitation of addressing range, less function.

2. Protection mode (Protected modes): Processor modes

Writing a powerful kernel will inevitably use a language like C, and C is a 32-bit environment

Characteristics:

(1) address by DT by "segment address" to find the corresponding descriptor, get the real address + offset

(2) 32-bit address line with 4GB addressing

(3) Implement virtual storage and code protection

3. The condition of the program running under real mode is satisfied:

(1) Instructions required to run the memory address of the CPU instruction is notified with the CS register with the IP register.

(2) The data required for operation is specified by different use registers such as DS,ES,FS,GS,SS to specify the location of data in memory for different purposes.

(3) The runtime to invoke the system service subroutine, with the interrupt mechanism to complete

4. The biggest difference between real mode and protected mode: Address Translation mode

(1) In real mode, the formula is: Segment Register =es, segment base =es*0x10, offset address =di, Physical address = segment Base + offset address (left shift four bit plus offset).

(2) In protected Mode, select Sub =es, segment base = Global Descriptor Select Child specified descriptor, offset address =di, Physical address = segment Base + offset address.

(3) Summary, the mapping method is different. Real mode = shift left four bit, protected mode = Check Global or local description table.

5. Real mode changes to protected mode

(1) Data segment: is the real mode code snippet, data segment, stack segment, Terminal Services program collectively

(2) Descriptor: Used to describe a data segment, 8 bytes, and a 5th byte description description Descriptor type. Descriptors are made up together as descriptor tables, which are the address translation table.

(3) Select sub: 2 bytes, 2nd bit table RPL, the third note is a GDT or a LDT, the highest 13-bit descriptor in the Description table address, 13-bit addressing range is exactly: 8k.

6. Location of the Gdt/ldt. The GDR represents the segment address and segment limit of the GDT in memory: Segment address 32 bits, segment limit 16 bits = 48 bits (that is, the largest field is 64k, each descriptor is 8k, so there is a total of 64k/8=8k). Similarly, LDR represents the location of the LDT in memory, but since LDR itself is also a data segment, it must have a descriptor, and the descriptor is placed in the GDT, so Ldr is just a "selector" more than Ds,es, which is used to obtain the address of the LDT in the GDT.

7. Where the service is interrupted. The Interrupt/Trap descriptor forms the Interrupt descriptor (IDT), which is stored by the full address register IDTR (48b=32+16). Note, although there are also 8k items, or 8k interrupts, the x86 provides 256 interrupts.

8. Reasons for multi-tasking support in protected mode: CR3 registers (total 32 bits, 12th 0) are used to store the memory address of the first-level page table. CR3 will be used as part of the task environment when the task is switched to the TSS data segment. The TSS data segment has a TSS descriptor, which is stored in the GDT. In addition, the TR register is used to hold the selector of the descriptor.

9. The role of paging mechanism: To solve the problem of accessing memory conflicts between different tasks, that is, to implement mapping from logical address to physical address. The way is "page table" (Level two page table):

(1) TSS: Achieving multitasking plays an important role by enabling task switching, which will save the current environment of the task being switched out.

(2) Control register: used to control and determine the processor operating mode and the current mode

CR0: The system control flag for the current mode and status of the processor.

CR1: Reserved.

CR2: Contains the address that caused the error, the page fault linear address register.

CR3: Page directory base address. Store a Level page table.

10. Summary: The protection model is more than the real mode of what.

(1) Register GDR,LDR,IDR,TR,CR3

(2) Data segment, descriptor Table (Gdt,ldt), task data segment (TS), page list

(3)          mechanism, permission detection (using the attribute bits of the selector sub/Descriptor/page table entry), linear address to physical address mapping

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.