summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2008-09-23 02:13:28 +0200
committerMichael Brown2008-09-23 02:13:28 +0200
commitca0b0f061673b27bb7bfa6f62e99385273c097da (patch)
treecf2c06b66558f8f85fbf69e37af1885f189c7d7e
parent[memmap] Allow for 4GB+ systems in debug message (diff)
downloadipxe-ca0b0f061673b27bb7bfa6f62e99385273c097da.tar.gz
ipxe-ca0b0f061673b27bb7bfa6f62e99385273c097da.tar.xz
ipxe-ca0b0f061673b27bb7bfa6f62e99385273c097da.zip
[relocate] Guard against systems that report empty memory regions
If the INT 15,e820 memory map reports a region [0,0), this confuses the "truncate to even megabytes" logic, which ends up rounding the region 'down' to [0,fff00000). Fix by ensuring that the region's end address is at least 1, before we subtract 1 to obtain the "last byte in region" address.
-rw-r--r--src/arch/i386/core/relocate.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/arch/i386/core/relocate.c b/src/arch/i386/core/relocate.c
index 39d00b09..aa58ad65 100644
--- a/src/arch/i386/core/relocate.c
+++ b/src/arch/i386/core/relocate.c
@@ -93,11 +93,16 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
/* If last byte that might be used (r_end-1)
* is in an odd megabyte, round down r_end to
* the top of the next even megabyte.
+ *
+ * Make sure that we don't accidentally wrap
+ * r_end below 0.
*/
- r_end = ( r_end - 1 ) & ~0xfffff;
- DBG ( "...end truncated to %lx "
- "(avoid ending in odd megabyte)\n",
- r_end );
+ if ( r_end >= 1 ) {
+ r_end = ( r_end - 1 ) & ~0xfffff;
+ DBG ( "...end truncated to %lx "
+ "(avoid ending in odd megabyte)\n",
+ r_end );
+ }
} else if ( ( r_end - size ) & 0x100000 ) {
/* If the last byte that might be used
* (r_end-1) is in an even megabyte, but the
@@ -108,7 +113,7 @@ __cdecl void relocate ( struct i386_all_regs *ix86 ) {
* Make sure that we don't accidentally wrap
* r_end below 0.
*/
- if ( r_end > 0x100000 ) {
+ if ( r_end >= 0x100000 ) {
r_end = ( r_end - 0x100000 ) & ~0xfffff;
DBG ( "...end truncated to %lx "
"(avoid starting in odd megabyte)\n",