start_kernel->setup_arch->paging_init->memtable_init

/*
* Setup initial mappings.  We use the page we allocated for zero page to hold
* the mappings, which will get overwritten by the vectors in traps_init().
* The mappings must be in virtual address order.
*/
void __init memtable_init(struct meminfo *mi)
{
    struct map_desc *init_maps, *p, *q;
    unsigned long address = 0;
    int i;

    build_mem_type_table();

[I48{)I{`RA9C7A(~S`FA9S

    init_maps = p = alloc_bootmem_low_pages(PAGE_SIZE);

#ifdef CONFIG_XIP_KERNEL
    p->physical   = CONFIG_XIP_PHYS_ADDR & PMD_MASK;
    p->virtual    = (unsigned long)&_stext & PMD_MASK;
    p->length     = ((unsigned long)&_etext - p->virtual + ~PMD_MASK) & PMD_MASK;
    p->type       = MT_ROM;
    p ++;
#endif

    for (i = 0; i < mi->nr_banks; i++) {
        if (mi->bank[i].size == 0)
            continue;

        p->physical   = mi->bank[i].start;                         // 0x3000 0000
        p->virtual    = __phys_to_virt(p->physical);         // 0xc000 0000
        p->length     = mi->bank[i].size;                           // 0x400 0000
        p->type       = MT_MEMORY;
        p ++;
    }

#ifdef FLUSH_BASE
    p->physical   = FLUSH_BASE_PHYS;
    p->virtual    = FLUSH_BASE;
    p->length     = PGDIR_SIZE;
    p->type       = MT_CACHECLEAN;
    p ++;
#endif

#ifdef FLUSH_BASE_MINICACHE
    p->physical   = FLUSH_BASE_PHYS + PGDIR_SIZE;
    p->virtual    = FLUSH_BASE_MINICACHE;
    p->length     = PGDIR_SIZE;
    p->type       = MT_MINICLEAN;
    p ++;
#endif

    /*
     * Go through the initial mappings, but clear out any
     * pgdir entries that are not in the description.
     */
    q = init_maps;
    do {
        if (address < q->virtual || q == p) {
            clear_mapping(address);                                                  //清除虚拟物理地址映射
            address += PGDIR_SIZE;
        } else {
            create_mapping(q);                                                           //创建虚拟物理地址映射

            address = q->virtual + q->length;
            address = (address + PGDIR_SIZE - 1) & PGDIR_MASK;

            q ++;
        }
    } while (address != 0);

    /*
     * Create a mapping for the machine vectors at the high-vectors
     * location (0xffff0000).  If we aren't using high-vectors, also
     * create a mapping at the low-vectors virtual address.
     */
    init_maps->physical   = virt_to_phys(init_maps);
    init_maps->virtual    = 0xffff0000;
    init_maps->length     = PAGE_SIZE;
    init_maps->type       = MT_HIGH_VECTORS;
    create_mapping(init_maps);                                                   //创建高端向量表的虚拟物理地址映射

    if (!vectors_high()) {
        init_maps->virtual = 0;
        init_maps->type = MT_LOW_VECTORS;
        create_mapping(init_maps);                                            

    }

    flush_cache_all();
    local_flush_tlb_all();

    top_pmd = pmd_off_k(0xffff0000);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值