rev |
line source |
pascal@3665
|
1 /* ----------------------------------------------------------------------- *
|
pascal@3665
|
2 *
|
pascal@3665
|
3 * Copyright 2009 Pascal Bellard - All Rights Reserved
|
pascal@3665
|
4 *
|
pascal@3665
|
5 * This program is free software; you can redistribute it and/or modify
|
pascal@3665
|
6 * it under the terms of the GNU General Public License as published by
|
pascal@3665
|
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
pascal@3665
|
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
|
pascal@3665
|
9 * (at your option) any later version; incorporated herein by reference.
|
pascal@3665
|
10 *
|
pascal@3665
|
11 * ----------------------------------------------------------------------- */
|
pascal@3665
|
12
|
pascal@3665
|
13 /*
|
pascal@3665
|
14 * ifmem.c
|
pascal@3665
|
15 *
|
pascal@3665
|
16 * Run one command if the memory is large enought, and another if it isn't.
|
pascal@3665
|
17 *
|
pascal@3665
|
18 * Usage:
|
pascal@3665
|
19 *
|
pascal@3665
|
20 * label boot_kernel
|
pascal@3665
|
21 * kernel ifmem.c
|
pascal@3665
|
22 * append size_in_KB boot_large [size_in_KB boot_medium] boot_small
|
pascal@3665
|
23 *
|
pascal@3665
|
24 * label boot_large
|
pascal@3665
|
25 * kernel vmlinuz_large_memory
|
pascal@3665
|
26 * append ...
|
pascal@3665
|
27 *
|
pascal@3665
|
28 * label boot_small
|
pascal@3665
|
29 * kernel vmlinuz_small_memory
|
pascal@3665
|
30 * append ...
|
pascal@3665
|
31 */
|
pascal@3665
|
32
|
pascal@3665
|
33 #include <inttypes.h>
|
pascal@3665
|
34 #include <com32.h>
|
pascal@3665
|
35 #include <console.h>
|
pascal@3665
|
36 #include <stdio.h>
|
pascal@3665
|
37 #include <string.h>
|
pascal@3665
|
38 #include <alloca.h>
|
pascal@3665
|
39 #include <stdlib.h>
|
pascal@3665
|
40 #include <syslinux/boot.h>
|
pascal@3665
|
41
|
pascal@3867
|
42 static unsigned long memory_size(void)
|
pascal@3665
|
43 {
|
pascal@3917
|
44 unsigned long res;
|
pascal@3665
|
45 com32sys_t ireg, oreg;
|
pascal@3665
|
46
|
pascal@3665
|
47 memset(&ireg, 0, sizeof ireg);
|
pascal@3665
|
48
|
pascal@3665
|
49 ireg.eax.w[0] = 0xe801;
|
pascal@3665
|
50 __intcall(0x15, &ireg, &oreg);
|
pascal@3665
|
51
|
pascal@3917
|
52 res = oreg.ecx.w[0] + ( oreg.edx.w[0] << 6);
|
pascal@3917
|
53 if (!res) {
|
pascal@3917
|
54 memset(&ireg, 0, sizeof ireg);
|
pascal@3917
|
55 ireg.eax.w[0] = 0x8800;
|
pascal@3917
|
56 __intcall(0x15, &ireg, &oreg);
|
pascal@3917
|
57 res = ireg.eax.w[0];
|
pascal@3917
|
58 }
|
pascal@3917
|
59 return res;
|
pascal@3665
|
60 }
|
pascal@3665
|
61
|
pascal@3665
|
62 int main(int argc, char *argv[])
|
pascal@3665
|
63 {
|
pascal@3665
|
64 char *s;
|
pascal@3870
|
65 int i, j = 1;
|
pascal@3665
|
66
|
pascal@3665
|
67 for (s = argv[1]; *s && (*s < '0' || *s > '9'); s++);
|
pascal@3665
|
68
|
pascal@3665
|
69 if (argc < 4 || !*s) {
|
pascal@3665
|
70 openconsole(&dev_null_r, &dev_stdcon_w);
|
pascal@3665
|
71 perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n");
|
pascal@3665
|
72 return 1;
|
pascal@3665
|
73 }
|
pascal@3665
|
74
|
pascal@3868
|
75 // find target according to ram size
|
pascal@3665
|
76 for (i = 1; i + 2 < argc; ) {
|
pascal@3869
|
77 j = i++; // size
|
pascal@3665
|
78 if (memory_size() >= strtoul(s, NULL, 0)) break;
|
pascal@3665
|
79 s = argv[++i];
|
pascal@3665
|
80 }
|
pascal@3867
|
81
|
pascal@3868
|
82 // find and copy extra parameters to command line
|
pascal@3869
|
83 // assume the command line ends with two words (not number)
|
pascal@3869
|
84 for (s = argv[i++]; i < argc; i++) {
|
pascal@3870
|
85 char c = *argv[i];
|
pascal@3869
|
86 if (c >= '0' && c <= '9') j = i;
|
pascal@3870
|
87 if (i - j > 2 && i < argc) {
|
pascal@3867
|
88 #define SZ 512
|
pascal@3867
|
89 static char cmdline[SZ];
|
pascal@3867
|
90 char *p = cmdline, *q = s;
|
pascal@3867
|
91 int j;
|
pascal@3867
|
92 for (j = i; j <= argc; j++) {
|
pascal@3867
|
93 while (*q && p < cmdline + SZ -1) *p++ = *q++;
|
pascal@3867
|
94 if (p < cmdline + SZ -1) *p++ = ' ';
|
pascal@3867
|
95 q = argv[j];
|
pascal@3867
|
96 }
|
pascal@3867
|
97 *p++ = 0;
|
pascal@3867
|
98 s = cmdline;
|
pascal@3867
|
99 }
|
pascal@3867
|
100 }
|
pascal@3867
|
101
|
pascal@3867
|
102 if (s) syslinux_run_command(s);
|
pascal@3867
|
103 else syslinux_run_default();
|
pascal@3665
|
104 return -1;
|
pascal@3665
|
105 }
|