wok rev 12216
syslinux/ifmem.c32: shrink
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Apr 03 13:45:02 2012 +0200 (2012-04-03) |
parents | 188ed036ce84 |
children | ebf5ca08edd3 |
files | syslinux/stuff/extra/ifmem.c |
line diff
1.1 --- a/syslinux/stuff/extra/ifmem.c Tue Apr 03 13:12:44 2012 +0200 1.2 +++ b/syslinux/stuff/extra/ifmem.c Tue Apr 03 13:45:02 2012 +0200 1.3 @@ -40,92 +40,88 @@ 1.4 #include <syslinux/boot.h> 1.5 1.6 struct e820_data { 1.7 - uint64_t base; 1.8 - uint64_t len; 1.9 - uint32_t type; 1.10 - uint32_t extattr; 1.11 + uint64_t base; 1.12 + uint64_t len; 1.13 + uint32_t type; 1.14 + uint32_t extattr; 1.15 } __attribute__((packed)); 1.16 1.17 // Get memory size in Kb 1.18 static unsigned long memory_size(void) 1.19 { 1.20 - uint64_t bytes = 0; 1.21 - com32sys_t ireg, oreg; 1.22 - struct e820_data ed; 1.23 + uint64_t bytes = 0; 1.24 + static com32sys_t ireg, oreg; 1.25 + static struct e820_data ed; 1.26 1.27 - memset(&ireg, 0, sizeof ireg); 1.28 + ireg.eax.w[0] = 0xe820; 1.29 + ireg.edx.l = 0x534d4150; 1.30 + ireg.ecx.l = sizeof(struct e820_data); 1.31 + ireg.edi.w[0] = OFFS(__com32.cs_bounce); 1.32 + ireg.es = SEG(__com32.cs_bounce); 1.33 1.34 - ireg.eax.w[0] = 0xe820; 1.35 - ireg.edx.l = 0x534d4150; 1.36 - ireg.ecx.l = sizeof(struct e820_data); 1.37 - ireg.edi.w[0] = OFFS(__com32.cs_bounce); 1.38 - ireg.es = SEG(__com32.cs_bounce); 1.39 + ed.extattr = 1; 1.40 1.41 - memset(&ed, 0, sizeof ed); 1.42 - ed.extattr = 1; 1.43 + do { 1.44 + memcpy(__com32.cs_bounce, &ed, sizeof ed); 1.45 1.46 - do { 1.47 - memcpy(__com32.cs_bounce, &ed, sizeof ed); 1.48 + __intcall(0x15, &ireg, &oreg); 1.49 + if (oreg.eflags.l & EFLAGS_CF || 1.50 + oreg.eax.l != 0x534d4150 || 1.51 + oreg.ecx.l < 20) 1.52 + break; 1.53 1.54 - __intcall(0x15, &ireg, &oreg); 1.55 - if (oreg.eflags.l & EFLAGS_CF || 1.56 - oreg.eax.l != 0x534d4150 || 1.57 - oreg.ecx.l < 20) 1.58 - break; 1.59 + memcpy(&ed, __com32.cs_bounce, sizeof ed); 1.60 1.61 - memcpy(&ed, __com32.cs_bounce, sizeof ed); 1.62 + if (ed.type == 1) 1.63 + bytes += ed.len; 1.64 1.65 - if (ed.type == 1) 1.66 - bytes += ed.len; 1.67 + ireg.ebx.l = oreg.ebx.l; 1.68 + } while (ireg.ebx.l); 1.69 1.70 - ireg.ebx.l = oreg.ebx.l; 1.71 - } while (ireg.ebx.l); 1.72 - 1.73 - if (!bytes) { 1.74 - memset(&ireg, 0, sizeof ireg); 1.75 - ireg.eax.w[0] = 0x8800; 1.76 - __intcall(0x15, &ireg, &oreg); 1.77 - return ireg.eax.w[0]; 1.78 - } 1.79 - return bytes >> 10; 1.80 + if (!bytes) { 1.81 + memset(&ireg, 0, sizeof ireg); 1.82 + ireg.eax.w[0] = 0x8800; 1.83 + __intcall(0x15, &ireg, &oreg); 1.84 + return ireg.eax.w[0]; 1.85 + } 1.86 + return bytes >> 10; 1.87 } 1.88 1.89 int main(int argc, char *argv[]) 1.90 { 1.91 - char *s; 1.92 - int i; 1.93 - unsigned long ram_size; 1.94 + int i; 1.95 + unsigned long ram_size; 1.96 1.97 - openconsole(&dev_null_r, &dev_stdcon_w); 1.98 + openconsole(&dev_null_r, &dev_stdcon_w); 1.99 1.100 - if (argc < 4) { 1.101 - perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n"); 1.102 - return 1; 1.103 - } 1.104 + if (argc < 4) { 1.105 + perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n"); 1.106 + return 1; 1.107 + } 1.108 1.109 - // find target according to ram size 1.110 - ram_size = memory_size(); 1.111 - printf("Total memory found %luK.\n",ram_size); 1.112 - ram_size += (1 << 10); // add 1M to round boundaries... 1.113 + // find target according to ram size 1.114 + ram_size = memory_size(); 1.115 + printf("Total memory found %luK.\n",ram_size); 1.116 + ram_size += (1 << 10); // add 1M to round boundaries... 1.117 1.118 - i = 1; 1.119 - s = argv[1]; 1.120 - do { 1.121 - char *p = s; 1.122 - unsigned long scale = 1; 1.123 - 1.124 - while (*p >= '0' && *p <= '9') p++; 1.125 - switch (*p | 0x20) { 1.126 - case 'g': scale <<= 10; 1.127 - case 'm': scale <<= 10; 1.128 - default : *p = 0; break; 1.129 - } 1.130 - i++; // size 1.131 - if (ram_size >= scale * strtoul(s, NULL, 0)) break; 1.132 - s = argv[++i]; 1.133 - } while (i + 1 < argc); 1.134 + i = 1; 1.135 + do { 1.136 + char *s = argv[i]; 1.137 + char *p = s; 1.138 + unsigned long scale = 1; 1.139 1.140 - if (i != argc) syslinux_run_command(argv[i]); 1.141 - else syslinux_run_default(); 1.142 - return -1; 1.143 + while (*p >= '0' && *p <= '9') p++; 1.144 + switch (*p | 0x20) { 1.145 + case 'g': scale <<= 10; 1.146 + case 'm': scale <<= 10; 1.147 + default : *p = 0; break; 1.148 + } 1.149 + i++; // seek to label 1.150 + if (ram_size >= scale * strtoul(s, NULL, 0)) break; 1.151 + i++; // next size or default label 1.152 + } while (i + 1 < argc); 1.153 + 1.154 + if (i != argc) syslinux_run_command(argv[i]); 1.155 + else syslinux_run_default(); 1.156 + return -1; 1.157 }