System Startup

To begin the boot, a special hardware circuit raises the logical value of the RESET pin of the CPU. After RESET is asserted, some registers of the processor (including cs and eip) are set to fixed values, and the code found at physical address 0xfffffff0 is executed. This address is mapped by Read-Only Memory (ROM). The set of programs stored in ROM is called the Basic Input/Output System (BIOS) . The BIOS performs the following four operations:

  1. Power-On Self-Test (POST).
  2. Initializes the hardware devices.  At the end of this phase, a table of installed PCI devices is displayed.
  3. Searches for an operating system to boot.
  4. As soon as a valid device is found, it copies the contents of its first sector into RAM, starting from physical address 0x00007c00, and then jumps into that address and executes the code just loaded

The first sector of the hard disk, named the Master Boot Record (MBR), includes the partition table and a small program, which loads the first sector of the partition containing the operating system to be started. Linux replaces the rudimentary program included in the MBR with a sophisticated program—the “boot loader” (LILO).

Actually, the LILO boot loader is too large to fit into a single sector, thus it is broken into two parts. The MBR or the partition boot sector includes a small boot loader, which is loaded into RAM starting from address 0x00007c00 by the BIOS. This small program moves itself to the address 0x00096a00, sets up the Real Mode stack (ranging from 0x00098000 to 0x000969ff), loads the second part of the LILO boot loader into RAM starting from address 0x00096c00, and jumps into it

  1. Invokes a BIOS procedure to load an initial portion of the kernel image from disk: the first 512 bytes of the kernel image are put in RAM at address 0x00090000, while the code of the setup( ) function is put in RAM starting from address 0x00090200.
  2. Invokes a BIOS procedure to load the rest of the kernel image from disk and puts the image in RAM starting from either low address 0x00010000 (for small kernel  images compiled with make zImage) or high address 0x00100000 (for big kernel images compiled with make bzImage).
  3. Jumps to the setup( ) code.

The code of the setup( ) assembly language function has been placed by the linker at offset 0x200 of the kernel image file. The boot loader can therefore easily locate the
code and copy it into RAM, starting from physical address 0x00090200.

  1. initial 
  2. Jumps to the startup_32( ) assembly language function

There are two different startup_32( ) functions; the one we refer to here is coded in the arch/i386/boot/compressed/head.S. After setup( ) terminates, the function has been moved either to physical address 0x00100000 or to physical address 0x00001000, depending on whether the kernel image was loaded high or low in RAM.

  1. Initializes
  2. decompress the kernel image,  The decompressed image is then moved into its final position, which starts at physical address 0x00100000
  3. Jumps to physical address 0x00100000.

The second startup_32( ) function sets up the execution environment for the first Linux process (process 0). The function performs the following operations:

  1. Initializes
  2. Jumps to the start_kernel( ) function.

setup arch/i386/boot/setup.S
startup_32 arch/i386/boot/compressed/head.S
startup_32 arch/i386/kernel/head.S
start_kernel init/main.c

你可能感兴趣的:(linux,network)