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 * ----------------------------------------------------------------------- */
24 #include <syslinux/boot.h>
28 static inline void error(const char *msg
)
33 static void usage(void)
35 error("Run one command if system match some CPU features, another if it doesn't. \n"
39 " append <option> <cpu_features> -- boot_entry_1 -- boot_entry_2 \n"
40 " label boot_entry_1 \n"
41 " kernel vmlinuz_entry1 \n"
43 " label boot_entry_2 \n"
44 " kernel vmlinuz_entry2 \n"
47 "options could be :\n"
48 " debug : display some debugging messages \n"
49 " dry-run : just do the detection, don't boot \n"
51 "cpu_features could be:\n"
52 " 64 : Processor is x86_64 compatible (lm cpu flag)\n"
53 " hvm : Processor features hardware virtualization (hvm or svm cpu flag)\n"
54 " multicore : Processor must be multi-core \n"
55 " smp : System must be multi-processor \n"
56 " pae : Processor features Physical Address Extension (PAE)\n"
57 " hypervisor : Processor is running under an hypervisor\n"
59 "if you want to match many cpu features, just separate them with a single space.\n");
62 /* XXX: this really should be librarized */
63 static void boot_args(char **args
)
70 for (pp
= args
; *pp
; pp
++)
71 len
+= strlen(*pp
) + 1;
73 q
= str
= alloca(len
);
74 for (pp
= args
; *pp
; pp
++) {
85 syslinux_run_default();
87 syslinux_run_command(str
);
90 #define show_bool(mybool) mybool ? "found":"not found"
92 int main(int argc
, char *argv
[])
97 bool hardware_matches
= true;
98 bool multicore
= false;
106 /* If no argument got passed, let's show the usage */
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
], "pae")) {
123 printf(" pae : %s on this system\n",
124 show_bool(cpu
.flags
.pae
));
125 hardware_matches
= cpu
.flags
.pae
&& hardware_matches
;
126 } else if (!strcmp(argv
[i
], "hvm")) {
128 printf(" hvm : %s on this system\n",
129 show_bool((cpu
.flags
.vmx
|| cpu
.flags
.svm
)));
130 hardware_matches
= (cpu
.flags
.vmx
|| cpu
.flags
.svm
)
132 } else if (!strcmp(argv
[i
], "multicore")) {
134 printf(" multicore : %d cores on this system\n", cpu
.num_cores
);
135 if (cpu
.num_cores
> 1)
137 hardware_matches
= multicore
&& hardware_matches
;
138 } else if (!strcmp(argv
[i
], "smp")) {
140 printf(" smp : %s on this system\n", show_bool(cpu
.flags
.smp
));
141 hardware_matches
= cpu
.flags
.smp
&& hardware_matches
;
142 } else if (!strcmp(argv
[i
], "hypervisor")) {
144 printf(" hypervisor : %s on this system\n", show_bool(cpu
.flags
.hypervisor
));
145 hardware_matches
= cpu
.flags
.hypervisor
&& hardware_matches
;
146 } else if (!strcmp(argv
[i
], "dry-run")) {
148 } else if (!strcmp(argv
[i
], "debug")) {
155 args
[n
] = args
[n
- 1];
159 printf("\nBooting labels are : '%s' or '%s'\n", *args
[0], *args
[1]);
160 printf("Hardware requirements%smatch this system, let's booting '%s'\n",
161 hardware_matches
? " " : " doesn't ",
162 hardware_matches
? *args
[0] : *args
[1]);
163 printf("Sleeping 5sec before booting\n");
169 boot_args(hardware_matches
? args
[0] : args
[1]);
171 printf("Dry-run mode, let's exiting\n");