Document directory
- BiOS completes the following functions:
- Work of bootloader
- Setup ()
- Start_kernel ()
Original article address:
Http://www.manio.org/cn/startup-of-linux-view-of-society.html
In fact, this should be the first part of this series of articles, because this article is about the history. Mr. Process is a modern man, but as long as it is a person, it should always have an ancestor. People always want to know where they come from before they can estimate where they will go. So we should also look at the origins of humans in the Linux World.
Figure 1: from power-on to BIOS
The real person who presses the power switch is the God in the Linux World, which creates everything in the Linux World. When he presses the power switch on the chassis, the motherboard starts to supply power, and the reset pin on the CPU is increased, which will lead to a series of CPU actions, which are determined by the chip design. Some registers in the CPU are set to fixed values because these registers may be used during startup, such as CS (code segment register) and EIP (pointer instruction register ). After this step is completed, the CPU can open the program in ROM at 0xfffffff0. This program is BIOS (Basic Input Output System ).
BiOS completes the following functions:
1. Post (power-on Self Test): The name of Gu mingsi is to check what devices are available and whether these devices are normal. If the CPU supports advanced configuration and Power Interface (ACPI. ACPI is used to manage the power supply and power-saving.
2. initialize the device: ensure that there is no IRQ or IO conflict.
3. Search for OS/bootloader. This step is further detailed.
In the BIOS settings menu, we can set where to start, such as floppy disk, hard disk, and optical drive... BiOS will search for OS in the order we set.
4. Copy the bootloader to Ram (Address: 0x00007c00) and run the command at that address.
What is bootloader?
Now, all we need to do is: bootloader will find the OS and copy the OS kernel to ram.
Figure 2: loading Boot Loader
As shown in, the first sector on the hard disk has a partition table (which records the operating systems) and a small version of bootloader. When this BIOS is set to start from here, this small version of bootloader is copied to ram 0x00007c00. Then it moves itself to 0x00096a00. After that, it copies another bootloader from the hard disk to 0x00096c00, and then starts execution from there. The reason for dividing two sections is that the current bootloader is too large and there is not much to store on the MBR.
Bootloader copies the OS Kernel image to ram.
Work of bootloader
1. Call BIOS to display the "loading image" message.
2. Call the BIOS to copy the first 512 bytes of the kernel image to 0x00090000. The setup () function is located at 0x00090200.
3. Call BIOS to load the remaining kernel image to 0x00010000 (Small kernel zimage) or 0x00100000 (large kernel bzimage)
4. Jump to setup () to start execution.
Setup ()
Setup () is used to initialize the device. Although the BIOS has done some initialization work, Linux does not depend on it. Setup () initializes the keyboard, FPU, and other devices, and sets some registers. At the end of setup (), startup_32 () is called ().
Startup_32 ()
Linux has two startup_32 ().
Which of the following statements is executed first?ARCH/i386/boot/compressed/head. s. The main function of startup_32 () is to decompress the kernel.
The second startup_32 () is inARCH/i386/kernel/head. s. The startup_32 () job is to set the survival environment for the first Linux Process (that is, the ancestor of mr. process. Finally, jump to start_kernel.
The description in understanding the Linux kernel 3rd is as follows:
- Initializes the segmentation registers with their final values.
- Fills the BSS segment of the kernel (see the section "program segments and process memory regions" in chapter 20) with zeros.
- Initializes the provisional kernel page tables contained inSwapper_pg_dirAndPg0To identically map the linear addresses to the same physical addresses, as explained in the section "kernel page tables" in Chapter 2.
- Stores the address of the page global directory in303.Register, and enables paging by settingPGBit inCr0Register.
- Sets up the kernel mode stack for process 0 (see the section "kernel Threads" in Chapter 3 ).
- Once again, the function clears all bits inEflagsRegister.
- InvokesSetup_idt ()To fill the IDT with null interrupt handlers (see the section "Preliminary initialization of the IDT" in Chapter 4 ).
- Puts the system parameters obtained from the bios and the parameters passed to the operating system into the first page frame (see the section "physical memory layout" in chapter 2 ).
- Identifies the model of the processor.
10. loadsGDTRAndIdtrRegisters with the addresses of the gdt and IDT tables.
11. jumps toStart_kernel ()Function.
Start_kernel ()
Complete the initialization of all components.
Understanding the Linux KernelThis section of work is described as follows:
The schedinit is initialized by invoking the sched_init () function (see chapter 7 ).
 the memory zones are initialized by invoking the build_all_zonelists () function (see the section "Memory zones" in Chapter 8 ).
 the buddy system allocators are initialized by invoking the page_alloc_init () and mem_init () functions (see the section "the buddy system algorithm" in Chapter 8 ).
 the final initialization of the IDT is already med by invoking trap_init () (see the section "Exception Handling" in Chapter 4) and init_irq () (See the section "IRQ data structures" in Chapter 4 ).
The tasklet_softirq and hi_softirq are initialized by invoking the softirq_init () function (see the section "softirqs" in Chapter 4 ).
The system date and time are initialized by the time_init () function (see the section "the Linux timekeeping architecture" in chapter 6 ).
The Slab allocator is initialized by the kmem_cache_init () function (see the section "general and specific caches" in Chapter 8 ).
 the speed of the CPU clock is determined by invoking the calibrate_delay () function (see the section "delay functions" in chapter 6 ).
The kernel thread for process 1 is created by invoking the kernel_thread () function. in turn, this kernel thread creates the other kernel threads and executes the/sbin/INIT program, as described in the section "kernel Threads" in Chapter 3.
The execution process of the above functions is as follows:
Figure 3: Procedure of starting a function
The second startup_32 () and start_kernel () reveal the true meaning of Linux life. Here we can see how mr. process (a common process) has everything. After understanding this, we can also figure out Linux. Really clear.
BTW, how can I make a good image ~ Beauty is born there, and you cannot block it. How can we make it nice and professional!