/*
- 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.
- This code is mostly position independent, so if you link the kernel at
- 0xc0008000, you call this at __pa(0xc0008000).
- See linux/arch/arm/tools/mach-types for the complete list of machine
- numbers for r1.
- We’re trying to keep crap to a minimum; DO NOT add any machine specific
* crap here - that’s what the boot loader (or in extreme, well justified - circumstances, zImage) is for.
*/
>
> 根据上方示例代码中的注释,Linux 内核启动之前要求如下:
> ①、关闭 MMU。
> ②、关闭 D-cache。
> ③、I-Cache 无所谓。
> ④、r0 = 0。
> ⑤、r1= machine nr(也就是机器 ID)。
> ⑥、r2 = atags 或者设备树(dtb)首地址。
> Linux 内核的入口点 stext 其实相当于内核的入口函数,**stext** 函数内容如下:
>
>
>
ENTRY(stext)
ARM_BE8(setend be ) @ ensure we are in BE8 mode
THUMB( adr r9, BSYM(1f) ) @ Kernel is always entered in ARM.
THUMB( bx r9 ) @ If this is a Thumb-2 kernel,
THUMB( .thumb ) @ switch to Thumb now.
THUMB(1: )
#ifdef CONFIG_ARM_VIRT_EXT
bl __hyp_stub_install
#endif
@ ensure svc mode and all interrupts masked
safe_svcmode_maskall r9
mrc p15, 0, r9, c0, c0 @ get processor id
bl __lookup_processor_type @ r5=procinfo r9=cpuid
movs r10, r5 @ invalid processor (r5=0)?
THUMB( it eq ) @ force fixup-able long branch encoding
beq __error_p @ yes, error ‘p’
#ifdef CONFIG_ARM_LPAE
mrc p15, 0, r3, c0, c1, 4 @ read ID_MMFR0
and r3, r3, #0xf @ extract VMSA support
cmp r3, #5 @ long-descriptor translation table format?
THUMB( it lo ) @ force fixup-able long branch encoding
blo __error_lpae @ only classic page table format
#endif
#ifndef CONFIG_XIP_KERNEL
adr r3, 2f
ldmia r3, {r4, r8}
sub r4, r3, r4 @ (PHYS_OFFSET - PAGE_OFFSET)
add r8, r8, r4 @ PHYS_OFFSET
#else
ldr r8, =PLAT_PHYS_OFFSET @ always constant in this case
#endif
/\*
* r1 = machine no, r2 = atags or dtb,
* r8 = phys_offset, r9 = cpuid, r10 = procinfo
*/
bl __vet_atags
#ifdef CONFIG_SMP_ON_UP
bl __fixup_smp
#endif
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT
bl __fixup_pv_table
#endif
bl __create_page_tables
/\*
* The following calls CPU specific code in a position independent
* manner. See arch/arm/mm/proc-*.S for details. r10 = base of
* xxx_proc_info structure selected by __lookup_processor_type
* above. On return, the CPU will be ready for the MMU to be
* turned on, and r0 will hold the CPU control register value.
*/
ldr r13, =__mmap_switched @ address to jump to after
@ mmu has been enabled
adr lr, BSYM(1f) @ return (PIC) address
mov r8, r4 @ set TTBR1 to swapper_pg_dir
ldr r12, [r10, #PROCINFO_INITFUNC]
add r12, r12, r10
ret r12
1: b __enable_mmu
ENDPROC(stext)
>
> **在 stext 函数中进行了