2 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
26 #include <ipxe/cpuid.h>
27 #include <ipxe/command.h>
28 #include <ipxe/parseopt.h>
32 * x86 CPU feature detection command
36 /** "cpuid" options */
37 struct cpuid_options {
38 /** Check AMD-defined features (%eax=0x80000001) */
40 /** Check features defined via %ecx */
44 /** "cpuid" option list */
45 static struct option_descriptor cpuid_opts[] = {
46 OPTION_DESC ( "ext", 'e', no_argument,
47 struct cpuid_options, amd, parse_flag ),
48 /* "--amd" retained for backwards compatibility */
49 OPTION_DESC ( "amd", 'a', no_argument,
50 struct cpuid_options, amd, parse_flag ),
51 OPTION_DESC ( "ecx", 'c', no_argument,
52 struct cpuid_options, ecx, parse_flag ),
55 /** "cpuid" command descriptor */
56 static struct command_descriptor cpuid_cmd =
57 COMMAND_DESC ( struct cpuid_options, cpuid_opts, 1, 1, "<bit>" );
62 * @v argc Argument count
63 * @v argv Argument list
64 * @ret rc Return status code
66 static int cpuid_exec ( int argc, char **argv ) {
67 struct cpuid_options opts;
68 struct x86_features features;
69 struct x86_feature_registers *feature_regs;
75 if ( ( rc = parse_options ( argc, argv, &cpuid_cmd, &opts ) ) != 0 )
78 /* Parse bit number */
79 if ( ( rc = parse_integer ( argv[optind], &bit ) ) != 0 )
82 /* Get CPU features */
83 x86_features ( &features );
85 /* Extract relevant feature register */
86 feature_regs = ( opts.amd ? &features.amd : &features.intel );
87 feature_reg = ( opts.ecx ? feature_regs->ecx : feature_regs->edx );
89 /* Check presence of specified feature */
90 return ( ( feature_reg & ( 1 << bit ) ) ? 0 : -ENOENT );
93 /** x86 CPU feature detection command */
94 struct command cpuid_command __command = {