可以看出,内核镜像起始地址为0xc0004000,终止地址为0xc04b0910,但是起始地址处到0xc0008000之间32K的地址似乎没有内容,内核镜像大小大约4M。那么这个内核镜像在物理内存是如何布局的呢。在/arch/arm/kernel/head.S中有描述:
- #define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET)
- //这个是内核线性地址的开始,PAGE_OFFSET = 0xc0000000 而TEXT_OFFSET = 0x00008000,所以KERNEL_RAM_VADDR = 0xc0008000
- #define KERNEL_RAM_PADDR (PHYS_OFFSET + TEXT_OFFSET)
- //这个是内核物理地址的开始处,PHYS_OFFSET = 0x30000000 而TEXT_OFFSET = 0x00008000,所以KERNEL_RAM_PADDR = 0x30008000,所以bootloader将内核装载到这个地址处,装载到其他地址是不行的
- #if (KERNEL_RAM_VADDR & 0xffff) != 0x8000
- #error KERNEL_RAM_VADDR must start at 0xXXXX8000
- #endif
- //检查定义的是否合法,内核开始物理地址必须是0xXXXX8000
- .globl swapper_pg_dir
- .equ swapper_pg_dir, KERNEL_RAM_VADDR - 0x4000
- //swapper_pg_dir这个变量是内核全局页表的起始地址 可以看出这里是0xc0004000,与内核链接符号表相同
- .macro pgtbl, rd
- ldr \rd, =(KERNEL_RAM_PADDR - 0x4000)
- .endm
- //声明一个宏,作用就是将0x30004000赋值给rd
- #ifdef CONFIG_XIP_KERNEL ///没定义
- #define KERNEL_START XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR)
- #define KERNEL_END _edata_loc
- #else
- #define KERNEL_START KERNEL_RAM_VADDR
- #define KERNEL_END _end //_end是内核链接符号表中的变量,代表内核结束线性地址
- #endif
- ENTRY(stext)
- setmode PSR_F_BIT | PSR_I_BIT | SVC_MODE, r9 @ ensure svc mode
- @ and irqs disabled
- mrc p15, 0, r9, c0, c0 @ get processor id
- bl __lookup_processor_type @ r5=procinfo r9=cpuid
- movs r10, r5 @ invalid processor (r5=0)?
- beq __error_p @ yes, error 'p'
- bl __lookup_machine_type @ r5=machinfo
- movs r8, r5 @ invalid machine (r5=0)?
- beq __error_a @ yes, error 'a'
- bl __vet_atags
- 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_machine_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, __switch_data @ address to jump to after
- @ mmu has been enabled
- adr lr, BSYM(__enable_mmu) @ return (PIC) address
- ARM( add pc, r10, #PROCINFO_INITFUNC )
- THUMB( add r12, r10, #PROCINFO_INITFUNC )
- THUMB( mov pc, r12 )
- ENDPROC(stext)
