1. 汇编部分主流程

1.1 时序图

 

1.2 代码解析

 1 ENTRY(stext)
 2 /*
 3  * Kernel startup entry point.
 4  * ---------------------------
 5  *
 6  * The requirements are:
 7  *   MMU = off, D-cache = off, I-cache = on or off,
 8  *   x0 = physical address to the FDT blob.
 9  *
10  * This code is mostly position independent so you call this at
11  * __pa(PAGE_OFFSET + TEXT_OFFSET).
12  *
13  * Note that the callee-saved registers are used for storing variables
14  * that are useful before the MMU is enabled. The allocations are described
15  * in the entry routines.
16  */
17     __HEAD
18 
19     /*
20      * DO NOT MODIFY. Image header expected by Linux boot-loaders.
21      */
22     b    stext                // 跳转到内核初始化中
23     .long    0                // reserved
24     .quad    TEXT_OFFSET      // Image load offset from start of RAM
25     .quad    0                // reserved
26     .quad    0                // reserved
27     .quad    0                // reserved
28     .quad    0                // reserved
29     .quad    0                // reserved
30     .byte    0x41             // Magic number, "ARM\x64"
31     .byte    0x52
32     .byte    0x4d
33     .byte    0x64
34     .word    0                // reserved
35 
36 ENTRY(stext)
37     mov    x21, x0                  // x21=FDT,FDT是bootloader传过来的,是DTS的基地址
38     bl    __calc_phys_offset        // 计算物理地址和物理地址和线性地址偏移x24=PHYS_OFFSET, x28=PHYS_OFFSET-PAGE_OFFSET
39     bl    el2_setup                 // 从el2模式退回到el1模式
40     mrs    x22, midr_el1            // 获得cpuid x22=cpuid
41     mov    x0, x22
42     bl    lookup_processor_type     // 搜索处理器类型,在arch/arm64/kernel/cputable.c中定义
43     mov    x23, x0                  // x23=current cpu_table
44     cbz    x23, __error_p           // invalid processor (x23=0)?
45     bl    __vet_fdt                 // 检测FDT是否是8字节对齐,位于物理地址的前512MB之内
46     bl    __create_page_tables      // 创建内核页表,x25=TTBR0, x26=TTBR1
47     /*
48      * The following calls CPU specific code in a position independent
49      * manner. See arch/arm64/mm/proc.S for details. x23 = base of
50      * cpu_info structure selected by lookup_processor_type above.
51      * On return, the CPU will be ready for the MMU to be turned on and
52      * the TCR will have been set.
53      */
54     ldr    x27, __switch_data        // 需要注意这里,处理器初始化完成后跳转到__switch_data
55                                        // 这时候MMU已经打开
56     adr    lr, __enable_mmu          // 初始化完成以后ret的时候返回到__enable_mmu所在的地址
57     ldr    x12, [x23, #CPU_INFO_SETUP]
58     add    x12, x12, x28             // cpu_info的地址转换成物理地址
59     br    x12                        // 初始化处理器
60 ENDPROC(stext)

 

posted on 2014-06-11 23:34  choi87  阅读(741)  评论(0)    收藏  举报