Chinaunix首页 | 论坛 | 博客
  • 博客访问: 810735
  • 博文数量: 118
  • 博客积分: 2067
  • 博客等级: 大尉
  • 技术积分: 1751
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-17 14:27
文章存档

2016年(1)

2013年(1)

2012年(3)

2011年(26)

2010年(47)

2009年(40)

分类: LINUX

2016-10-13 11:27:36

linux kernel version: 4.8.0 -rc5

1. first core boot process:
arch/arm64/kernel/head.S 
    

点击(此处)折叠或打开

  1. 70 __HEAD
  2.  71 _head:
  3.  72 /*
  4.  73 * DO NOT MODIFY. Image header expected by Linux boot-loaders.
  5.  74 */
  6.  75 #ifdef CONFIG_EFI
  7.  76 /*
  8.  77 * This add instruction has no meaningful effect except that
  9.  78 * its opcode forms the magic "MZ" signature required by UEFI.
  10.  79 */
  11.  80 add x13, x18, #0x16
  12.  81 b stext
  13.  82 #else
  14.  83 b stext              // branch to kernel start, magic
  15.  84 .long 0              // reserved
  16.  85 #endif


点击(此处)折叠或打开

  1. 211 ENTRY(stext)
  2. 212 bl preserve_boot_args
  3. 213 bl el2_setup                      // Drop to EL1, w20=cpu_boot_mode
  4. 214 adrp x24, __PHYS_OFFSET
  5. 215 and x23, x24, MIN_KIMG_ALIGN - 1      // KASLR offset, defaults to 0
  6. 216 bl set_cpu_boot_mode_flag
  7. 217 bl __create_page_tables // x25=TTBR0, x26=TTBR1
  8. 218 /*
  9. 219 * The following calls CPU setup code, see arch/arm64/mm/proc.S for
  10. 220 * details.
  11. 221 * On return, the CPU will be ready for the MMU to be turned on and
  12. 222 * the TCR will have been set.
  13. 223 */
  14. 224 bl __cpu_setup              // initialise processor
  15. 225 adr_l x27, __primary_switch // address to jump to after
  16. 226                              // MMU has been enabled
  17. 227 b __enable_mmu
  18. 228 ENDPROC(stext)


点击(此处)折叠或打开

  1. 781 __primary_switch:
  2. 782 #ifdef CONFIG_RELOCATABLE
  3. 783 /*
  4. 784 * Iterate over each entry in the relocation table, and apply the
  5. 785 * relocations in place.
  6. 786 */
  7. 787 ldr w9, =__rela_offset              // offset to reloc table
  8. 788 ldr w10, =__rela_size              // size of reloc table
  9. 789
  10. 790 mov_q x11, KIMAGE_VADDR // default virtual offset
  11. 791 add x11, x11, x23              // actual virtual offset
  12. 792 add x9, x9, x11              // __va(.rela)
  13. 793 add x10, x9, x10              // __va(.rela) + sizeof(.rela)
  14. 794
  15. 795 0: cmp x9, x10
  16. 796 b.hs 1f
  17. 797 ldp x11, x12, [x9], #24
  18. 798 ldr x13, [x9, #-8]
  19. 799 cmp w12, #R_AARCH64_RELATIVE
  20. 800 b.ne 0b
  21. 801 add x13, x13, x23          // relocate
  22. 802 str x13, [x11, x23]
  23. 803 b 0b
  24. 804
  25. 805 1:
  26. 806 #endif
  27. 807 ldr x8, =__primary_switched
  28. 808 br x8
  29. 809 ENDPROC(__primary_switch)


点击(此处)折叠或打开

  1. 421 __primary_switched:
  2. 422 mov x28, lr // preserve LR
  3. 423 adr_l x8, vectors // load VBAR_EL1 with virtual
  4. 424 msr vbar_el1, x8 // vector table address
  5. 425 isb
  6. 426
  7. 427 // Clear BSS
  8. 428 adr_l x0, __bss_start
  9. 429 mov x1, xzr
  10. 430 adr_l x2, __bss_stop
  11. 431 sub x2, x2, x0
  12. 432 bl __pi_memset
  13. 433 dsb ishst // Make zero page visible to PTW
  14. 434
  15. 435 adr_l sp, initial_sp, x4
  16. 436 mov x4, sp
  17. 437 and x4, x4, #~(THREAD_SIZE - 1)
  18. 438 msr sp_el0, x4 // Save thread_info
  19. 439 str_l x21, __fdt_pointer, x5 // Save FDT pointer
  20. 440
  21. 441 ldr_l x4, kimage_vaddr // Save the offset between
  22. 442 sub x4, x4, x24 // the kernel virtual and
  23. 443 str_l x4, kimage_voffset, x5 // physical mappings
  24. 444
  25. 445 mov x29, #0
  26. 446 #ifdef CONFIG_KASAN
  27. 447 bl kasan_early_init
  28. 448 #endif
  29. 449 #ifdef CONFIG_RANDOMIZE_BASE
  30. 450 tst x23, ~(MIN_KIMG_ALIGN - 1) // already running randomized?
  31. 451 b.ne 0f
  32. 452 mov x0, x21 // pass FDT address in x0
  33. 453 mov x1, x23 // pass modulo offset in x1
  34. 454 bl kaslr_early_init // parse FDT for KASLR options
  35. 455 cbz x0, 0f // KASLR disabled? just proceed
  36. 456 orr x23, x23, x0 // record KASLR offset
  37. 457 ret x28 // we must enable KASLR, return
  38. 458 // to __enable_mmu()
  39. 459 0:
  40. 460 #endif
  41. 461 b start_kernel
  42. 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) |
0

上一篇:shell 循环

下一篇:没有了

给主人留下些什么吧!~~