分类: LINUX
2010-03-31 08:38:33
查询到了处理器类型和系统的内存映像后就要进入初始化过程中比较关键的一步了,开始设置mmu,但首先要设置一个临时的内核页表,映射4m的内存,这在初始化过程中是足够了:
//r5=0800 0000 ram起始地址 r6=0020 0000 io地址,r7=f020 0000 虚io
teq r7, #0 @ invalid architecture?
moveq r0, #'a' @ yes, error 'a'
beq __error
bl __create_page_tables
其中__create_page_tables为:
__create_page_tables:
pgtbl r4
//r4=0800 4000 临时页表的起始地址
//r5=0800 0000, ram的起始地址
//r6=0020 0000, i/o寄存器空间的起始地址
//r7=0000 3c08
//r8=0000 0c1e
//the page table in 0800 4000 is just temp base page, when init_task's sweaper_page_dir ready,
// the temp page will be useless
// the high 12 bit of virtual address is base table index, so we need 4kx4 = 16k temp base page,
mov r0, r4
mov r3, #0
add r2, r0, #0x4000 @ 16k of page table
1: str r3, [r0], #4 @ Clear page table
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.
* This is marked cacheable and bufferable.
*
* The identity mapping will be removed by
*/
// 由于linux编译的地址是0xC0008000,load的地址是0x08008000,我们需要将虚地址0xC0008000映射到0800800一段
//同时,由于部分代码也要直接访问0x08008000,所以0x08008000对应的表项也要填充
// 页表中的表象为section,AP=11表示任何模式下可访问,domain为0。
add r3, r8, r5 @ mmuflags + start of RAM
//r3=0800 0c1e
add r0, r4, r5, lsr #18
//r0=0800 4200
str r3, [r0] @ identity mapping
//*0800 4200 = 0800 0c1e 0x200表象 对应的是0800 0000 的1m
/*
* Now setup the pagetables for our kernel direct
* mapped region. We round TEXTADDR down to the
* nearest megabyte boundary.
*/
//下面是映射4M
add r0, r4, #(TEXTADDR & 0xfff00000) >> 18 @ start of kernel
//r0 = r4+ 0x3000 = 0800 4000 + 3000 = 0800 7000
str r3, [r0], #4 @ PAGE_OFFSET + 0MB
//*0800 7004 = 0800 0c1e
add r3, r3, #1 << 20
//r3=0810 0c1e
str r3, [r0], #4 @ PAGE_OFFSET + 1MB
//*0800 7008 = 0810 0c1e
add r3, r3, #1 << 20
str r3, [r0], #4
//*0800 700c = 0820 0c1e @ PAGE_OFFSET + 2MB
add r3, r3, #1 << 20
str r3, [r0], #4 @ PAGE_OFFSET + 3MB
//*0800 7010 = 0830 0c1e
bic r8, r8, #0x0c @ turn off cacheable
//r8=0000 0c12 @ and bufferable bits
mov pc, lr //子程序返回。
下一回 arm linux 就要开始打开mmu的操作了