1. Start the system. When the PC is powered on, the 80x86 processor (CPU) self-test in the real mode, starts executing the code at the start address of the physical address 0xFFF0, that is, the start address of the ROM-BIOS. The BIOS of the PC performs system self-test, and initializes the interrupt vector table to the physical address 0x0. The first sector of the boot device is then loaded to the address 0x7c00, and the instructions are performed. This is not related to Linux, the X86 series hardware is set.
Linux's kernel itself cannot be booted, so the role of lilo and loadinglin is to load the system kernel. The principle of LILO can refer to Lilo's readme. From the power-up to the kernel, the process is: Power-Power -> Perform BIOS-> loading The first sector -> LILO-> load the kernel.
The first part of the Linux kernel is written in assembly language (files are boot / bootsect.s). When this program begins to execute, it first moves its part of the code to the absolute address 0x90000, load the following 2K code from the boot device to the address 0x90200, the rest of the kernel is loaded to the address 0x10000. Display "Loading ..." when loading the system.
Then, the program control is handed over to another real mode assembler (boot / setup.s). This part of the program identifies some of the characteristics of the host system and the type of VGA motherboard. If necessary, it allows the user to select video mode for the console. Next, this program moves the entire system from the address 0x10000 to the address 0x1000, enters the protection mode. The program controls the rest of the system, that is, the address 0x1000. The above part of the code annotation is extremely detailed. If you want to K, the comment comment comment with the source is your best help, in addition, someone commented in these code in Chinese, seems to be in the Chinese Linux Forum. You can find it. One step is the decompression process of the system kernel. This part of the code is at address 0x1000 (file /boot/head.s), which initializes the register, then executes Decompress_kernel (), this function is from zboot / inflate.c, zboot / unzip .c and zboot / misc.c three files. After decompression, the data is placed in address 0x100000 (1 meg), which is why Linux cannot run less than 2M memory. The decompressed code is executed at address 0x101000 to complete all 32-bit mode settings: load IDT, GDT, and LDT, identify the processor and coprocessor, set the memory leaf size; finally execute start_kernel (). Start_kernel () In the init / main.c file, there is no return value. This is not explained. If you know about the protection mode, you can read it easily. If you don't understand the protection mode, I suggest you read the Chapter 8 of the 386/486 assembly language. That is a best gate document on the protection mode.
2. The system runs, process tables, and process creation and revoking, execution programs. Do not explain, please find this UNIX or Linux program to see. The readings I recommend are second, third, four chapters of the design and implementation of the UNIX operating system. The book is the BSD4.3. Take another time, the source code is your best teacher, the reference book is to understand the principles.
3. File system. Linux provides a standard interface layer between the kernel and the file system to exchange information between them, which is called "VFS" and virtual file systems. Therefore, the code of the file system is divided into two layers: the upper layer is the management of the core data sheet and the data structure, and the lower layer is the function set of the file system and the data structure involving VFS. All dependencies of the file system are in the fs / *. C file. Their main functions are: management cache; (buffer.c) responding to FCNTL () and ioctl () system calls; (fcntl.c ioctl.c) in nodes and caches Pipes and FIFOS; (FIFO.C PIPE.C) Management file and node table; (file_table.c inode.c) lock / unlock files and directories; (LOCKS.C) mapping node name; (Namei.c open.c) to achieve flexible SELECT () function; (SELECT) .c) Provide system information; (stat.c) installation / unload file system; (super.c) execute executable file and memory information dump; (Exec.c) load different binary format; (bin_fmt * .c) The VFS interface consists of some relatively advanced operations, including the functionality of the file system and features that are completed by the specific file system. The most relevant structure has inode_Operations and File_Operations, of course they are not isolated, and some other data structures. These are all defined in the include / linux / fs.h file. The real file system is in the kernel's entrance to the file_system_type structure, and the file_system_type list is in the fs / filesystems.c file, which will be referenced when a mount operation occurs. The function read_super of the corresponding file system type fills in the contents of SUPER_BLOCK, ie, in order to fill in SUPER_OPERATIONS and TYPE_SB_INFO, the former provides a pointer to the general file system operation pointing to the current file system type, which gives the latter to give this file system type special information. The file system type is a list, the function (UN) register_filesystem is the file system type to the kernel registration / deletion, in the file fs / super. Implementation in C. The file system type task is to put a relatively advanced VFS operation image to a physical medium (disk, network, etc.) by performing low-level operations. The VFS interface is very flexible, which supports traditional UNIX file systems, also supports external MSDOS and UMSDOS. In addition to its own directory, each file system type consists of the following elements: 1. The portal system array file_systems [] entry; (fs / filesystem.c) 2. Super block containing files; (include / linux / type_fs.h) 3 Node contains files; (include / Linux / type_fs_i.h) 4. Generally include files; (include / Linux / type_fs.h) 5. Two lines in file include / linux / fs.h # include, 6. The entrance to SUPER_BLOCK and INODE; file system itself includes all related code for nodes and data management processed under Minix as an example to take a look at the working mechanism of VFS. When the MINIX file system is installed, the function minix_read_super reads the data from the installation device to fill in the structure Super_Block. In the structure, S_OP acquires points to the MiniX_SOPS pointer, the general file system uses MiniX_SOPS to assign a hyperlink operation.