1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Erwan Velu - All Rights Reserved
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.
11 * ----------------------------------------------------------------------- */
16 * Run one command (boot_entry_1) if the booted system match some CPU features
17 * and another (boot_entry_2) if it doesn't.
18 * Eventually this and other features should get folded into some kind
19 * of scripting engine.
25 * append <option> <cpu_features> -- boot_entry_1 -- boot_entry_2
34 * debug : display some debugging messages
35 * dry-run : just do the detection, don't boot
37 * cpu_features could be:
38 * 64 : CPU have to be x86_64 compatible
39 * hvm : Processor must have hardware virtualization (hvm or svm)
40 * multicore : Processor must be multi-core
41 * smp : System have to be SMP
43 * if you want to match many cpu features, just separate them with a single space
51 #include <syslinux/boot.h>
55 #define REG_AH(x) ((x).eax.b[1])
56 #define REG_CX(x) ((x).ecx.w[0])
57 #define REG_DX(x) ((x).edx.w[0])
59 static unsigned char sleep(unsigned int msec
)
61 unsigned long micro
= 1000 * msec
;
62 com32sys_t inreg
, outreg
;
65 REG_CX(inreg
) = (micro
>> 16);
66 REG_DX(inreg
) = (micro
& 0xFFFF);
67 __intcall(0x15, &inreg
, &outreg
);
68 return REG_AH(outreg
);
71 /* XXX: this really should be librarized */
72 static void boot_args(char **args
)
79 for (pp
= args
; *pp
; pp
++)
82 q
= str
= alloca(len
+ 1);
83 for (pp
= args
; *pp
; pp
++) {
91 syslinux_run_default();
93 syslinux_run_command(str
);
96 #define show_bool(mybool) mybool ? "found":"not found"
98 int main(int argc
, char *argv
[])
103 bool hardware_matches
= true;
104 bool multicore
= false;
112 for (i
= 1; i
< argc
; i
++) {
113 if (!strcmp(argv
[i
], "--")) {
115 args
[n
++] = &argv
[i
+ 1];
116 } else if (!strcmp(argv
[i
], "64")) {
118 printf(" 64bit : %s on this system\n",
119 show_bool(cpu
.flags
.lm
));
120 hardware_matches
= cpu
.flags
.lm
&& hardware_matches
;
121 } else if (!strcmp(argv
[i
], "hvm")) {
123 printf(" hvm : %s on this system\n",
124 show_bool((cpu
.flags
.vmx
|| cpu
.flags
.svm
)));
125 hardware_matches
= (cpu
.flags
.vmx
|| cpu
.flags
.svm
)
127 } else if (!strcmp(argv
[i
], "multicore")) {
129 printf(" multicore : %d cores on this system\n", cpu
.num_cores
);
130 if (cpu
.num_cores
> 1)
132 hardware_matches
= multicore
&& hardware_matches
;
133 } else if (!strcmp(argv
[i
], "smp")) {
135 printf(" smp : %s on this system\n", show_bool(cpu
.flags
.smp
));
136 hardware_matches
= cpu
.flags
.smp
&& hardware_matches
;
137 } else if (!strcmp(argv
[i
], "dry-run")) {
139 } else if (!strcmp(argv
[i
], "debug")) {
146 args
[n
] = args
[n
- 1];
150 printf("\nBooting labels are : '%s' or '%s'\n", *args
[0], *args
[1]);
151 printf("Hardware requirements%smatch this system, let's booting '%s'\n",
152 hardware_matches
? " " : " doesn't ",
153 hardware_matches
? *args
[0] : *args
[1]);
154 printf("Sleeping 5sec before booting\n");
160 boot_args(hardware_matches
? args
[0] : args
[1]);
162 printf("Dry-run mode, let's exiting\n");