搜索内存,找到RSDP

源码摘自grub2。

acpi的rsdp保存在bios扩展数据区域或地址0xe0000~0xfffff区域内,通过搜索这两个地址区域找到rsdp。

struct acpi_rsdp_v10 *

machine_acpi_get_rsdpv1 (void)
{
    int ebda_len;
    uint8_t *ebda, *ptr;

    printf ("acpi:Looking for RSDP. Scanning EBDA\n");
    ebda = (uint8_t *) ((* ((uint16_t *) 0x40e)) << 4);
    ebda_len = * (uint16_t *) ebda;
    if (! ebda_len)
    return 0;
    for (ptr = ebda; ptr < ebda + 0x400; ptr += 16)
    if (memcmp (ptr, "RSD PTR ", 8) == 0
            && byte_checksum (ptr, sizeof (struct acpi_rsdp_v10)) == 0
            && ((struct acpi_rsdp_v10 *) ptr)->revision == 0)
    return (struct acpi_rsdp_v10 *) ptr;

    printf ("acpi:Looking for RSDP. Scanning BIOS\n");
    for (ptr = (uint8_t *) 0xe0000; ptr < (uint8_t *) 0x100000;
    ptr += 16)
    if (memcmp (ptr, "RSD PTR ", 8) == 0
            && byte_checksum (ptr, sizeof (struct acpi_rsdp_v10)) == 0
            && ((struct acpi_rsdp_v10 *) ptr)->revision == 0)
    return (struct acpi_rsdp_v10 *) ptr;
    return 0;
}

struct acpi_rsdp_v20 *
machine_acpi_get_rsdpv2 (void)
{
    int ebda_len;
    uint8_t *ebda, *ptr;

    printf ("acpi:Looking for RSDP. Scanning EBDA\n");
    ebda = (uint8_t *) ((* ((uint16_t *) 0x40e)) << 4);
    ebda_len = * (uint16_t *) ebda;
    if (! ebda_len)
    return 0;
    for (ptr = ebda; ptr < ebda + 0x400; ptr += 16)
    if (memcmp (ptr, "RSD PTR ", 8) == 0
            && byte_checksum (ptr, sizeof (struct acpi_rsdp_v10)) == 0
            && ((struct acpi_rsdp_v10 *) ptr)->revision != 0
            && ((struct acpi_rsdp_v20 *) ptr)->length < 1024
            && byte_checksum (ptr, ((struct acpi_rsdp_v20 *) ptr)->length)
            == 0)
    return (struct acpi_rsdp_v20 *) ptr;

    printf ("acpi:Looking for RSDP. Scanning BIOS\n");
    for (ptr = (uint8_t *) 0xe0000; ptr < (uint8_t *) 0x100000;
    ptr += 16)
    if (memcmp (ptr, "RSD PTR ", 8) == 0
            && byte_checksum (ptr, sizeof (struct acpi_rsdp_v10)) == 0
            && ((struct acpi_rsdp_v10 *) ptr)->revision != 0
            && ((struct acpi_rsdp_v20 *) ptr)->length < 1024
            && byte_checksum (ptr, ((struct acpi_rsdp_v20 *) ptr)->length)
            == 0)
    return (struct acpi_rsdp_v20 *) ptr;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值