Linux0.11 Start ModeBIOS boot
When the PC power is turned on, the CPU of the 80X86 structure will automatically enter the real mode and automatically execute the program from 0XFFFF0.
This is usually the address in Rom-bios. The BIOS of the PC will perform some system detection and start at Physical address 0 at the beginning
Initializes the interrupt vector. The first sector of the bootable device is then read into the memory absolute address 0x7c00, and jumps to this
A place.
Bootsect.s/setup.sBootsect.s
The first part of Linux is Boot/bootsect.s, which will be read into the absolute memory address 0x7c00 by the BIOS,
When it is executed it will move itself to the memory absolute address 0x90000 (576KB), and put the boot device back
2KB byte code BOOT/SETUP.S read into memory 0x90200, while other parts of the kernel (System module)
is read into the memory address 0x10000 (64KB) at the beginning, so the order of execution starts from the machine appliance such as.
Setup.s
The message "Loading ..." will be displayed during system load. Then control will be passed to BOOT/SETUP.S, which is
Another real-mode assembly language program.
The boot section identifies certain features of the host and, if necessary, requires a book to select the display mode for the console. Then the entire
System moves from address 0x10000 to 0x0000, reads and retains system parameters for the systems module, and then enters
Protection mode and jump to the rest of the system (0x0000).
System Module LoadingHead.s
The Head.s is located on the system module head. From here, the kernel is fully operating in protected mode. This program
can be relatively single. The first is to load individual data segment registers, reset the interrupt descriptor Table IDT, and enable the tables to execute a
Only the wrong dummy interrupt subroutine Ignore_int is reported. Then reset the GDT to detect if the A20 address line is actually turned on,
If it doesn't turn into a dead loop. Detect the Math coprocessor.
Set up a paging mechanism to place the page catalog table at the beginning of the absolute physical address 0 (this program will be overwritten). At last
Head.s uses the return instruction to eject the entry address of the/INIT/MAIN.C program, which is pre-placed on the stack, to run
Main () program.
Main.c
The MAIN.C program first uses the system parameters obtained by the previous SETUP.S program to set the system's root file device number and a
Some memory global variables.
Initializing the basic Environment
The kernel first initializes all aspects of the hardware. Includes trap doors, block devices, character devices, and TTY, including manual settings
The first task (task 0). When all initialization is complete, set the interrupt allow flag to turn on interrupt and "manually" switch
Run to task 0.
Task 0 Startup (Idle process)
Direct fork () creates task 1, because the kernel-created process cannot use copy-on-write, and the kernel
And then create a new task 1 to share the stack, so you can not use the stack to break other programs to run, so use the internal
The associated function fork () and pause (). The pause () loop begins after Task 1 is created.
Task 1 Startup (init process)
Note: The init process is created by the user-state process idle process, so you can use Copy-on-write,
So you can use stacks
System initialization has been performed in main (), including memory management, various hardware devices, and drivers. Init ()
The function runs in the child process (Task 1) that was created for the first time in task 0. It begins with the first program that will be executed
(shell), and then loads the program in a non-interactive shell mode and executes it (see below
Task 2 starts) and waits for Task 2 to end.
The init process creates a new shell process again at the end of Task 2, which is run as a login shell/bin/sh
Of After the child process that was created has been waiting to be returned, the child process that was created will close all previously left
Handle (stdin, stdout, stderr), create a new session and set the process group number, and then reopen
/dev/tty0 as stdin, and copied into stdout and stderr. Execute/bin/sh again.
Another function of wait () is to handle the orphan process. If the parent process of a process terminates first, the process
The parent process is set to the INIT process here, and the INIT process is responsible for releasing a process that has been terminated by any
Data structure and other resources.
Task 2 startup (/bin/sh)
First created
Created by the INIT process, close file descriptor 0 (stdin), open the/etc/rc file as read-only, and use the Execve () function to replace itself with a/bin/sh program and then execute/bin/sh. Since the operation of SH here is non-interactive, it exits immediately after executing the command in the RC file, and process 2 ends.
Non-first-time creation
Run as a login shell, interactive shell.
Newer start-up mode
In the previous program, the Init () function directly began executing the command interpreter (shell program)/bin/sh, and
This is not the case in a system that is actually available. In order to have the ability to log in to the system and multiple people to use the system simultaneously,
The usual system is to perform the system initialization program init.c here or in a similar place, and this program will be based on the system/etc/
directory, create child processes for each end device supported in the system, and
Terminal initialization Setup Agettty (collectively Getty), the Gettty program displays the user's login
Message "Login:". After the user has typed the user name, Getty is replaced with the login program. Login Program Verification
After the user has entered the correct password, finally call the shell program, and enter the shell interactive work interface.
The primary task of the INIT process is to execute the commands set in the/ETC/RC file according to the information set in the
The information in the/etc/inittab file creates a sub-process for each terminal device that allows login, using fork ()
and run Getty in each newly created child process. While the INIT process calls wait (), it goes to the end of the waiting child process
State.
Each time a child process exits, it knows which corresponding terminal's child process is ended, based on the PID returned, so
A new sub-process will be created for the corresponding terminal. Each of the permitted terminals is a corresponding
Process for which it waits.
When the system shuts down, Init is responsible for killing all other processes, unloading all file systems, and stopping the processor
And it is configured to do the work.
Getty Program
The main task of the Gettty program is to set the terminal type, properties, speed, and wiring procedures. It opens and initializes a TTY
Port, displays the prompt message, and waits for the user to type the user name. The program can only be executed by Superuser. Usually, if
/etc/issue text file exists, Getty will first display the text information in it, and then display the login prompt letter
User input login name, and execute the login program.
Login Program
The login program is primarily used to require the login user to enter a password. It passwd from the password file according to the username entered by the user.
And then call Getpass () to display the "password:" Prompt to read the user
Type the password, and then use the encryption algorithm to encrypt the password that you typed, and with the password file in the user item
pw_passwd field for comparison. If the login fails, the login program exits the Wait () that was executed and was init by the parent process
Received, Init creates a sub-process again based on the recorded information, and again in the process for that terminal
Execute Getty.
If the user has typed the correct password, login will modify the current working directory to the user's starting point specified in the password file.
Directory. and modify the access rights of the corresponding terminal to user read/write and group write, set the process group ID. Then use the resulting
Information that initializes the environment variable information, such as (home=). Then show/ETC/MOTD (Message-of-the-day)
The text information in the file and checks to see if the user has information about the message. Last login program changed to login
The user's user ID and executes the shell program specified by the user entry in the user password file, such as Bash post csh. If
If the shell is not specified, the default/bin/sh is used.
Shell Program
During login, when login starts executing the shell, the first character of the parameter argv[0] is '-', indicating that the
The shell is executed as a login shell. At this point, the shell program performs some and the login process based on the character
The appropriate action. The login shell is first read from the/etc/profile file and the. profile file (if present)
Command and execute. If you set the ENV environment variable when entering the shell or set the variable in. Profile,
The shell next reads the command from the file named by the variable and executes it. So the user should put each login as
The command to execute is placed in the. profile file, and the command to execute each run of the shell is placed in the ENV variable
The specified file in the volume.
If you put it in. Profile:
env= $HOME/.anyfilename; Export ENV
Summary of kernel Initiation mode of reading notes of "Linux0.11 Kernel full annotation"