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 * ----------------------------------------------------------------------- */
23 #include <syslinux/boot.h>
27 #define REG_AH(x) ((x).eax.b[1])
28 #define REG_CX(x) ((x).ecx.w[0])
29 #define REG_DX(x) ((x).edx.w[0])
31 static inline void error(const char *msg
)
36 static void usage(void)
38 error("Run one command if system match some CPU features, another if it doesn't. \n"
42 " append <option> <cpu_features> -- boot_entry_1 -- boot_entry_2 \n"
43 " label boot_entry_1 \n"
44 " kernel vmlinuz_entry1 \n"
46 " label boot_entry_2 \n"
47 " kernel vmlinuz_entry2 \n"
50 "options could be :\n"
51 " debug : display some debugging messages \n"
52 " dry-run : just do the detection, don't boot \n"
54 "cpu_features could be:\n"
55 " 64 : Processor is x86_64 compatible (lm cpu flag)\n"
56 " hvm : Processor features hardware virtualization (hvm or svm cpu flag)\n"
57 " multicore : Processor must be multi-core \n"
58 " smp : System must be multi-processor \n"
59 " pae : Processor features Physical Address Extension (PAE)\n"
61 "if you want to match many cpu features, just separate them with a single space.\n");
64 static unsigned char sleep(unsigned int msec
)
66 unsigned long micro
= 1000 * msec
;
67 com32sys_t inreg
, outreg
;
70 REG_CX(inreg
) = (micro
>> 16);
71 REG_DX(inreg
) = (micro
& 0xFFFF);
72 __intcall(0x15, &inreg
, &outreg
);
73 return REG_AH(outreg
);
76 /* XXX: this really should be librarized */
77 static void boot_args(char **args
)
84 for (pp
= args
; *pp
; pp
++)
85 len
+= strlen(*pp
) + 1;
87 q
= str
= alloca(len
);
88 for (pp
= args
; *pp
; pp
++) {
99 syslinux_run_default();
101 syslinux_run_command(str
);
104 #define show_bool(mybool) mybool ? "found":"not found"
106 int main(int argc
, char *argv
[])
111 bool hardware_matches
= true;
112 bool multicore
= false;
120 /* If no argument got passed, let's show the usage */
126 for (i
= 1; i
< argc
; i
++) {
127 if (!strcmp(argv
[i
], "--")) {
129 args
[n
++] = &argv
[i
+ 1];
130 } else if (!strcmp(argv
[i
], "64")) {
132 printf(" 64bit : %s on this system\n",
133 show_bool(cpu
.flags
.lm
));
134 hardware_matches
= cpu
.flags
.lm
&& hardware_matches
;
135 } else if (!strcmp(argv
[i
], "pae")) {
137 printf(" pae : %s on this system\n",
138 show_bool(cpu
.flags
.pae
));
139 hardware_matches
= cpu
.flags
.pae
&& hardware_matches
;
140 } else if (!strcmp(argv
[i
], "hvm")) {
142 printf(" hvm : %s on this system\n",
143 show_bool((cpu
.flags
.vmx
|| cpu
.flags
.svm
)));
144 hardware_matches
= (cpu
.flags
.vmx
|| cpu
.flags
.svm
)
146 } else if (!strcmp(argv
[i
], "multicore")) {
148 printf(" multicore : %d cores on this system\n", cpu
.num_cores
);
149 if (cpu
.num_cores
> 1)
151 hardware_matches
= multicore
&& hardware_matches
;
152 } else if (!strcmp(argv
[i
], "smp")) {
154 printf(" smp : %s on this system\n", show_bool(cpu
.flags
.smp
));
155 hardware_matches
= cpu
.flags
.smp
&& hardware_matches
;
156 } else if (!strcmp(argv
[i
], "dry-run")) {
158 } else if (!strcmp(argv
[i
], "debug")) {
165 args
[n
] = args
[n
- 1];
169 printf("\nBooting labels are : '%s' or '%s'\n", *args
[0], *args
[1]);
170 printf("Hardware requirements%smatch this system, let's booting '%s'\n",
171 hardware_matches
? " " : " doesn't ",
172 hardware_matches
? *args
[0] : *args
[1]);
173 printf("Sleeping 5sec before booting\n");
179 boot_args(hardware_matches
? args
[0] : args
[1]);
181 printf("Dry-run mode, let's exiting\n");