关于6410开发板Linux内存地址0Xc0008000的由来

Rafema 2011-03-08

查看6410数据手册可以看到,内存开始地址应该是0x50000000,而实际在real6410开发板使用过程中U-boot加载Linux内核都是加载到0xC0008000处开始运行,我猜测(还没有看代码来验证猜测)这个是因为Linux启动内核的地址为0xC0008000,而U-boot为了和Linux保持一致,故对内存也做了映射,方便用户使用。下面先以内核2.6.28为例来先来看一下Linux中这个内存地址的由来。

首先看启动代码代码arch/arm/kernel/head.S

 29 #define KERNEL_RAM_VADDR        (PAGE_OFFSET + TEXT_OFFSET)//定义虚拟内存首地址
30 #define KERNEL_RAM_PADDR        (PHYS_OFFSET + TEXT_OFFSET)//定义实际物理内存地址

PAGE_OFFSET的出处

代码arch/arm/include/asm/memory.c

27 #ifdef CONFIG_MMU
28
29 /*
30 * PAGE_OFFSET - the virtual address of the start of the kernel image
31 * TASK_SIZE - the maximum size of a user space task.
32 * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
33 */
34 #define PAGE_OFFSET             UL(CONFIG_PAGE_OFFSET)

代码include/linux/autoconf.h

#define CONFIG_PAGE_OFFSET 0xc0000000

PHYS_OFFSET 的出处

代码 arch/arm/mach-s3c6400/include/mach/memory.h //与6400平台相关的内存设置

#define PHYS_OFFSET UL(0x50000000)

TEXT_OFFSET的定义在arch/arm/Makefile中,这个值是内核所在位置的实际偏移量,具体对这个值的说明看文件arch/arm/kernel/head.S。


 38 /*
39  * swapper_pg_dir is the virtual address of the initial page table.
40  * We place the page tables 16K below KERNEL_RAM_ADDR.  Therefore, we must
41  * make sure that KERNEL_RAM_ADDR is correctly set.  Currently, we expect
42  * the least significant 16 bits to be 0x8000, but we could probably
43  * relax this restriction to KERNEL_RAM_ADDR >= PAGE_OFFSET + 0x4000.
44  */

也就是说,从地址KERNEL_RAM_VADDR 开始的至少0x4000用来存放内核页表,而存放内核页表的空间值建议是0x8000。