Linux Kernel section III 20135332 Seibu Yao

Source: Internet
Author: User

Summary section:

Linux Kernel source code:

Arch supports different CPU source code; main concern x86

Init kernel-initiated code; focus on MAIN.C, the entire Linux kernel boot code start_kernel function

Kernel Core Code

Installing the kernel Source: How to install the kernel source code

Build Linux System OS

Using GDB to track kernel run procedures

-S CPU freezes before it is initialized

-S create server on TCP port

Analysis Start_kernel function

Trap Init involving interruptions

This function is used to initialize the system-related interrupt handling, and call __trap_init ((void *) Vectors_base ()) in the function.

The exception function sets the vector to the address at which the vectors_base begins. The __trap_init function is located in ENTRY-ARMV. s file, for ARM processors, there are several ways to reset, undefined instruction, SWI, prefetch termination, data termination, IRQ, and Fiq.

SWI is primarily used to implement system calls, and after an IRQ has been generated, the exception vector enters the interrupt processing process and executes the DO_IRQ function.

Rest_init:init_process Initializing Process # 1th

Start_kernel: Create process number No. 0

Mm_init: Initialization of memory management module

Sched_init: call Process scheduling initialization

Initialize the system scheduling process, mainly to the timer mechanism and clock interrupt bottom half initialization function to set.

The time-related initialization process has two main steps:

(1) Call the Init_timervecs () function to initialize the kernel timer mechanism;

(2) Call the INIT_BH () function to set the BH function corresponding to the BH vector timer_bh, TQUEUE_BH, and IMMEDIATE_BH respectively to TIMER_BH (), TQUEUE_BH (), and IMMEDIATE_BH () functions

Kthreadd: Kernel thread for managing system resources

The idle idle process is dispatched when the system does not have a process to execute, that is, process number No. 0, which persists.

Qemu start a virtual machine

: Start the first process first, and everything is started by the first process.

-kernel file name –initrd rootfs.img

After the kernel starts, it needs to access the hard disk, Nic.

Understanding of Linux Startup:

The initial stage

The computer automatically reads the stored programs from the motherboard's BIOS (Basic input/output System). This procedure usually knows some hardware directly connected to the motherboard (hard disk, network interface, keyboard, serial port, and port). Most of the BIOS now allows you to start your computer by selecting one from a floppy disk, CD-ROM, or hard disk.

Phase II

The computer will read the starting bytes from the storage device of your choice (for example, CD-ROM is bytes, if we start from the CD-ROM). This bytes is called the Master Boot record MBR (Master boot recording). The MBR tells the computer to load the boot loader (boot loader) from one of the devices ' partitions (partition). Boot Loader stores information about the operating system (OS), such as the name of the operating system, the location of the operating system kernel (kernel), and so on. The usual boot loader are grub and Lilo.

Phase III

Boot loader will help us load kernel. Kernel is actually a program to operate the computer, it is the kernel of the computer operating system, the main task is to manage the computer's hardware resources, as a software and hardware interface. Any operation on the operating system is communicated to the hardware via kernel. Windows and Linux each have their own kernel. The narrow-sense operating system refers to the kernel, generalized operating system including kernel and kernel above the various applications.

Load Kernel Stage

If we load a Linux kernel,linux kernel start working. Kernel first reserves the memory space it needs to run, and then detects the computer hardware through the driver (driver). This allows the operating system to know what hardware is available. The kernel will then start an init process. It is a 1th process in a Linux system (Linux does not have a process number No. 0). In this, kernel completed the computer start-up phase of the work, the handover to Init to manage.

Summary: Init process kernel

Run the INIT process phase

(depending on the boot loader option, Linux can now enter single user mode.) In this mode, the initial script has not been executed and we can detect and fix possible errors on the computer.

Init then runs a series of initial scripts (startup scripts), which are common shell scripts in Linux. These scripts perform the following functions:

Set the computer name, time zone, detect the file system, mount the hard disk, empty the temporary files, set up the network ...

Summarize

BIOS, MBR---boot loader, kernel---init process

Resources:

Http://www.linuxidc.com/Linux/2015-03/114679.htm

Http://www.jb51.net/LINUXjishu/214026.html

Experimental section: 

CD linuxkernel/

Qemu-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img

QEMU is equivalent to opening a virtual machine

Kernel starts a kernel, and the location is specified by the file name after it.

INITRD instruction is to mount a virtual hard disk, rootfs.img is this virtual hard disk

You can see that menuos only supports three commands

Debug kernel with GDB trace

Qemu-kernel linux-3.18.6/arch/x86/boot/bzimage-initrd rootfs.img-s -S # Description of the-s and-s options:

#-S Freeze CPU at startup (with ' C ' to start execution)

#-S Shorthand for-gdb tcp::1234 If you do not want to use port 1234, you can use-GDB tcp:xxxx to replace the-s option

Split the shell window horizontally

Gdb

(gdb) file Linux-3.18.6/vmlinux # Loading symbol table before Targe remote in GDB interface

(GDB) Target remote:1234 # Establish a connection between GDB and Gdbserver, press C to keep the Linux on qemu running

(GDB) Break Start_kernel # breakpoints can be set before target remote or after

First breakpoint: Start_kernel

List to see the code near it:

Second breakpoint: Rest_init

Linux Kernel section III 20135332 Seibu Yao

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.