20169217 "Linux kernel Fundamentals and analysis" work for the second week

Source: Internet
Author: User

Through the second week of study, I want to divide my blog into two parts, the first part is the experimental building Linux kernel Analysis experiment One of the experimental report, the second part of Reading chapter 1,2,18 content and time situation.

Now, first, experiment one.

Experimental content: Disassembly of a C language program into a compilation program.

C Language Program code: should be experimental requirements I have some of the values have been modified.

int g (int x)

{

return x+6;

}

int f (int x)

{

return g (x);

}

int main (void)

{

Return F (9) +3;

}

Experimental process:

First create a MAIN.C file

Write the C language program that has just modified the value

Then use Gcc-s-o main.s main.c-m32 to disassemble the program into assembler,-s to perform disassembly,-m32 to convert to 32-bit assembler. Note that the experimental building environment is 64-bit, so here to add-m32.

Use gedit main.s to view the assembler.

We will find that just a few sentences have become such a complicated assembler, through the simultaneous learning Monensin teacher Mooc I learned that this program as long as "." The statements that begin with, such as ". Globl g", are used to link auxiliary information and are not actually executed, so they can be ignored directly. Then this procedure is simplified and becomes the following form:

G:
PUSHL%EBP
MOVL%esp,%EBP
MOVL 8 (%EBP),%eax
Addl $6,%eax
POPL%EBP
Ret
F:
PUSHL%EBP
MOVL%esp,%EBP
Subl $4,%esp
MOVL 8 (%EBP),%eax
Movl%eax, (%ESP)
Call G
Leave
Ret
Main
PUSHL%EBP
MOVL%esp,%EBP
Subl $4,%esp
Movl $9, (%ESP)
Call F
Addl,%eax
Leave
Ret

We find that, like the C complaint procedure, this assembler is divided into three parts, F function, g function, and main main function. Next, let's briefly analyze the assembler.

For assembler If we are not very familiar with, we can use the original C language Program analysis, first executed is the main function, PUSHL%ebp movl%esp,%ebp two meaning is to save the contents of the stack base pointer, and then copy the stack top pointer to the stack pointer. Subl $4,%esp movl $9, (%ESP) These two instructions mean that the top hand of the stack is assigned a unit under 4 units, and the second instruction stores the value 9 in the unit just allocated. So the purpose of these two instructions is to press the value 9 onto the stack.  Next is call F, which calls the F function, so let's look at the F function. The first three sentences are the same as the first three sentences of the main function, and the fourth sentence Movl 8 (%EBP),%eax it means to transfer the contents of the stack base pointer and 8 corresponding storage unit to the accumulation register eax. The next instruction then copies the EAX content to the position indicated by the top pointer of the stack.    Call G calls the G function. POPL%EBP This directive is equivalent to: MOVL (%ESP),%EBP add $4,%esp. Implements the stack-based pointer ebp that was pressed into the stack before the content is stacked into EBP. Leave is the Undo function stack, and RET is the equivalent of return in C that returns the program run value.

This is basically the case, and by looking at the assembly instructions, we can clearly see how Linux is taking the point to run the program.

Next is the second part, the Linux kernel compilation, through the learning materials I can probably do the Linux kernel compilation and installation, the process is as follows:

Enter the terminal and use the command sudo passwd root to start the root account,

Install the required packages for compiling the kernel

# Apt-get Update

# apt-get Install build-essential kernel-package libncurses5-dev fakeroot Select y

Download 4.7.5 source Package and Unzip

# wget HTTPS://WWW.KERNEL.ORG/PUB/LINUX/KERNEL/V4.X/LINUX-4.7.5.TAR.XZ

# TAR-JXVF LINUX-4.7.5.TAR.XZ

Seemingly slow to download, here I downloaded the latest version 4.7.5

The next step is to configure the kernel:

#cd linux-4.7.5

#make Menuconfig

Then the graphical configuration interface, then the problem, the configuration here I do not quite know what the meaning, I guess it might be similar to the BIOS configuration under Windows, I checked, there is still need to continue to study.

Then compile, compile encountered a relatively large problem, in the compilation process Flash back once, and compile again time is very long, today did not compile successfully, the next need to install a new kernel, etc., the blog first written here, follow-up I will continue to study and study, and do experiments, There are new developments or new questions that will be added here.

20169217 "Linux kernel Fundamentals and analysis" work for the second week

Related Article

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.