0.11 Road (four): from the actual mode to the protection mode

Source: Internet
Author: User

(i) Close the interrupt and move the system to the memory address start position 0x00000

Set the interrupt Allow flag (IF) in the CPU's flag register (EFlags) to 0. The system will no longer respond to interrupts until the interrupt service system in the main function that adapts to the protected mode is rebuilt before it is opened, and the service that responds to the outage will no longer be the interrupt service program provided by the BIOS, but the system itself.
is to complete the handover of Interrupt descriptor Table (IDT) in real mode and in protected mode. This process is created with off-interrupt (CLI) and open interrupt (STI), which means that the system cannot respond to interrupts during creation, otherwise there is no corresponding interrupt program, and the crash.

The Setup program copies the kernel program located in 0x10000 to the 0x00000 where the memory address starts. Originally 0x00000 This location is stored by the BIOS of the interrupt vector table and the BIOS data area, so they will be overwritten, so before the new protection mode for the interrupt service system is established, the operating system no longer has the ability to respond and handle interrupts. That's the point of shutting down the interrupt.

To create a 32-bit operating system, a new concept is introduced: Interrupt description Schedule (IDT) and Global descriptor Table (GDT).

(ii) Open A20 for 32-bit addressing

Originally 5 F, opened A20, it became 8 F, that is, 4G.
For 0.11来, the maximum can only support 16MB of physical memory, but its linear address space is already 4GB.
Real mode CPU addressing range of 0~0XFFFFF, a total of 1MB addressing space, requires a total of 20 address lines 0~19 number. After entering protection mode, 32-bit addressing mode is used, that is, addressing with 32 address lines, and 21st (A20) to 32nd Address line selection control will mean the switching of the addressing mode.

(iii) Re-programming in 8259A protection mode

In order to establish the interrupt mechanism, it is necessary to know 8259A, which can be programmed by the interrupt controller. A single 8259A can manage 8-level vector priority interrupts.

We need to reprogram the 8259A because the CPU in protected mode, int 0x00~int 0x1F is reserved by Intel as an internal (non-shielded) interrupt and an abnormal interrupt. If the 8259A is not reprogrammed, an int 0x00 ~ int 0x1F interrupt will be overwritten. Therefore, the original irq0x00~irq0x0f corresponding interrupt number needs to be re-distributed through 8259A programming, that is, in protected mode, the irq0x00~irq0x0f interrupt number is int 0x20~ int 0x2F.

The Setup program uses the following code to set the operating mode of the CPU to protected mode, the CR0 register No. 0 bit (PE) 1, that is, the set processor mode of operation is protected.

mov    ax, #0x0001        protectedbitlmsw   ax                 is it!

Lmsw:load Machine Status Word
Processor status Word. However, only the lower 4 bits of the operand are stored in CR0, only Pe,mp,em and TS are rewritten, CR0 other bits are unaffected.

After the CPU is switched to protected mode, an important feature is to decide which program to follow in the GDT. With the GDT's boot, the next step is to jump to the beginning of the head program. Head.s begins execution.

In fact, what we call the System program is the head program linked to the main program, head in front, main next to head. The head program makes a great deal of sense for the layout of kernel programs in memory: creating paging mechanisms that create page catalog tables, page tables, buffers, GDT, and IDT in 0x000000 locations.

Again, in real mode, CS itself is the code snippet base, in protected mode, CS itself is not the code snippet base, but the code segment selector. In other words, the actual mode is changed to protect mode, the use of the base of the segment and the real mode is very different, to use the GDT to produce the segment base.

Next, place the page Catalog table and page table in the memory start location. They are placed in a memory location starting from 0x00000.

You can then execute the main function that was compiled with the 32-bit compiler. In summary, Head.s is the 32-bit protection mode that is used to transition from 16-bit real mode to main function execution.

0.11 Road (four): from the actual mode to the protection mode

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.