使用 BIOS int 0x15/E820 查看内存映射

Using BIOS int 0x15/E820 to view the memory map

我正在 x86 上进行一些裸机编程。我处于 16 位模式,我使用 qemu 进行模拟......我使用 int 0x15/ax = 0xE820 查看内存映射......使用 qemu 监视器(检查我写映射的区域)我得到以下信息关于内存映射:

Start=0 Length= 0x9fc00 (type 1)
Start=0x9fc00 Length= 0x400 (type 2) 
Start=0xf0000 Length= 0x10000 (type 2)
Start=0x100000 Length= 0x7ee0000 (type 1)
Start=0x7fe0000 Length= 0x10000 (type 2)
Start=0xfffc0000 Length = 0x40000 (Type 2)

那么,不在这个映射中的段(例如 0xA0000)是否属于 MMIO 之类的东西?我知道 BIOS 等使用类型 2 内存区域(Start=0x9fc00 Length= 0x400(类型 2) 是 EDBA)当我写入这些区域时会发生什么?

注意:我没有类型 3(ACPI) 可能是因为我使用的是 qemu。在真正的硬件中,我很可能也应该获得类型 3 区域。那个内存也是吗?

这个 BIOS 调用在 INT 15h, AX=E820h - Query System Address Map, 在 "Assumptions and Limitations":

部分中注明的位置
  1. The BIOS will return address ranges describing base board memory and ISA or PCI memory that is contiguous with that baseboard memory.
  2. The BIOS WILL NOT return a range description for the memory mapping of PCI devices, ISA Option ROM's, and ISA plug & play cards. This is because the OS has mechanisms available to detect them.
  3. The BIOS will return chipset defined address holes that are not being used by devices as reserved.
  4. Address ranges defined for base board memory mapped I/O devices (for example APICs) will be returned as reserved.
  5. All occurrences of the system BIOS will be mapped as reserved. This includes the area below 1 MB, at 16 MB (if present) and at end of the address space (4 gig).
  6. Standard PC address ranges will not be reported. Example video memory at A0000 to BFFFF physical will not be described by this function. The range from E0000 to EFFFF is base board specific and will be reported as suits the bas board.
  7. All of lower memory is reported as normal memory. It is OS's responsibility to handle standard RAM locations reserved for specific uses, for example: the interrupt vector table(0:0) and the BIOS data area(40:0).

维基百科文章 Detecting Memory (x86) 在其部分添加 "BIOS Function: INT 0x15, EAX = 0xE820" 添加以下规则:

  • After getting the list, it may be desirable to: sort the list, combine adjacent ranges of the same type, change any overlapping areas to the most restrictive type, and change any unrecognised "type" values to type 2.
  • Type 3 "ACPI reclaimable" memory regions may be used like (and combined with) normal "available RAM" areas as long as you're finished using the ACPI tables that are stored there (i.e. it can be "reclaimed").
  • Types 2, 4, 5 (reserved, ACPI non-volatile, bad) mark areas that should be avoided when you are allocating physical memory.
  • Treat unlisted regions as Type 2 -- reserved.
  • Your code must be able to handle areas that don't start or end on any sort of "page boundary".

结论:地图中未找到的范围是功能性的, 可能被视频等设备内存占用了