- 论坛徽章:
- 0
|
函数的流程如图所示:
我的疑问:我认为在内核映像的直接映射的时候,就已经把物理地址第1MB的内存映射了,那为什么还要再次对物理内存的第1MB进行影射呢?
代码如下:
1、内核映像所占区域映射- /*
- * Now setup the pagetables for our kernel direct
- * mapped region.
- */
- mov r3, pc
- mov r3, r3, lsr #SECTION_SHIFT
- orr r3, r7, r3, lsl #SECTION_SHIFT
- add r0, r4, #(KERNEL_START & 0xff000000) >> (SECTION_SHIFT - PMD_ORDER)
- str r3, [r0, #((KERNEL_START & 0x00f00000) >> SECTION_SHIFT) << PMD_ORDER]!
- ldr r6, =(KERNEL_END - 1)
- add r0, r0, #1 << PMD_ORDER
- add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER)
- 1: cmp r0, r6
- add r3, r3, #1 << SECTION_SHIFT
- strls r3, [r0], #1 << PMD_ORDER
- bls 1b
复制代码 2、物理地址空间第1MB映射到线性地址0xc0000000第1MB- /*
- * Then map boot params address in r2 or the first 1MB (2MB with LPAE)
- * of ram if boot params address is not specified.
- */
- mov r0, r2, lsr #SECTION_SHIFT
- movs r0, r0, lsl #SECTION_SHIFT
- moveq r0, r8
- sub r3, r0, r8
- add r3, r3, #PAGE_OFFSET
- add r3, r4, r3, lsr #(SECTION_SHIFT - PMD_ORDER)
- orr r6, r7, r0
- str r6, [r3]
复制代码 整个函数代码如下:- __create_page_tables:
- pgtbl r4, r8 @ page table address
- /*
- * Clear the swapper page table
- */
- mov r0, r4
- mov r3, #0
- add r6, r0, #PG_DIR_SIZE
- 1: str r3, [r0], #4
- str r3, [r0], #4
- str r3, [r0], #4
- str r3, [r0], #4
- teq r0, r6
- bne 1b
- #ifdef CONFIG_ARM_LPAE
- /*
- * Build the PGD table (first level) to point to the PMD table. A PGD
- * entry is 64-bit wide.
- */
- mov r0, r4
- add r3, r4, #0x1000 @ first PMD table address
- orr r3, r3, #3 @ PGD block type
- mov r6, #4 @ PTRS_PER_PGD
- mov r7, #1 << (55 - 32) @ L_PGD_SWAPPER
- 1: str r3, [r0], #4 @ set bottom PGD entry bits
- str r7, [r0], #4 @ set top PGD entry bits
- add r3, r3, #0x1000 @ next PMD table
- subs r6, r6, #1
- bne 1b
- add r4, r4, #0x1000 @ point to the PMD tables
- #endif
- ldr r7, [r10, #PROCINFO_MM_MMUFLAGS] @ mm_mmuflags
- /*
- * Create identity mapping to cater for __enable_mmu.
- * This identity mapping will be removed by paging_init().
- */
- adr r0, __turn_mmu_on_loc
- ldmia r0, {r3, r5, r6}
- sub r0, r0, r3 @ virt->phys offset
- add r5, r5, r0 @ phys __turn_mmu_on
- add r6, r6, r0 @ phys __turn_mmu_on_end
- mov r5, r5, lsr #SECTION_SHIFT
- mov r6, r6, lsr #SECTION_SHIFT
- 1: orr r3, r7, r5, lsl #SECTION_SHIFT @ flags + kernel base
- str r3, [r4, r5, lsl #PMD_ORDER] @ identity mapping
- cmp r5, r6
- addlo r5, r5, #1 @ next section
- blo 1b
- /*
- * Now setup the pagetables for our kernel direct
- * mapped region.
- */
- mov r3, pc
- mov r3, r3, lsr #SECTION_SHIFT
- orr r3, r7, r3, lsl #SECTION_SHIFT
- add r0, r4, #(KERNEL_START & 0xff000000) >> (SECTION_SHIFT - PMD_ORDER)
- str r3, [r0, #((KERNEL_START & 0x00f00000) >> SECTION_SHIFT) << PMD_ORDER]!
- ldr r6, =(KERNEL_END - 1)
- add r0, r0, #1 << PMD_ORDER
- add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER)
- 1: cmp r0, r6
- add r3, r3, #1 << SECTION_SHIFT
- strls r3, [r0], #1 << PMD_ORDER
- bls 1b
- #ifdef CONFIG_XIP_KERNEL
- /*
- * Map some ram to cover our .data and .bss areas.
- */
- add r3, r8, #TEXT_OFFSET
- orr r3, r3, r7
- add r0, r4, #(KERNEL_RAM_VADDR & 0xff000000) >> (SECTION_SHIFT - PMD_ORDER)
- str r3, [r0, #(KERNEL_RAM_VADDR & 0x00f00000) >> (SECTION_SHIFT - PMD_ORDER)]!
- ldr r6, =(_end - 1)
- add r0, r0, #4
- add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER)
- 1: cmp r0, r6
- add r3, r3, #1 << 20
- strls r3, [r0], #4
- bls 1b
- #endif
- /*
- * Then map boot params address in r2 or the first 1MB (2MB with LPAE)
- * of ram if boot params address is not specified.
- */
- mov r0, r2, lsr #SECTION_SHIFT
- movs r0, r0, lsl #SECTION_SHIFT
- moveq r0, r8
- sub r3, r0, r8
- add r3, r3, #PAGE_OFFSET
- add r3, r4, r3, lsr #(SECTION_SHIFT - PMD_ORDER)
- orr r6, r7, r0
- str r6, [r3]
- #ifdef CONFIG_DEBUG_LL
- #if !defined(CONFIG_DEBUG_ICEDCC) && !defined(CONFIG_DEBUG_SEMIHOSTING)
- /*
- * Map in IO space for serial debugging.
- * This allows debug messages to be output
- * via a serial console before paging_init.
- */
- addruart r7, r3, r0
- mov r3, r3, lsr #SECTION_SHIFT
- mov r3, r3, lsl #PMD_ORDER
- add r0, r4, r3
- mov r3, r7, lsr #SECTION_SHIFT
- ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
- orr r3, r7, r3, lsl #SECTION_SHIFT
- #ifdef CONFIG_ARM_LPAE
- mov r7, #1 << (54 - 32) @ XN
- #else
- orr r3, r3, #PMD_SECT_XN
- #endif
- str r3, [r0], #4
- #ifdef CONFIG_ARM_LPAE
- str r7, [r0], #4
- #endif
- #else /* CONFIG_DEBUG_ICEDCC || CONFIG_DEBUG_SEMIHOSTING */
- /* we don't need any serial debugging mappings */
- ldr r7, [r10, #PROCINFO_IO_MMUFLAGS] @ io_mmuflags
- #endif
- #if defined(CONFIG_ARCH_NETWINDER) || defined(CONFIG_ARCH_CATS)
- /*
- * If we're using the NetWinder or CATS, we also need to map
- * in the 16550-type serial port for the debug messages
- */
- add r0, r4, #0xff000000 >> (SECTION_SHIFT - PMD_ORDER)
- orr r3, r7, #0x7c000000
- str r3, [r0]
- #endif
- #ifdef CONFIG_ARCH_RPC
- /*
- * Map in screen at 0x02000000 & SCREEN2_BASE
- * Similar reasons here - for debug. This is
- * only for Acorn RiscPC architectures.
- */
- add r0, r4, #0x02000000 >> (SECTION_SHIFT - PMD_ORDER)
- orr r3, r7, #0x02000000
- str r3, [r0]
- add r0, r4, #0xd8000000 >> (SECTION_SHIFT - PMD_ORDER)
- str r3, [r0]
- #endif
- #endif
- #ifdef CONFIG_ARM_LPAE
- sub r4, r4, #0x1000 @ point to the PGD table
- #endif
- mov pc, lr
- ENDPROC(__create_page_tables)
复制代码 |
|