- 492 OUTPUT_ARCH(arm)
- 493 ENTRY(stext)
- 494 jiffies = jiffies_64;
- 495 SECTIONS
- 496 {
- 497 /*
- 498 * XXX: The linker does not define how output sections are
- 499 * assigned to input sections when there are multiple statements
- 500 * matching the same input section name. There is no documented
- 501 * order of matching.
- 502 *
- 503 * unwind exit sections must be discarded before the rest of the
- 504 * unwind sections get included.
- 505 */
- 506 /DISCARD/ : {
- 507 *(.ARM.exidx.exit.text)
- 508 *(.ARM.extab.exit.text)
- 509
- ......
- 645 }
stext 是 Linux 内核的入口地址,在文件 arch/arm/kernel/head.S 中有如下所示提示内容:
- /*
- * Kernel startup entry point.
- * ---------------------------
- *
- * This is normally called from the decompressor code. The requirements
- * are: MMU = off, D-cache = off, I-cache = dont care, r0 = 0,
- * r1 = machine nr, r2 = atags or dtb pointer.
- .....
- */
- 80 ENTRY(stext)
- ......
- 91 @ ensure svc mode and all interrupts masked
- 92 safe_svcmode_maskall r9
- 93
- 94 mrc p15, 0, r9, c0, c0 @ get processor id
- 95 bl __lookup_processor_type @ r5=procinfo r9=cpuid
- 96 movs r10, r5 @ invalid processor (r5=0)?
- 97 THUMB( it eq ) @ force fixup-able long branch encoding
- 98 beq __error_p @ yes, error 'p'
- 99
- ......
- 107
- 108 #ifndef CONFIG_XIP_KERNEL
- ......
- 113 #else
- 114 ldr r8, =PLAT_PHYS_OFFSET @ always constant in this case
- 115 #endif
- 116
- 117 /*
- 118 * r1 = machine no, r2 = atags or dtb,
- 119 * r8 = phys_offset, r9 = cpuid, r10 = procinfo
- 120 */
- 121 bl __vet_atags
- ......
- 128 bl __create_page_tables
- 129
- 130 /*
- 131 * The following calls CPU specific code in a position independent
- 132 * manner. See arch/arm/mm/proc-*.S for details. r10 = base of
- 133 * xxx_proc_info structure selected by __lookup_processor_type
- 134 * above. On return, the CPU will be ready for the MMU to be
- 135 * turned on, and r0 will hold the CPU control register value.
-
- 原子哥在线教学:www.yuanzige.com 论坛:www.openedv.com
- 942
- I.MX6U 嵌入式 Linux 驱动开发指南
- 136 */
- 137 ldr r13, =__mmap_switched @ address to jump to after
- 138 @ mmu has been enabled
- 139 adr lr, BSYM(1f) @ return (PIC) address
- 140 mov r8, r4 @ set TTBR1 to swapper_pg_dir
- 141 ldr r12, [r10, #PROCINFO_INITFUNC]
- 142 add r12, r12, r10
- 143 ret r12
- 144 1: b __enable_mmu
- 145 ENDPROC(stext)
Linux 内核将每种处理器都抽象为一个 proc_info_list 结构体,每种处理器都对应一个 procinfo。因此,可以通过处理器 ID 来找到对应的 procinfo 结构,__lookup_processor_type 函数找 到对应处器的 procinfo 以后会将其保存到 r5 寄存器中。
- 81 __mmap_switched:
- 82 adr r3, __mmap_switched_data
- 83
- 84 ldmia r3!, {r4, r5, r6, r7}
- 85 cmp r4, r5 @ Copy data segment if needed
- 86 1: cmpne r5, r6
- 87 ldrne fp, [r4], #4
- 88 strne fp, [r5], #4
- 89 bne 1b
- 90
- 91 mov fp, #0 @ Clear BSS (and zero fp)
- 92 1: cmp r6, r7
- 93 strcc fp, [r6],#4
- 94 bcc 1b
- 95
- 96 ARM( ldmia r3, {r4, r5, r6, r7, sp})
- 97 THUMB( ldmia r3, {r4, r5, r6, r7} )
- 98 THUMB( ldr sp, [r3, #16] )
- 99 str r9, [r4] @ Save processor ID
- 100 str r1, [r5] @ Save machine type
- 101 str r2, [r6] @ Save atags pointer
- 102 cmp r7, #0
- 103 strne r0, [r7] @ Save control register values
- 104 b start_kernel
- 105 ENDPROC(__mmap_switched)