wok diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/syslinux/stuff/extra/ifmem.c	Fri Jul 10 10:50:27 2009 +0200
     1.3 @@ -0,0 +1,77 @@
     1.4 +/* ----------------------------------------------------------------------- *
     1.5 + *
     1.6 + *   Copyright 2009 Pascal Bellard - All Rights Reserved
     1.7 + *
     1.8 + *   This program is free software; you can redistribute it and/or modify
     1.9 + *   it under the terms of the GNU General Public License as published by
    1.10 + *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
    1.11 + *   Boston MA 02110-1301, USA; either version 2 of the License, or
    1.12 + *   (at your option) any later version; incorporated herein by reference.
    1.13 + *
    1.14 + * ----------------------------------------------------------------------- */
    1.15 +
    1.16 +/*
    1.17 + * ifmem.c
    1.18 + *
    1.19 + * Run one command if the memory is large enought, and another if it isn't.
    1.20 + *
    1.21 + * Usage:
    1.22 + *
    1.23 + *    label boot_kernel
    1.24 + *        kernel ifmem.c
    1.25 + *        append size_in_KB boot_large [size_in_KB boot_medium] boot_small
    1.26 + *
    1.27 + *    label boot_large
    1.28 + *        kernel vmlinuz_large_memory
    1.29 + *        append ...
    1.30 + *
    1.31 + *    label boot_small
    1.32 + *        kernel vmlinuz_small_memory
    1.33 + *        append ...
    1.34 + */
    1.35 +
    1.36 +#include <inttypes.h>
    1.37 +#include <com32.h>
    1.38 +#include <console.h>
    1.39 +#include <stdio.h>
    1.40 +#include <string.h>
    1.41 +#include <alloca.h>
    1.42 +#include <stdlib.h>
    1.43 +#include <syslinux/boot.h>
    1.44 +
    1.45 +static long memory_size(void)
    1.46 +{
    1.47 +  com32sys_t ireg, oreg;
    1.48 +
    1.49 +  memset(&ireg, 0, sizeof ireg);
    1.50 +
    1.51 +  ireg.eax.w[0] = 0xe801;
    1.52 +  __intcall(0x15, &ireg, &oreg);
    1.53 +
    1.54 +  return  oreg.ecx.w[0] + ( oreg.edx.w[0] << 6);
    1.55 +}
    1.56 +
    1.57 +int main(int argc, char *argv[])
    1.58 +{
    1.59 +  char *s;
    1.60 +  int i;
    1.61 +
    1.62 +  for (s = argv[1]; *s && (*s < '0' || *s > '9'); s++);
    1.63 +
    1.64 +  if (argc < 4 || !*s) {
    1.65 +    openconsole(&dev_null_r, &dev_stdcon_w);
    1.66 +    perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n");
    1.67 +    return 1;
    1.68 +  }
    1.69 +
    1.70 +  for (i = 1; i + 2 < argc; ) { 
    1.71 +    i++; // size
    1.72 +    if (memory_size() >= strtoul(s, NULL, 0)) break;
    1.73 +    s = argv[++i];
    1.74 +  }
    1.75 +  if (argv[i])
    1.76 +    syslinux_run_command(argv[i]);
    1.77 +  else
    1.78 +    syslinux_run_default();
    1.79 +  return -1;
    1.80 +}