wok view syslinux/stuff/extra/ifmem.c @ rev 3665

Up syslinux (3.82) + add ifmem.c32
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jul 10 10:50:27 2009 +0200 (2009-07-10)
parents
children 03b14f7eba36
line source
1 /* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2009 Pascal Bellard - All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
13 /*
14 * ifmem.c
15 *
16 * Run one command if the memory is large enought, and another if it isn't.
17 *
18 * Usage:
19 *
20 * label boot_kernel
21 * kernel ifmem.c
22 * append size_in_KB boot_large [size_in_KB boot_medium] boot_small
23 *
24 * label boot_large
25 * kernel vmlinuz_large_memory
26 * append ...
27 *
28 * label boot_small
29 * kernel vmlinuz_small_memory
30 * append ...
31 */
33 #include <inttypes.h>
34 #include <com32.h>
35 #include <console.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <alloca.h>
39 #include <stdlib.h>
40 #include <syslinux/boot.h>
42 static long memory_size(void)
43 {
44 com32sys_t ireg, oreg;
46 memset(&ireg, 0, sizeof ireg);
48 ireg.eax.w[0] = 0xe801;
49 __intcall(0x15, &ireg, &oreg);
51 return oreg.ecx.w[0] + ( oreg.edx.w[0] << 6);
52 }
54 int main(int argc, char *argv[])
55 {
56 char *s;
57 int i;
59 for (s = argv[1]; *s && (*s < '0' || *s > '9'); s++);
61 if (argc < 4 || !*s) {
62 openconsole(&dev_null_r, &dev_stdcon_w);
63 perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n");
64 return 1;
65 }
67 for (i = 1; i + 2 < argc; ) {
68 i++; // size
69 if (memory_size() >= strtoul(s, NULL, 0)) break;
70 s = argv[++i];
71 }
72 if (argv[i])
73 syslinux_run_command(argv[i]);
74 else
75 syslinux_run_default();
76 return -1;
77 }