This part should be the most important and hard to understand!
First, you must understand thatSource codeThe kernel is started from head. S (ARC/i386/boot/head. s) Until main. C (init/main. c) start_kernel () in, this is a rough journey!
Don't be scared first. Come on! My first task is to understand this journey!
We still need to understand that, in this section, if there are many things that we cannot understand, we should think of whether the operating system base or hardware is solidified by hardware design! In some cases, we should think like this. If not, we should analyze the software source code. However, there is still an introductory initialization process, becauseProgramThis part cannot be left or right.
I. kernel initialization and startup process.
At the beginning of the Computer startup, it was not related to Linux, that is, the boot process. However, it is also necessary to talk about this part. Otherwise, I always feel that the entire process is not transparent.
When the PC machine starts power-on, the 80x86 processor (CPU) in real mode self-check, start to execute the physical address 0xffff0 is the starting address of the ROM-BIOSCode. The bios of the PC performs system self-check and initializes the interrupt vector table to the physical address 0x0. Load the first sector of the boot device to address 0x7c00 and execute the command here. It has nothing to do with Linux. This is the case with x86 hardware.
Because the 32-bit intel processor is powered on, after reset or init, the initial value of the control register Cr0 is 0x60000010 h, and the corresponding processor is in real mode, the paging mechanism is not enabled (PE = 0, Pg = 0). Therefore, the length of the address and operand used by the processor is 16 bits. The initial value of the code segment register is 0xf000h, the initial value of the EIP in the instruction register is 0xfff0h (these two values are also determined by the Intel processor architecture, so the 0xffff0h principle is here .) The boot process is as follows:
1. The Machine powers up, the processor completes self-check and initialization, sets the initial values of each register, and then starts executing the command.
2. The address of the first instruction executed by the processor is CS * 16 + IP, that is, 0xffff0h, and this address is only 16 bytes away from the maximum programmable address 0xfffffh of the processor in real mode, is the entry address of the BIOS residing in the Rom. The processor starts to execute commands from this place. Therefore, the first thing that gets control of the machine is the BIOS. (Understand why the BIOS is first loaded. Maybe you will ask me how the BIOS entry address knows the memory, that is, how the BIOS entry address is loaded into the memory, let's take a look at the knowledge of memory address space in the microcomputer principle .)
3. BiOS completes the detection of the entire machine system, and records the basic information about the system configuration in the BIOS data area of the memory, and then, from the boot disk (floppy disk, hard disk, optical drive, etc) read a boot sector (such as the 0-sector 0 of a floppy disk) to 0x7c00h of the memory, and finally go to 0x7c00h to give control of the machine to the operating system. (Question: Why is the boot sector read from the address 0x7c00h in memory? This is an agreement !) (When I look at the code, I may not be able to answer some questions at the moment. However, this does not affect further reading. As I read more deeply, I will certainly gain some benefits! I encourage myself to give two sentences .)
4. Now, the operating system is playing.
Linux starts to run. It loads itself to the absolute address 0x90000 and loads the next 2 K bytes to the address 0x90200. (Note: There are two phases in this area: one is boot (please refer to this: bootsect. s), the initialization process (setup. s) setup. s programs are stored at 0x90200. The starting part of the program (from 0x90200 to 0x90266) is some system parameters, which together with the pilot parameters located between 0x90000 and 0x90200 constitute the initial parameter area of the entire operating system. Most of these parameters are written by the image creation program when the system boot image is created, and some are recorded after the setup program tests the system. This part of the data is the first batch of parameters accepted by the operating system, which will affect the operation process of the entire system.
What should we do next? We recommend that you take a look at the setup. S source code.