1 /* ----------------------------------------------------------------------- *
3 * Copyright 2008 H. Peter Anvin - 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 if the CPU has 64-bit support, and another if it doesn't.
17 * Eventually this and other features should get folded into some kind
18 * of scripting engine.
24 * append boot_kernel_64 [-- boot_kernel_32pae] -- boot_kernel_32
25 * label boot_kernel_32
28 * label boot_kernel_64
37 #include <syslinux/boot.h>
39 static bool __constfunc cpu_has_cpuid(void)
41 return cpu_has_eflag(X86_EFLAGS_ID);
44 static bool __constfunc cpu_has_level(uint32_t level)
52 group = level & 0xffff0000;
53 limit = cpuid_eax(group);
55 if ((limit & 0xffff0000) != group)
64 /* This only supports feature groups 0 and 1, corresponding to the
65 Intel and AMD EDX bit vectors. We can add more later if need be. */
66 static bool __constfunc cpu_has_feature(int x)
68 uint32_t level = ((x & 1) << 31) | 1;
70 return cpu_has_level(level) && ((cpuid_edx(level) >> (x & 31) & 1));
73 /* XXX: this really should be librarized */
74 static void boot_args(char **args)
81 for (pp = args; *pp; pp++)
84 q = str = alloca(len+1);
85 for (pp = args; *pp; pp++) {
93 syslinux_run_default();
95 syslinux_run_command(str);
98 int main(int argc, char *argv[])
104 for (i = 0; i < 3; i++)
108 for (i = 1; i < argc; i++) {
109 if (!strcmp(argv[i], "--")) {
111 args[n++] = &argv[i+1];
117 boot_args(cpu_has_feature(X86_FEATURE_LM) ? args[0] :
118 cpu_has_feature(X86_FEATURE_PAE) ? args[1] :