您的位置 首页 电子

ARM Linux内核发动2

上一篇ARMLinux内核启动(1)的衔接。接着上一篇说,看下面源码:/**Setuptheinitialpagetables.Weonlysetupthebare…

上一篇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

这段代码也和上面的相同。这段完结的作业主要是判别内核对这个渠道的支撑。那渠道信息在那里界说呢?

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,

当想要增加新的渠道是,需修正Mach-types (arch\arm\tools)这个文件,由于内核在编译时Makefile脚本会依据

Mach-types (arch\arm\tools)文件生成Mach-types.h (include\asm-arm\)文件。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/dianzi/277326.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部