armlinux内核启动过程(自解压后)的启动分析_第1页
armlinux内核启动过程(自解压后)的启动分析_第2页
armlinux内核启动过程(自解压后)的启动分析_第3页
armlinux内核启动过程(自解压后)的启动分析_第4页
armlinux内核启动过程(自解压后)的启动分析_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、内核启动过程分析* linux/arch/arm/kernel/head.s* copyright (c) 1994-2002 russell king* copyright (c) 2003 arm limited* all rights reserved* this program is free software; you can redistribute it and/or modify* it under the terms of the gnu general public license version 2 as* published by the free software f

2、oundation.* kernel startup code for all 32-bit cpus#include <linux/linkage.h>#include <linux/init.h>#include <asm/assembler.h>#include <asm/domain.h> #include <asm/ptrace<h> #include <asm/asm-offsets>h> #include <asm/memory.h> #include <asm/threadfo

3、.h>#include <asm/system>h> #if (phys_offset & oxoolfffff)#error '*phys_offset must be at an even 2mib boundary!n/boundary(分界线) #endif#define kernel_ram_vaddr#define kernel_ram_paddr(page.offset + text_offset) (phys_offset + text_offset)* swapper_pg_dir is the virtual address of t

4、he initial page* we place the page tables 16k below kernel_ram_vaddr therefore, we must* make sure that kernel_ram_vaddr is correctly set. currently, we expect* the least significant 16 bits to be 0x8000, but we could probably* relax this restriction to kernel_ram_vaddr >= page_offset + 0x4000.*/

5、 swapper_pg_d让是初始页表的虚拟地址我们将页表放在 kernel_ram_vaddr以下16k的空间中.因此我们必须保证kernel_ram_vaddr已经被正常设置.当前,我们期望的是这个地址的最后 16 bits为0x8000,但我们或许可以放宽这项限制到kernel_ram_vaddr >= page offset + 0x4000.#if (kernel_ram_vaddr & oxffff) != 0x8000#error kernel_ram_vaddr must start at 0xxxxx8000 内核的起始地址必须是 32k 对齐#endifglo

6、blequ 为 16kbkernel startup entry point.* 水这些参数同通常是由解压代码传进来的* this is normally called from the decompressor code. the requirements* are: mmu = off, d-cache = off,icache = dont care, ro = 0,* rl = machine nr, r2 = a tags pointer.* this code is mostly position independent, so if you link the kernel at*

7、 0xc0008000, you call this at pa(0xc0008000).* see linux/arch/arm/tools/mach-types for the complete list of machine* numbers for rlrl中放的是机器id* we're trying to keep crap to a minimum; do not add any machine specific* crap here thatfs what the boot loader (or in extreme 极度的,well justified 合理的* cir

8、cumstances事件,详细事件,zlmage) is for.不要随意的添加机器id,要和bootloard/swapper_pg_dir定义一个全局变量swapper_pg_dir, kernel_ram_vaddr 0x4000/*页表的起始地址,大小.macro pgtbl, rd/*定义一个宏,在建页表时用到*/ldr rd, =(kernel_ram_paddr 0x4000).endm#ifdef config_xip_kernel#define kernel start xip virt addr(config xip phys addr)#define kernel_end

9、_edataoc#else #define kernel_start kernel_ram_vaddr#define kernel.end _end /*内核镜像的结束地址(虚拟地址,在vmlinux.lds.s 中定义)*/#endif提供的相匹配。*/.section m.text.headn, maxn 定义一个.text.head段,段的属性a是允许段,x可执行v entry(stext) 入 口 点msr cpsr_c, #psr_f_bit | psr_i_bit | svc_mode ensure svc mode 管理模式 and irqs disabledmrc pl5, 0

