微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM Linux内核启动2

ARM Linux内核启动2

时间:11-09 来源:互联网 点击:
上一篇ARM Linux内核启动(1)的衔接。

接着上一篇说,看下面源码:

/*
* Setup the initial page tables. We only setup the barest
* amount which are required to get the kernel running, which
* generally means mapping in the kernel code.只创建内核代码的映射
*
* r5 = physical address of start of RAM
* r6 = physical IO address
* r7 = byte offset into page tables for IO
* r8 = page table flags
*/
__create_page_tables:
pgtblr4, r5@ page table address页表地址

/*
* Clear the 16K level 1 swapper page table
*/
movr0, r4
movr3, #0
addr2, r0, #0x4000
1:strr3, [r0], #4
strr3, [r0], #4
strr3, [r0], #4
strr3, [r0], #4
teqr0, r2
bne1b

/*
* Create identity mapping for first MB of kernel to
* cater for the MMU enable. This identity mapping
* will be removed by paging_init(). We use our current program
* counter to determine corresponding section base address.
*/现在只创建开始1M的映射,其他外设寄存器空间的映射由paging_init()创建
movr2, pc, lsr #20@ start of kernel section
addr3, r8, r2, lsl #20@ flags + kernel base
strr3, [r4, r2, lsl #2]@ identity mapping

/*
* Now setup the pagetables for our kernel direct
* mapped region. We round TEXTADDR down to the
* nearest megabyte boundary. It is assumed that
* the kernel fits within 4 contigous 1MB sections.
*/现在为内核直接映射区建立页表。我们大概将TEXTADDR降到最近的M区域
addr0, r4, #(TEXTADDR & 0xff000000) >> 18@ start of kernel
strr3, [r0, #(TEXTADDR & 0x00f00000) >> 18]!
addr3, r3, #1 < 20
strr3, [r0, #4]!@ KERNEL + 1MB
addr3, r3, #1 < 20
strr3, [r0, #4]!@ KERNEL + 2MB
addr3, r3, #1 < 20
strr3, [r0, #4]@ KERNEL + 3MB

/*
* Then map first 1MB of ram in case it contains our boot params.
*/
addr0, r4, #VIRT_OFFSET >> 18
addr2, r5, r8
strr2, [r0]

linux内核中3GB以上的地址空间为内核空间,所以需要把内核所在的物理空间地址映射到3GB以上。这里只映射了4MB。注意第一节进行了两次映射,一个和物理地址相同映射,另一个映射到3GB以上。

......这中间还有一段代码,就不分析了,都是有关调试的。

/*
* Read processor ID register (CP#15, CR0), and look up in the linker-built
* supported processor list. Note that we cant use the absolute addresses
* for the __proc_info lists since we arent running with the MMU on
* (and therefore, we are not in the correct address space). We have to
* calculate the offset.
*
* Returns:
*r5, r6, r7 corrupted
*r8 = page table flags
*r9 = processor ID
*r10 = pointer to processor structure
*/
__lookup_processor_type:
adrr5, 2f
ldmiar5, {r7, r9, r10}
subr5, r5, r10@ convert addresses
addr7, r7, r5@ to our address space
addr10, r9, r5
mrcp15, 0, r9, c0, c0@ get processor id
1:ldmiar10, {r5, r6, r8}@ value, mask, mmuflags
andr6, r6, r9@ mask wanted bits
teqr5, r6
moveqpc, lr
addr10, r10, #PROC_INFO_SZ@ sizeof(proc_info_list)
cmpr10, r7
blt1b
movr10, #0@ unknown processor
movpc, lr

/*
* Look in include/asm-arm/procinfo.h and arch/arm/kernel/arch.[ch] for
* more information about the __proc_info and __arch_info structures.
*/

内核中定义的处理器信息和平台信息,在连接文件vmlinux.lds.S (arch\arm\kernel)中有如下定义:

vmlinux.lds.S (arch\arm\kernel)

__proc_info_begin = .;
*(.proc.info)
__proc_info_end = .;
__arch_info_begin = .;
*(.arch.info)
__arch_info_end = .;

2:.long__proc_info_end
.long__proc_info_begin
.long2b
.long__arch_info_begin
.long__arch_info_end
这段代码的开头标志,看起来是不是很熟悉,这个就是在第一篇中看到的的,不知道的话,可以回过去查看。这段代码主要是有关处理器的查找。

/*
* Lookup machine architecture in the linker-build list of architectures.
* Note that we cant use the absolute addresses for the __arch_info
* lists since we arent running with the MMU on (and therefore, we are
* not in the correct address space). We have to calculate the offset.
*不能使用绝对地址
* r1 = machine architecture number
* Returns:
* r2, r3, r4 corrupted
* r5 = physical start address of RAM
* r6 = physical address of IO
* r7 = byte offset into page tables for IO
*/
__lookup_architecture_type:
adrr4, 2b
ldmiar4, {r2, r3, r5, r6, r7}@ throw away r2, r3
subr5, r4, r5@ convert addresses
addr4, r6, r5@ to our address space
addr7, r7, r5
1:ldrr5, [r4]@ get machine type
teqr5, r1@ matches loader number?
beq2f@ found
addr4, r4, #SIZEOF_MACHINE_DESC@ next machine_desc
cmpr4, r7
blt1b
movr7, #0@ unknown architecture
movpc, lr
2:ldmibr4, {r5, r6, r7}@ found, get results
movpc, lr

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top