ARM Linux kernel from entry to start_kernel code analysis-only until the machine type is selected

Source: Internet
Author: User

Reprinted from: http://blog.sina.com.cn/bytex

 

For ARM Linux,
The analysis starts from the First Command of the kernel and goes to the start_kernel () function.
We are currently using the linux-2.6.19 kernel version as an example to analyze, all the code in this article, the front will add a line number to facilitate and source code for comparison.
Example:
In the file init/Main. C:
00478:
Asmlinkage void _ init start_kernel (void)
Above "00478 :"
Indicates the second line. The content after the colon is the source code.

During code analysis, indentation is used to indicate the calling levels of each code.

Some code is specific to the platform. Although most of the functions of the platform are similar, to better describe the code and platform-related code, we chose the at91 (arm926ejs) platform for analysis.

In addition, this article is based on uncompressed kernel.
This article does not discuss ARCH/ARM/boot/compressed.

I. startup Conditions
Generally, the task from system power-on to running to Linux kenel is
Loader to complete.
This article will not introduce the content of Boot Loader too much.
Here we will only discuss how to go to Linux
Some constraints of the kernel, which is generally completed before the boot loader finally jumps to the kernel:
1.
The CPU must be in SVC (supervisor) mode, and IRQ and FIQ interruptions are prohibited;
2. MMU (Memory Management Unit) must be disabled,
In this case, the virtual address is a physical address;
3. Data Cache must be disabled
4.
The Instruction Cache (Instruction Cache) can be enabled or disabled, which is not mandatory;
5. CPU General Register 0
(R0) must be 0;
6. CPU general register 1 (R1) must be ARM Linux machine type (about Machine
Type, which will be explained later)
7. General CPU register 2 (R2) must be a Kernel Parameter List
The physical address (parameter list is the list of device information attributes transmitted by the boot loader to the kernel. For details, see "booting arm
Linux "documentation ).

Ii. Starting Kernel

First, let's explain several important macros (for MMU scenarios ):

Macro
Location
Default Value
Description
Kernel_ram_addrARCH/ARM/kernel/head. s
+ 26
0xc0008000
Virtual Address of the kernel in Ram
Page_offsetInclude/ASM-arm/memeory. h
+ 500xc0000000
Starting virtual address of the kernel space
Text_offsetARCH/ARM/makefile
+ 137Zero X 00008000
Offset between the kernel and the storage space
TextaddrARCH/ARM/kernel/head. s
+ 490xc0008000
Starting virtual address of the kernel
Phys_offsetInclude/ASM-arm/arch-xxx/memory. hPlatform Problems
Starting physical address of RAM

The kernel entry is stext, which is defined in arch/ARM/kernel/vmlinux. LDS. S:
00011:
Entry (stext)
For vmlinux. LDS. S, This Is a ld script file. The format of this file is different from that of assembly and C Programs. This document does not
Script has made many introductions and only explains the content used in the kernel. For more information about LD, see ld.info.
Entry (stext)
Indicates that the program entry is in the stext symbol.
The stext symbol is defined in arch/ARM/kernel/head. S:
Next we will
Linux
The Main Boot Code is listed for a general introduction. Then, we will explain it in detail one by one.

In ARCH/ARM/kernel/head. s
Lines 72-94 are the main code of ARM Linux boot:

00072:
Entry (stext)
00073:
MSRCpsr_c, # psr_f_bit | psr_ I _bit | svc_mode @ ensure SVC
Mode
00074:@ And irqs
Disabled
00075:MRCP15,
0, R9, C0, C0@ Get Processor
ID
00076:
BL_ Lookup_processor_type@ R5 = procinfo
R9 = cpuid
00077:MovsR10,
R5@ Invalid processor (R5 = 0 )?
00078:
Beq_ Error_p@ Yes, error
'P'
00079:
BL_ Lookup_machine_type@
R5 = machinfo
00080:
MovsR8, R5@ Invalid Machine
(R5 = 0 )?
00081:Beq_ Error_a@ Yes, error
'A'
00082:
BL_ Create_page_tables
00083:

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.