10、, r9, co, co get processor id通过协处理器cpl5的寄存器co来获得bl _lookup_processor_type r5=procinfo r9=cpuid 判断内核是否支持处理器 cpu movs rlo, r5 invalid processor (r5=0)?beq _error_p yes,errorbl _lookup_machine_type r5=machinfo通过机器码判断是否支持单板movsr5 invalid machine (r5=0)?beq _error_a yes,error fafbl _vet_atags检查 atags 合法性

11、bl _create_page_tables创建页表* the following calls cpu specific code in a position independent* mannen see arch/arm/mm/proc-*<s for details. rlo = 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

12、 the cpu control register value.*/idr 13, _svvitch_data address to jump to after mmu has been enabledadr lr, _enable_mmu return (pic) addressadd pc, rlo, #procinfo_initfuncendproc(stext) get offset between vit&phys convert virt addresses to physical address space value, mask mask wanted bitslinu

13、x/arch/arm/kernel/head-common.s _lookup_processor_type: adr r3, 3f ldmda r3, r5 - r7 sub3,3, r7 add r5, r5, r3 add r6, r6, r31: idmia r5, r3, r4 sizeof(procnfoist)and r4 r4, r9 teq r3, r4 beq 2f add r5, r5, #proc_info_sz cmp r5, r6bio lbmov5, #02: mov pc, lr unknown processorendproc(lookup_processor

14、_type) linux/arch/arm/kernel/head-common.s 这段代码的定义地址3: longlong _arch_info_begin.long _arch_info_end_lookup_machine_type:adr r3, 3b r3中存放这标号3处的物理地址ldmia r3, r4, r5, r6 r4 中存放标号 3 处的虚拟地址,r5=_arch_info_begin 的虚 拟地址,r6存放的是_arch_info_end的虚拟地址sub r3, r3, r4 get offset between virt&phys物理地址与虚拟地址间的偏移量

15、add r5, r5, r3 convert virt addresses to r5 也变成了对应的物理地址add r6, r6, r3 physical address spacer6 也变成了对应的物理地址1: idr r3, r5, #machinfo_type get machine typeteq r3, rl matches loader number? 和内核传进的比较beq 2f found匹配了那么就返回head.sadd r5, r5, #sizeof_machine_desc next machine_desc cmp r5, r6比较看看是不是最后一个机器idbio

16、lbmov r5, #0 unknown machine2: mov pc, lrendproc(lookup machine type)#if defined(config_smp)entry (secondary _startup)/* common entry point for secondary cpus.* ensure that wefre in svc mode, and irqs are disabled. lookup* the processor type there is no need to check the machine type* as it has alre

17、ady been validated by the primary processormsr cpsr_c, #psr_f_bit | psr_i_bit | svc.modemrc pl5, 0, r9, co, co get processor idbl _lookup_processor_typemovs rlo, r5 invalid processor?moveq r0 #fpf yes, error 'pbeq _error* use the page tables supplied from _cpu_up.adr 珂 _secondary_dataidmia r4, r

18、5, r7, rl3 address to jump to aftersub r4, r4, r5 mmu has been enabledldr r4, r7, r4 get secondary_data.pgdiradr lr, _enable_mmu return addressadd pc, rlo, #procinfo_initfunc initialise processor (return control reg) endproc(secondary_startup)= & secondary_dataentry(_secondary_switched)ldr sp, r

19、7, #4 get secondary_data.stackmov fp, #0bsecondary _start_kernelendproc(secondary .switched).type_secondary_data, % object_secondary _data:long long secondary _datalong_secondary _switched#endif/setup common bits before finally enabling the mmu. essentially* this is just loading the page table point

20、er and domain access* registers.*/_enable_mmu:#ifdef config_alignment_traporr ro, r0, #cr_a/*使能地址对齐检查功能*/#elsebic ro, r0, #cr_a/*禁止地址对齐检査功能可#endif#ifdef config cpu dcache disable defined(config_smp) */#endif#ifdef config_cpu_bpredict_disablebic ro, ro, #cr_z#endif#ifdef config_cpu_icache_disablebic

