ARM Linux内核启动2
2016-06-16 来源:eefocus
接着上一篇说,看下面源码:
/*
* 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:
pgtbl r4, r5@ page table address页表地址
/*
* Clear the 16K level 1 swapper page table
*/
mov r0, r4
mov r3, #0
add r2, r0, #0x4000
1: str r3, [r0], #4
str r3, [r0], #4
str r3, [r0], #4
str r3, [r0], #4
teq r0, r2
bne 1b
/*
* 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()创建
mov r2, pc, lsr #20@ start of kernel section
add r3, r8, r2, lsl #20@ flags + kernel base
str r3, [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区域
add r0, r4, #(TEXTADDR & 0xff000000) >> 18@ start of kernel
str r3, [r0, #(TEXTADDR & 0x00f00000) >> 18]!
add r3, r3, #1 << 20
str r3, [r0, #4]!@ KERNEL + 1MB
add r3, r3, #1 << 20
str r3, [r0, #4]!@ KERNEL + 2MB
add r3, r3, #1 << 20
str r3, [r0, #4]@ KERNEL + 3MB
/*
* Then map first 1MB of ram in case it contains our boot params.
*/
add r0, r4, #VIRT_OFFSET >> 18
add r2, r5, r8
str r2, [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 can't use the absolute addresses
* for the __proc_info lists since we aren't 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:
adr r5, 2f
ldmia r5, {r7, r9, r10}
sub r5, r5, r10@ convert addresses
add r7, r7, r5@ to our address space
add r10, r9, r5
mrc p15, 0, r9, c0, c0@ get processor id
1: ldmia r10, {r5, r6, r8} @ value, mask, mmuflags
and r6, r6, r9@ mask wanted bits
teq r5, r6
moveq pc, lr
add r10, r10, #PROC_INFO_SZ@ sizeof(proc_info_list)
cmp r10, r7
blt 1b
mov r10, #0@ unknown processor
mov pc, 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
.long 2b
.long __arch_info_begin
.long __arch_info_end
这段代码的开头标志,看起来是不是很熟悉,这个就是在第一篇中看到的的,不知道的话,可以回过去查看。这段代码主要是有关处理器的查找。
/*
* Lookup machine architecture in the linker-build list of architectures.
* Note that we can't use the absolute addresses for the __arch_info
* lists since we aren't 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:
adr r4, 2b
ldmia r4, {r2, r3, r5, r6, r7}@ throw away r2, r3
sub r5, r4, r5@ convert addresses
add r4, r6, r5@ to our address space
add r7, r7, r5
1: ldr r5, [r4] @ get machine type
teq r5, r1@ matches loader number?
beq 2f@ found
add r4, r4, #SIZEOF_MACHINE_DESC@ next machine_desc
cmp r4, r7
blt 1b
mov r7, #0@ unknown architecture
mov pc, lr
2: ldmib r4, {r5, r6, r7} @ found, get results
mov pc, 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\)文件。
- 松下汽车电子系统与 Arm 携手推进软件定义汽车标准化
- arm处理器中a5 a8 a9,v6 v7,arm7 arm9 arm11都是依据什么来分类的
- ARM处理器架构
- Linux Kernel之flush_cache_all在ARM平台下是如何实现的
- Arm 引领软件定义汽车革新, 共同迈向汽车行业未来
- arm召开2025二季度财报会,V9架构继续大获成功
- ARM、Intel、MIPS处理器啥区别?看完全懂了
- makefile初步制作,arm-linux- (gcc/ld/objcopy/objdump)详解
- ubuntu下使用qemu模拟ARM(六)------驱动程序
- Ubuntu下安装arm-linux-gnueabi-xxx编译器