Linux如何映射物理内存到内核空间

在setup_arch()中:
 
1. parse_cmdline(): 根据uboot传递的mem信息,调用early_mem()通过arm_add_memory()把物理内存信息添加到meminfo结构体中。
 
2. paging_init(): 这个就是关键的初始化页表的函数,在里面会调用bootmem_init()->bootmem_init_node()->map_memory_bank(),在这里会根据meminfo的信息调用create_mapping()来为物理内存建立内核空间的映射,一般是从0xc0000000开始。下面是arm linux的虚拟地址映射表:
 
Start       End     Use
--------------------------------------------------------------------------
ffff8000 ffffffff   copy_user_page / clear_user_page use.
ffff1000 ffff7fff   Reserved.
    
ffff0000 ffff0fff CPU vector page.
    The CPU vectors are mapped here if the  CPU supports vector relocation (control
    register V bit.)
 
ffc00000 fffeffff DMA memory mapping region.  Memory returned by the dma_alloc_xxx functions will be dynamically mapped here.
 
ff000000 ffbfffff Reserved for future expansion of DMA mapping region.
 
VMALLOC_END feffffff Free for platform use, recommended.
    VMALLOC_END must be aligned to a 2MB
    boundary.
 
VMALLOC_START VMALLOC_END-1 vmalloc() / ioremap() space.
    Memory returned by vmalloc/ioremap will
    be dynamically placed in this region.
    VMALLOC_START may be based upon the value
    of the high_memory variable.
 
PAGE_OFFSET high_memory-1 Kernel direct-mapped RAM region.
    This maps the platforms RAM, and typically
    maps all platform RAM in a 1:1 relationship.
 
TASK_SIZE PAGE_OFFSET-1 Kernel module space
    Kernel modules inserted via insmod are
    placed here using dynamic mappings.
 
00001000 TASK_SIZE-1 User space mappings
    Per-thread mappings are placed here via
    the mmap() system call.
 
00000000 00000fff CPU vector page / null pointer trap
    CPUs which do not support vector remapping
    place their vector page here.  NULL pointer
    dereferences by both the kernel and user
    space are also caught via this mapping.
虽然后面这个表我不知道什么意思,但是上面的对我还是蛮有用的,至少我知道了,物理内存是如何映射到内核空间的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值