PC startup process

xiaoxiao2021-03-06  21

I. Introduction

Recently, I often see the startup process of asking a computer (PC computer) online, this process is really mysterious but is not complicated. Although I am not a system programmer, I have been careful about the bottom layer. This article is a summary of this problem, I hope to help those friends who wish to understand this mysterious process.

Second, the hardware initialization of the PC machine

When we press the PC's switch or when the CPU's RESET pin has a signal, the CPU enters the hardware initialization phase. At this stage, the CPU is a large number of work, detecting the state of each component inside, initializing the internal registers of each register, initializing the calculation of the calculation processor, and the like. After the initialization process, the registers within the system have stable and fixed values. Table 1 Lists the state of the Pentium 4 CPU initialization, about the status of other CPUs, friends can refer to Intel's related manuals, and the data here is also from Intel's information. (IA-32 Intel Architecture Software Developer's Manual Volume 3: System Programming Guide This table only lists the initial values ​​of some registers that everyone care about, and other content can be found in Intel's manual.

Table I

Register initial value EFLAGS00000002HEIP0000FFF0HCR060000010HCSSelector = F000HBase = FFFF0000HLimit = FFFFHAR = Present, R / WAccessedDS ES SS FS GSSelector = 0000HBase = 00000000HLimit = FFFFHAR = Present, R / WAccessed

According to the initial value of CR0, we can see that the CPU is initialized to run in a state in which the real mode does not pagin.

Here, you must explain the initial value of CS, in order to illustrate the special of this value, I first deviate from the theme, I first explain some of the special places of the 386 series segment registers. In a 386 or higher 32-bit processor, CS, DS, ES, SS, FS, GS registers are still 16, but they put things in them now have a new name "Select Sub" except us. In addition to this selection, these registers have a shadow section we can't see, this part mainly includes Base, Limit, Access, and more. The role of these things is mainly functions such as memory addressing and protection. The current address is actually like this:

Line address = selector.base offset

This addressing method is the only addressing method of the 386 series, whether in real mode or protection mode. Some information believe that in real mode, the address is generated:

Segment register value X16 offset

In fact, in the address generation part of the CPU, the way the address is formed is the Base offset of the invisible portion of the segment selector. Just in real mode When we load segment selectors, the system automatically sets the invisible parts of the segment selection. Let us give an example. For example, we must put the DS in 1000h now.

MOV AX, 1000H

MOV DS, AX

When we execute this instruction in real mode, the CPU has quietly set up the immune part of the DS, the result is as follows:

DS.BASE = 10000H

DS.LIMIT = ffffh

This takes out the base when the CPU is directly to the invisible portion of the segment register when we execute instructions.

Ok, let's go back to theme. When the CPU is initialized, cs.base = fff000h EIP = 0000FFF0H, so the system will jump to the address fffffff0h to perform the initial first instruction, since the system does not enable the paging mechanism, the current address is the physical address. . In the design of the PC, this address is a ROM address, which is stored in BIOS. Third, BIOS initialization

BIOS take over the computer, it works power self-test (POST), set interrupt vectors, fill in the BIOS data area, hardware device initialization, etc. Although the BIOS code is executed in the system's highest 64K, it is necessary to fill in the minimum of physical memory.

1M

In the space, this is a completely available, and should be the current DS.BASE = 00000000h, if DS (or ES, etc.) is used as a segment base address, BIOS can be placed in a low variable to the system.

1M

Space.

In addition to these, there is a very important thing that puts yourself from the system's high address area to

1M

In the 64K of the space, why should you move yourself?

1

M

Below? Since the system is in the actual mode, it also provides services to the real mode, and some hardware interrupt services are provided. These are the same as the old 8086, if we don't move the BIOS, the hardware interruption in the mode does not have a service code. But how do BIOS moved from high-end? It sounds very simple, but don't forget, now we are still in real address mode, the DS or other segment registers can only be positioned low.

1M

Space, in order to achieve this code, there is a different approach, but some of the BIOS code I have seen is to enter the CPU into the protection mode. At this time, DS and ES can access all address space in the system, so Successfully move the code from the system up to 64K to the system

1M

In this time, this time, BIOS switches the system to the real address mode and performs jump between the time, and jumps to the low system.

1M

space. After the BIOS initialization is completed, it is necessary to load the operating system.

Don't worry, do my friends think? Now the BIOS has moved to RAM, but we have no way to modify F0000h to FFFFH memory. Is it true that the memory here is really a ROM, if it is a ROM, we can't The high-end 64K thing moved. Oh, first tell you, here is indeed RAM just not let us write, why can we write when BIOS is initialized, and we can't write? The memory here is set by the system set to Shadow RAM, we can program the characteristics of certain memory regions by programming the chipset on the motherboard, and set up to write 22 h and 23h with the OUT instruction, due to each chipset Different, I have not been done in this setting (after all, my machine, don't write J), ​​this is clear, the original BIOS will set the memory properties of the destination area to read only after being moved.

Fourth, the boot of the operating system

Regarding the guidance of the operating system, I think there are a lot of materials, nor complicated, here you don't need to say more.

Five, conclusion

The above is my summary, I hope to communicate with everyone.

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

New Post(0)