浏览代码

[pcbios] Merge adjacent memory regions of same type

Some BIOSes can report multiple memory regions which may be adjacent
and the same type.  Since only the first region is used in the
mboot.c32 layer it's possible to run out of memory when loading all of
the boot modules.  One may get around this problem by having iPXE
merge these memory regions internally.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Eduardo Habkost 13 年前
父节点
当前提交
3293eb8e73
共有 1 个文件被更改,包括 10 次插入2 次删除
  1. 10
    2
      src/arch/i386/firmware/pcbios/memmap.c

+ 10
- 2
src/arch/i386/firmware/pcbios/memmap.c 查看文件

@@ -156,6 +156,7 @@ unsigned int extmemsize ( void ) {
156 156
  */
157 157
 static int meme820 ( struct memory_map *memmap ) {
158 158
 	struct memory_region *region = memmap->regions;
159
+	struct memory_region *prev_region = NULL;
159 160
 	uint32_t next = 0;
160 161
 	uint32_t smap;
161 162
 	size_t size;
@@ -238,8 +239,15 @@ static int meme820 ( struct memory_map *memmap ) {
238 239
 
239 240
 		region->start = e820buf.start;
240 241
 		region->end = e820buf.start + e820buf.len;
241
-		region++;
242
-		memmap->count++;
242
+
243
+		/* Check for adjacent regions and merge them */
244
+		if ( prev_region && ( region->start == prev_region->end ) ) {
245
+			prev_region->end = region->end;
246
+		} else {
247
+			prev_region = region;
248
+			region++;
249
+			memmap->count++;
250
+		}
243 251
 
244 252
 		if ( memmap->count >= ( sizeof ( memmap->regions ) /
245 253
 					sizeof ( memmap->regions[0] ) ) ) {

正在加载...
取消
保存