aboutsummaryrefslogtreecommitdiffstats
path: root/src/memmap.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2009-02-27 20:19:27 -0500
committerKevin O'Connor <kevin@koconnor.net>2009-02-27 20:19:27 -0500
commit5d8ec3ee06686179f157c609e3fd053fc1c5c6b1 (patch)
tree83f0c34f4fe59106f8e6a6e1de362fa398d53a74 /src/memmap.c
parent9caf78634dd5e95611e222b047e60957fd2a22ce (diff)
downloadseabios-5d8ec3ee06686179f157c609e3fd053fc1c5c6b1.tar.gz
Minor - simplify add_e820() function.
Make code a little simpler. This also fixes a corner-case where a hole could be incorrectly added to the map.
Diffstat (limited to 'src/memmap.c')
-rw-r--r--src/memmap.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/src/memmap.c b/src/memmap.c
index c56f6f55..5b7eba5f 100644
--- a/src/memmap.c
+++ b/src/memmap.c
@@ -62,18 +62,15 @@ add_e820(u64 start, u64 size, u32 type)
// Huh? Nothing to do.
return;
+ // Find position of new item (splitting existing item if needed).
u64 end = start + size;
int i;
for (i=0; i<e820_count; i++) {
struct e820entry *e = &e820_list[i];
- if (end < e->start)
- // Simple insertion point.
- break;
u64 e_end = e->start + e->size;
if (start > e_end)
- // No overlap.
continue;
- // New item overlaps (or borders) an existing one.
+ // Found position - check if an existing item needs to be split.
if (start > e->start) {
e->size = start - e->start;
i++;
@@ -88,37 +85,35 @@ add_e820(u64 start, u64 size, u32 type)
remove_e820(i);
}
}
- if (type != E820_HOLE) {
- insert_e820(i, start, size, type);
- i++;
- }
- // Remove all existing items that are completely overlapped.
- while (i<e820_count) {
- e = &e820_list[i];
- if (end < e->start)
- // No overlap - done.
- break;
- e_end = e->start + e->size;
- if (end >= e_end) {
- // Existing item completely overlapped - remove it.
- remove_e820(i);
- continue;
- }
- // Not completely overlapped - adjust its start.
- e->start = end;
- e->size = e_end - e->start;
- if (type == e->type) {
- // Same type - merge them.
- (e-1)->size += e->size;
- remove_e820(i);
- }
+ break;
+ }
+ // Insert new item.
+ if (type != E820_HOLE) {
+ insert_e820(i, start, size, type);
+ i++;
+ }
+ // Remove/adjust existing items that are overlapping.
+ while (i<e820_count) {
+ struct e820entry *e = &e820_list[i];
+ if (end < e->start)
+ // No overlap - done.
break;
+ u64 e_end = e->start + e->size;
+ if (end >= e_end) {
+ // Existing item completely overlapped - remove it.
+ remove_e820(i);
+ continue;
}
- //dump_map();
- return;
+ // Not completely overlapped - adjust its start.
+ e->start = end;
+ e->size = e_end - e->start;
+ if (type == e->type) {
+ // Same type - merge them.
+ (e-1)->size += e->size;
+ remove_e820(i);
+ }
+ break;
}
- // Just insert item.
- insert_e820(i, start, size, type);
//dump_map();
}