/*
* 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.
*
* r8 = machinfo
* r9 = cpuid
* r10 = procinfo
*
* Returns:
* r0, r3, r6, r7 corrupted
* r4 = physical page table address
*/
__create_page_tables:
pgtbl r4 @ page table address
/*r4为页表的基地址0x30004000*/
/*
* Clear the 16K level 1 swapper page table
*/
/*清除页表所用的内存为0,0x30004000~0x30007fff*/
mov r0, r4
mov r3, #0
add r6, r0, #0x4000
1: str r3, [r0], #4
str r3, [r0], #4
str r3, [r0], #4
str r3, [r0], #4
teq r0, r6
bne 1b
/*将内核镜像中的MMU flag数值取出,准备设置page table*/
ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags 假如r7=0xabced
/*
* 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.
*/
mov r6, pc @ 取当前pc的值到r6,对当前的地址进行映射
mov r6, r6, lsr #20 @ start of kernel section, 每页的大小为1M,高12位为页表项的索引,mini2440上r6=0x300
orr r3, r7, r6, lsl #20 @ flags + kernel base <span style="color: rgb(102, 102, 102); font-family: 宋体;font-size:12px; line-height: 26px;">根据上句得出的段计数左移20位算出段地址,并将将低20bit设置成MMU的flag,得到一个map entry,假如r3=0x300abced</span>
str r3, [r4, r6, lsl #2] @ identity mapping r4=0x30004000 r6=0x300<<2=0xc00; *(0x30004c00)=0x300abcde
/*
* Now setup the pagetables for our kernel direct
* mapped region.
*/
add r0, r4, #(KERNEL_START & 0xff000000) >> 18 /*为什么是0xff000000,用r0来作为以后建立一个表项后,来增加4个字节的基地址,右移18位=(<pre name="code" class="cpp">#(KERNEL_START & 0xff000000)
<<20)>>2*/str r3, [r0, #(KERNEL_START & 0x00f00000) >> 18]!ldr r6, =(KERNEL_END - 1)add r0, r0, #4add r6, r4, r6, lsr #181: cmp r0, r6
/*对内核虚拟地址的开始
KERNEL_START到结束
KERNEL_END 做映射
*/
add r3, r3, #1 << 20 /*r3的高12位为对应物理页高12位的索引,*/strls r3, [r0], #4 /*r0为要将要写页表内容的页表项地址*/bls 1b/* * Then map first 1MB of ram in case it contains our boot params. */add r0, r4, #PAGE_OFFSET >> 18orr r6, r7, #(PHYS_OFFSET & 0xff000000).if (PHYS_OFFSET & 0x00f00000)orr r6, r6, #(PHYS_OFFSET & 0x00f00000).endifstr r6, [r0]#endifmov pc, lrENDPROC(__create_page_tables)