x86架构下的物理内存(2)

在linux中,内核启动的时候,在很早的阶段,内核调用detect_memory来通过bios探测内存,它又调用

detect_memory_e820来探测地址信息:

static int detect_memory_e820(void)
{
    int count = 0;
    struct biosregs ireg, oreg;
    struct e820entry *desc = boot_params.e820_map;
    static struct e820entry buf; /* static so it is zeroed */
    initregs(&ireg);
    ireg.ax  = 0xe820;
    ireg.cx  = sizeof buf;
    ireg.edx = SMAP;
    ireg.di  = (size_t)&buf;
    do {
        intcall(0x15, &ireg, &oreg); //调用bios中断
        ireg.ebx = oreg.ebx;
        if (oreg.eflags & X86_EFLAGS_CF)
            break;
        if (oreg.eax != SMAP) {
            count = 0;
            break;
        }
        *desc++ = buf;
        count++;
    } while (ireg.ebx && count < ARRAY_SIZE(boot_params.e820_map));
    return boot_params.e820_entries = count;
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/24773.html