From afef2c845b93ebe52c178a5a42d498be75fb4c8c Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 21 May 2009 16:03:15 -0700 Subject: Drop support for ACPI 3 E820 extended memory attributes Drop all support for ACPI 3 E820 extended memory attributes. There are BIOSes in the field that report completely bogus information here, resulting in no memory at all being detected (we then fall back to E801 detection, but that is problematic in its own ways.) There is strong reasons to believe at this point that the extended memory attributes are not usable in their current form, so drop them and revert back to simple 20-byte support, including for MEMDISK spoofing. Signed-off-by: H. Peter Anvin --- memdisk/e820.h | 3 +-- memdisk/e820func.c | 21 ++++++--------------- memdisk/e820test.c | 13 ++++++------- memdisk/memdisk.inc | 20 +++++++------------- memdisk/msetup.c | 22 +++++++--------------- memdisk/setup.c | 6 ++---- 6 files changed, 29 insertions(+), 56 deletions(-) (limited to 'memdisk') diff --git a/memdisk/e820.h b/memdisk/e820.h index 429b98c2..04b44484 100644 --- a/memdisk/e820.h +++ b/memdisk/e820.h @@ -21,7 +21,6 @@ struct e820range { uint64_t start; uint32_t type; - uint32_t extattr; } __attribute__((packed)); extern struct e820range ranges[]; @@ -29,6 +28,6 @@ extern int nranges; extern uint32_t dos_mem, low_mem, high_mem; extern void e820map_init(void); -extern void insertrange(uint64_t, uint64_t, uint32_t, uint32_t); +extern void insertrange(uint64_t, uint64_t, uint32_t); extern void get_mem(void); extern void parse_mem(void); diff --git a/memdisk/e820func.c b/memdisk/e820func.c index ccfc38ea..80471a9b 100644 --- a/memdisk/e820func.c +++ b/memdisk/e820func.c @@ -37,8 +37,7 @@ void e820map_init(void) ranges[1].type = -1U; } -static void insertrange_at(int where, uint64_t start, - uint32_t type, uint32_t extattr) +static void insertrange_at(int where, uint64_t start, uint32_t type) { int i; @@ -47,18 +46,16 @@ static void insertrange_at(int where, uint64_t start, ranges[where].start = start; ranges[where].type = type; - ranges[where].extattr = extattr; nranges++; ranges[nranges].start = 0ULL; ranges[nranges].type = -1U; - ranges[nranges].extattr = 0; } -void insertrange(uint64_t start, uint64_t len, uint32_t type, uint32_t extattr) +void insertrange(uint64_t start, uint64_t len, uint32_t type) { uint64_t last; - uint32_t oldtype, oldattr; + uint32_t oldtype; int i, j; /* Remove this to make len == 0 mean all of memory */ @@ -69,40 +66,34 @@ void insertrange(uint64_t start, uint64_t len, uint32_t type, uint32_t extattr) i = 0; oldtype = -2U; - oldattr = 0; while ( start > ranges[i].start && ranges[i].type != -1U ) { oldtype = ranges[i].type; - oldattr = ranges[i].extattr; i++; } /* Consider the replacement policy. This current one is "overwrite." */ if ( start < ranges[i].start || ranges[i].type == -1U ) - insertrange_at(i++, start, type, extattr); + insertrange_at(i++, start, type); while ( i == 0 || last > ranges[i].start-1 ) { oldtype = ranges[i].type; - oldattr = ranges[i].extattr; ranges[i].type = type; - ranges[i].extattr = extattr; i++; } if ( last < ranges[i].start-1 ) - insertrange_at(i, last+1, oldtype, oldattr); + insertrange_at(i, last+1, oldtype); /* Now the map is correct, but quite possibly not optimal. Scan the map for ranges which are redundant and remove them. */ i = j = 1; oldtype = ranges[0].type; - oldattr = ranges[0].extattr; while ( i < nranges ) { - if ( ranges[i].type == oldtype && ranges[i].extattr == oldattr ) { + if ( ranges[i].type == oldtype ) { i++; } else { oldtype = ranges[i].type; - oldattr = ranges[i].extattr; if ( i != j ) ranges[j] = ranges[i]; i++; j++; diff --git a/memdisk/e820test.c b/memdisk/e820test.c index 41fee007..2de7fd4e 100644 --- a/memdisk/e820test.c +++ b/memdisk/e820test.c @@ -36,17 +36,17 @@ void printranges(void) { int i; for ( i = 0 ; i < nranges ; i++ ) { - printf("%016llx %016llx %d %x\n", + printf("%016llx %016llx %d\n", ranges[i].start, ranges[i+1].start - ranges[i].start, - ranges[i].type, ranges[i].extattr); + ranges[i].type); } } int main(void) { uint64_t start, len; - uint32_t type, extattr; + uint32_t type; char line[BUFSIZ], *p; e820map_init(); @@ -55,12 +55,11 @@ int main(void) while ( fgets(line, BUFSIZ, stdin) ) { p = strchr(line, ':'); p = p ? p+1 : line; - extattr = 1; - if ( sscanf(p, " %llx %llx %d %x", &start, &len, &type, &extattr) >= 3 ) { + if ( sscanf(p, " %llx %llx %d", &start, &len, &type) == 3 ) { putchar('\n'); - printf("%016llx %016llx %d %x <-\n", start, len, type, extattr); + printf("%016llx %016llx %d <-\n", start, len, type); putchar('\n'); - insertrange(start, len, type, extattr); + insertrange(start, len, type); printranges(); } } diff --git a/memdisk/memdisk.inc b/memdisk/memdisk.inc index fa4fe3e5..00537a83 100644 --- a/memdisk/memdisk.inc +++ b/memdisk/memdisk.inc @@ -540,26 +540,19 @@ int15_e820: jne .renew mov ebx,E820Table .renew: - add bx,16 ; Advance to next - mov eax,[bx-8] ; Type + add bx,12 ; Advance to next + mov eax,[bx-4] ; Type and eax,eax ; Null type? jz .renew ; If so advance to next mov [es:di+16],eax - and cl,~3 - cmp ecx,24 - jb .no_extattr - mov eax,[bx-4] ; Extended attributes - mov [es:di+20],eax - mov ecx,24 ; Bytes loaded -.no_extattr: - mov eax,[bx-16] ; Start addr (low) - mov edx,[bx-12] ; Start addr (high) + mov eax,[bx-12] ; Start addr (low) + mov edx,[bx-8] ; Start addr (high) mov [es:di],eax mov [es:di+4],edx mov eax,[bx] ; End addr (low) mov edx,[bx+4] ; End addr (high) - sub eax,[bx-16] ; Derive the length - sbb edx,[bx-12] + sub eax,[bx-12] ; Derive the length + sbb edx,[bx-8] mov [es:di+8],eax ; Length (low) mov [es:di+12],edx ; Length (high) cmp dword [bx+8],-1 ; Type of next = end? @@ -568,6 +561,7 @@ int15_e820: .notdone: pop eax ; "SMAP" mov edx,eax ; Some systems expect eax = edx = SMAP + mov ecx,20 ; Bytes loaded pop ds int15_success: mov byte [bp+6], 02h ; Clear CF diff --git a/memdisk/msetup.c b/memdisk/msetup.c index a2067011..e5111174 100644 --- a/memdisk/msetup.c +++ b/memdisk/msetup.c @@ -38,7 +38,6 @@ static inline int get_e820(void) uint64_t base; uint64_t len; uint32_t type; - uint32_t extattr; } *buf = sys_bounce; uint32_t copied; int range_count = 0; @@ -46,7 +45,6 @@ static inline int get_e820(void) memset(®s, 0, sizeof regs); memset(buf, 0, sizeof *buf); - buf->extattr = 1; do { regs.eax.l = 0x0000e820; @@ -61,18 +59,12 @@ static inline int get_e820(void) if ( regs.eax.l != 0x534d4150 || copied < 20 ) break; - if ( copied < 24 ) - buf->extattr = 1; - - printf("e820: %08x%08x %08x%08x %d [%x]\n", + printf("e820: %08x%08x %08x%08x %d\n", (uint32_t)(buf->base >> 32), (uint32_t)buf->base, (uint32_t)(buf->len >> 32), (uint32_t)buf->len, - buf->type, buf->extattr); - - if ( !(buf->extattr & 1) ) - continue; /* Disabled range, just ignore */ + buf->type); - insertrange(buf->base, buf->len, buf->type, buf->extattr); + insertrange(buf->base, buf->len, buf->type); range_count++; } while ( regs.ebx.l ); @@ -86,7 +78,7 @@ static inline void get_dos_mem(void) memset(®s, 0, sizeof regs); syscall(0x12, ®s, ®s); - insertrange(0, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1, 1); + insertrange(0, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1); printf(" DOS: %d K\n", regs.eax.w[0]); } @@ -102,10 +94,10 @@ static inline int get_e801(void) if ( !(err = regs.eflags.l & 1) ) { if ( regs.eax.w[0] ) { - insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1, 1); + insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1); } if ( regs.ebx.w[0] ) { - insertrange(0x1000000, (uint64_t)((uint32_t)regs.ebx.w[0] << 16), 1, 1); + insertrange(0x1000000, (uint64_t)((uint32_t)regs.ebx.w[0] << 16), 1); } printf("e801: %04x %04x\n", regs.eax.w[0], regs.ebx.w[0]); @@ -127,7 +119,7 @@ static inline int get_88(void) if ( !(err = regs.eflags.l & 1) ) { if ( regs.eax.w[0] ) { - insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1, 1); + insertrange(0x100000, (uint64_t)((uint32_t)regs.eax.w[0] << 10), 1); } printf(" 88: %04x\n", regs.eax.w[0]); diff --git a/memdisk/setup.c b/memdisk/setup.c index 61f9bfb5..94a80113 100644 --- a/memdisk/setup.c +++ b/memdisk/setup.c @@ -295,8 +295,6 @@ void unzip_if_needed(uint32_t *where_p, uint32_t *size_p) /* Must be memory */ if ( ranges[i].type != 1 ) continue; - if (!(ranges[i].extattr & 1)) - continue; /* Range start */ if ( ranges[i].start >= 0xFFFFFFFF ) @@ -752,7 +750,7 @@ __cdecl void setup(__cdecl syscall_t cs_syscall, void *cs_bounce) } /* Reserve the ramdisk memory */ - insertrange(ramdisk_image, ramdisk_size, 2, 1); + insertrange(ramdisk_image, ramdisk_size, 2); parse_mem(); /* Recompute variables */ /* Figure out where it needs to go */ @@ -896,7 +894,7 @@ __cdecl void setup(__cdecl syscall_t cs_syscall, void *cs_bounce) /* Reserve this range of memory */ wrz_16(BIOS_BASEMEM, driveraddr >> 10); - insertrange(driveraddr, dos_mem-driveraddr, 2, 1); + insertrange(driveraddr, dos_mem-driveraddr, 2); parse_mem(); pptr->mem1mb = low_mem >> 10; -- cgit v1.2.1