新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > ARM Linux內(nèi)核啟動(dòng)2

ARM Linux內(nèi)核啟動(dòng)2

作者: 時(shí)間:2016-11-09 來源:網(wǎng)絡(luò) 收藏
上一篇ARM Linux內(nèi)核啟動(dòng)(1)的銜接。

接著上一篇說,看下面源碼:

本文引用地址:http://m.butianyuan.cn/article/201611/317996.htm

/*
* 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.只創(chuàng)建內(nèi)核代碼的映射
*
* 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.
*/現(xiàn)在只創(chuàng)建開始1M的映射,其他外設(shè)寄存器空間的映射由paging_init()創(chuàng)建
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.
*/現(xiàn)在為內(nèi)核直接映射區(qū)建立頁表。我們大概將TEXTADDR降到最近的M區(qū)域
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內(nèi)核中3GB以上的地址空間為內(nèi)核空間,所以需要把內(nèi)核所在的物理空間地址映射到3GB以上。這里只映射了4MB。注意第一節(jié)進(jìn)行了兩次映射,一個(gè)和物理地址相同映射,另一個(gè)映射到3GB以上。

......這中間還有一段代碼,就不分析了,都是有關(guān)調(diào)試的。

/*
* 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.
*/

內(nèi)核中定義的處理器信息和平臺(tái)信息,在連接文件vmlinux.lds.S (archarmkernel)中有如下定義:

vmlinux.lds.S (archarmkernel)

__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
這段代碼的開頭標(biāo)志,看起來是不是很熟悉,這個(gè)就是在第一篇中看到的的,不知道的話,可以回過去查看。這段代碼主要是有關(guān)處理器的查找。

/*
* 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.
*不能使用絕對(duì)地址
* 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

這段代碼也和上面的一樣。這段完成的工作主要是判斷內(nèi)核對(duì)這個(gè)平臺(tái)的支持。那平臺(tái)信息在那里定義呢?

MACHINE_START (KEV7A400, "Sharp KEV7a400")
MAINTAINER ("Marc Singer")
BOOT_MEM (0xc0000000, 0x80000000, io_p2v (0x80000000))
BOOT_PARAMS (0xc0000100)
MAPIO (kev7a400_map_io)
INITIRQ (lh7a400_init_irq)
.timer= &lh7a40x_timer,
MACHINE_END

主要是通過MACHINE_START宏,

/*
* Set of macros to define architecture features. This is built into
* a table by the linker.
*/
#define MACHINE_START(_type,_name)
const struct machine_desc __mach_desc_##_type
__attribute__((__section__(".arch.info"))) = {
.nr= MACH_TYPE_##_type,
.name= _name,

當(dāng)想要添加新的平臺(tái)是,需修改Mach-types (archarmtools)這個(gè)文件,因?yàn)閮?nèi)核在編譯時(shí)Makefile腳本會(huì)根據(jù)

Mach-types (archarmtools)文件生成Mach-types.h (includeasm-arm)文件。



關(guān)鍵詞: ARMLinux內(nèi)核啟

評(píng)論


技術(shù)專區(qū)

關(guān)閉