linux kernel version: 4.8.0 -rc5
1. first core boot process:
arch/arm64/kernel/head.S
-
70 __HEAD
-
71 _head:
-
72 /*
-
73 * DO NOT MODIFY. Image header expected by Linux boot-loaders.
-
74 */
-
75 #ifdef CONFIG_EFI
-
76 /*
-
77 * This add instruction has no meaningful effect except that
-
78 * its opcode forms the magic "MZ" signature required by UEFI.
-
79 */
-
80 add x13, x18, #0x16
-
81 b stext
-
82 #else
-
83 b stext // branch to kernel start, magic
-
84 .long 0 // reserved
-
85 #endif
-
211 ENTRY(stext)
-
212 bl preserve_boot_args
-
213 bl el2_setup // Drop to EL1, w20=cpu_boot_mode
-
214 adrp x24, __PHYS_OFFSET
-
215 and x23, x24, MIN_KIMG_ALIGN - 1 // KASLR offset, defaults to 0
-
216 bl set_cpu_boot_mode_flag
-
217 bl __create_page_tables // x25=TTBR0, x26=TTBR1
-
218 /*
-
219 * The following calls CPU setup code, see arch/arm64/mm/proc.S for
-
220 * details.
-
221 * On return, the CPU will be ready for the MMU to be turned on and
-
222 * the TCR will have been set.
-
223 */
-
224 bl __cpu_setup // initialise processor
-
225 adr_l x27, __primary_switch // address to jump to after
-
226 // MMU has been enabled
-
227 b __enable_mmu
-
228 ENDPROC(stext)
-
781 __primary_switch:
-
782 #ifdef CONFIG_RELOCATABLE
-
783 /*
-
784 * Iterate over each entry in the relocation table, and apply the
-
785 * relocations in place.
-
786 */
-
787 ldr w9, =__rela_offset // offset to reloc table
-
788 ldr w10, =__rela_size // size of reloc table
-
789
-
790 mov_q x11, KIMAGE_VADDR // default virtual offset
-
791 add x11, x11, x23 // actual virtual offset
-
792 add x9, x9, x11 // __va(.rela)
-
793 add x10, x9, x10 // __va(.rela) + sizeof(.rela)
-
794
-
795 0: cmp x9, x10
-
796 b.hs 1f
-
797 ldp x11, x12, [x9], #24
-
798 ldr x13, [x9, #-8]
-
799 cmp w12, #R_AARCH64_RELATIVE
-
800 b.ne 0b
-
801 add x13, x13, x23 // relocate
-
802 str x13, [x11, x23]
-
803 b 0b
-
804
-
805 1:
-
806 #endif
-
807 ldr x8, =__primary_switched
-
808 br x8
-
809 ENDPROC(__primary_switch)
-
421 __primary_switched:
-
422 mov x28, lr // preserve LR
-
423 adr_l x8, vectors // load VBAR_EL1 with virtual
-
424 msr vbar_el1, x8 // vector table address
-
425 isb
-
426
-
427 // Clear BSS
-
428 adr_l x0, __bss_start
-
429 mov x1, xzr
-
430 adr_l x2, __bss_stop
-
431 sub x2, x2, x0
-
432 bl __pi_memset
-
433 dsb ishst // Make zero page visible to PTW
-
434
-
435 adr_l sp, initial_sp, x4
-
436 mov x4, sp
-
437 and x4, x4, #~(THREAD_SIZE - 1)
-
438 msr sp_el0, x4 // Save thread_info
-
439 str_l x21, __fdt_pointer, x5 // Save FDT pointer
-
440
-
441 ldr_l x4, kimage_vaddr // Save the offset between
-
442 sub x4, x4, x24 // the kernel virtual and
-
443 str_l x4, kimage_voffset, x5 // physical mappings
-
444
-
445 mov x29, #0
-
446 #ifdef CONFIG_KASAN
-
447 bl kasan_early_init
-
448 #endif
-
449 #ifdef CONFIG_RANDOMIZE_BASE
-
450 tst x23, ~(MIN_KIMG_ALIGN - 1) // already running randomized?
-
451 b.ne 0f
-
452 mov x0, x21 // pass FDT address in x0
-
453 mov x1, x23 // pass modulo offset in x1
-
454 bl kaslr_early_init // parse FDT for KASLR options
-
455 cbz x0, 0f // KASLR disabled? just proceed
-
456 orr x23, x23, x0 // record KASLR offset
-
457 ret x28 // we must enable KASLR, return
-
458 // to __enable_mmu()
-
459 0:
-
460 #endif
-
461 b start_kernel
-
462 ENDPROC(__primary_switched)
from here, enter C code function: start_kernel().
2. secondary core boot process:
init/main.c ---> start_kernel() --> rest_init(); -> kernel_thread(kernel_init, NULL, CLONE_FS); ---- >
kernel_init(void *unused) ---> kernel_init_freeable(); ----> smp_init();(kernel/smp.c)-->
cpu_up(cpu);
阅读(1210) | 评论(0) | 转发(0) |