21、ro, ro, #cr_i /*禁止指令的 cache*/#endifmov r5, #(domain_val(domain_user, domain.manager) | domain_val(domain_kernel, domain-manager) | domain_val(domain_table, domain.manager) | domain_val(domain_io, domain-client)mcr pl5, 0, r5, c3, co, 0 load domain access register 把内核控制域存入 cpl5 的寄存器c3中mcr pl5, 0, r4,

22、 c2, co, 0 load page table pointer 把页表基址存入 cpl5 的寄存器 c2 中 b _turn_mmu_onendproc(_enable_mmu)严* enable the mmu. this completely changes the structure of the visible* memory space you will not be able to trace execution through this.* if you have an enquiry about this, *please* check the linuxarm-kern

23、el* mailing list archives before sending another post to the list.* r0 = cp#15 control register* rl3 = virtual* address to jump to upon completion* other registers depend on the function called upon completion*/.align 5 /*32k 对齐*/_turn_mmu_on:mov ro, r0mcr pl5, 0, ro, cl, co, 0 write control regmrc

24、pl5, 0, r3, co, co, 0 read id regmov r3, r3mov r3, r3/*为什么这里有两个nop,因为打开mmu操作之后要经过三个cycle之后才生效,这和arm的流水线有关*/mov pc, rl3endproc(_turn_mmu_on)amount which are required to get the kernel runnings which generally means mapping in the kernel code.* r8=machinfo* r9=cpuid* rlo =procinfo* returns:ro, r3, r6,

25、 r7 corrupted r4 = physical page table addresscreate_page_tables: page table addresspgtbl r4* clear the 16k level 1 swapper (交易者)page table*/mov ro, r4mov r3, #0add r6, ro, #0x4000 页表的结束地址1: str r3, ro, #4str r3, ro, #4str r3, ro, #4str r3, ro, #4teq ro, r6bne lb清空整个16k的页表idr r7, rlo, #procinfo_mm_m

26、muflagsj mm_mmuflags*define(procinfo_mm_mmuflags, offsetof(struct*_cpu_mm_mmu_flags);define in archarmkernel旬mov r6, pc, lsr #20 为物理地址orr r3,7, r6, isl #20str r3, r4, r6, lsl #2 个页表占4bit* create identity mapping for first mb of kernel to* cater (满足)for the mmu enable. this identity mapping* will be

27、removed by pagingnit()> we use our current program* counter to determine corresponding (相应的)section base address.*/ start of kernel section此时mmu还没有开启,所以pc flags + kernel base identity mapping填到对应的页表中区,lsl #2是因为一* now setup the pagetables for our kernel direct* mapped region.(地区,范围)*/add ro, r4, #

28、(kernel_start & oxffoooooo) » 18 str r3, ro, #(kernel_start & oxoofooooo) » 18!idr r6, =(kernel_end1) /*内核结束地址(虚拟地址)*/ add ro, ro, #4add r6, r4, r6, lsr #181: cmp ro, r6add3, r3, #1 « 20strls r3, ro, #4bls lb#ifdef config_xip_kernel/* map some ram to cover our data and bss are

29、as*/orr r3, r7, #(kernel_ram_paddr & oxffoooooo).if (kernel_ram_paddr & oxoofooooo)orr r3, r3, #(kernel_ram_paddr & oxoofooooo) endifadd ro, r4, #(kernel_ram_vaddr & oxffoooooo) » 18 str r3, ro, #(kernel_ram_vaddr & 0x00(x)0000) » 18! idr r6, =(_end 1)add ro, ro, #4add

30、f6,4,6, lsr #181: cmp ro, r6add r3, r3, #1 « 20strls r3, ro, #4bls lb#endif* then map first 1mb of ram in case it contains our boot params, add ro, r4, #page_offset » 18orr r6, r7, #(phys_offset & oxffoooooo).if (phys.offset & oxoofboooo)orr r6, i*6, #(phys_offset & oxoofooooo) .endifstr r6, ro#ifdef config debug llldr r7

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论