# HG changeset patch # User Pascal Bellard # Date 1333453502 -7200 # Node ID d64d0a05e4320b1d34204c59b37e449f3e435313 # Parent 188ed036ce843f6b8fd7c28f4ef95c51ab130885 syslinux/ifmem.c32: shrink diff -r 188ed036ce84 -r d64d0a05e432 syslinux/stuff/extra/ifmem.c --- a/syslinux/stuff/extra/ifmem.c Tue Apr 03 13:12:44 2012 +0200 +++ b/syslinux/stuff/extra/ifmem.c Tue Apr 03 13:45:02 2012 +0200 @@ -40,92 +40,88 @@ #include struct e820_data { - uint64_t base; - uint64_t len; - uint32_t type; - uint32_t extattr; + uint64_t base; + uint64_t len; + uint32_t type; + uint32_t extattr; } __attribute__((packed)); // Get memory size in Kb static unsigned long memory_size(void) { - uint64_t bytes = 0; - com32sys_t ireg, oreg; - struct e820_data ed; + uint64_t bytes = 0; + static com32sys_t ireg, oreg; + static struct e820_data ed; - memset(&ireg, 0, sizeof ireg); + ireg.eax.w[0] = 0xe820; + ireg.edx.l = 0x534d4150; + ireg.ecx.l = sizeof(struct e820_data); + ireg.edi.w[0] = OFFS(__com32.cs_bounce); + ireg.es = SEG(__com32.cs_bounce); - ireg.eax.w[0] = 0xe820; - ireg.edx.l = 0x534d4150; - ireg.ecx.l = sizeof(struct e820_data); - ireg.edi.w[0] = OFFS(__com32.cs_bounce); - ireg.es = SEG(__com32.cs_bounce); + ed.extattr = 1; - memset(&ed, 0, sizeof ed); - ed.extattr = 1; + do { + memcpy(__com32.cs_bounce, &ed, sizeof ed); - do { - memcpy(__com32.cs_bounce, &ed, sizeof ed); + __intcall(0x15, &ireg, &oreg); + if (oreg.eflags.l & EFLAGS_CF || + oreg.eax.l != 0x534d4150 || + oreg.ecx.l < 20) + break; - __intcall(0x15, &ireg, &oreg); - if (oreg.eflags.l & EFLAGS_CF || - oreg.eax.l != 0x534d4150 || - oreg.ecx.l < 20) - break; + memcpy(&ed, __com32.cs_bounce, sizeof ed); - memcpy(&ed, __com32.cs_bounce, sizeof ed); + if (ed.type == 1) + bytes += ed.len; - if (ed.type == 1) - bytes += ed.len; + ireg.ebx.l = oreg.ebx.l; + } while (ireg.ebx.l); - ireg.ebx.l = oreg.ebx.l; - } while (ireg.ebx.l); - - if (!bytes) { - memset(&ireg, 0, sizeof ireg); - ireg.eax.w[0] = 0x8800; - __intcall(0x15, &ireg, &oreg); - return ireg.eax.w[0]; - } - return bytes >> 10; + if (!bytes) { + memset(&ireg, 0, sizeof ireg); + ireg.eax.w[0] = 0x8800; + __intcall(0x15, &ireg, &oreg); + return ireg.eax.w[0]; + } + return bytes >> 10; } int main(int argc, char *argv[]) { - char *s; - int i; - unsigned long ram_size; + int i; + unsigned long ram_size; - openconsole(&dev_null_r, &dev_stdcon_w); + openconsole(&dev_null_r, &dev_stdcon_w); - if (argc < 4) { - perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n"); - return 1; - } + if (argc < 4) { + perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n"); + return 1; + } - // find target according to ram size - ram_size = memory_size(); - printf("Total memory found %luK.\n",ram_size); - ram_size += (1 << 10); // add 1M to round boundaries... + // find target according to ram size + ram_size = memory_size(); + printf("Total memory found %luK.\n",ram_size); + ram_size += (1 << 10); // add 1M to round boundaries... - i = 1; - s = argv[1]; - do { - char *p = s; - unsigned long scale = 1; - - while (*p >= '0' && *p <= '9') p++; - switch (*p | 0x20) { - case 'g': scale <<= 10; - case 'm': scale <<= 10; - default : *p = 0; break; - } - i++; // size - if (ram_size >= scale * strtoul(s, NULL, 0)) break; - s = argv[++i]; - } while (i + 1 < argc); + i = 1; + do { + char *s = argv[i]; + char *p = s; + unsigned long scale = 1; - if (i != argc) syslinux_run_command(argv[i]); - else syslinux_run_default(); - return -1; + while (*p >= '0' && *p <= '9') p++; + switch (*p | 0x20) { + case 'g': scale <<= 10; + case 'm': scale <<= 10; + default : *p = 0; break; + } + i++; // seek to label + if (ram_size >= scale * strtoul(s, NULL, 0)) break; + i++; // next size or default label + } while (i + 1 < argc); + + if (i != argc) syslinux_run_command(argv[i]); + else syslinux_run_default(); + return -1; }