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,
58 "[--ext] [--ecx] <bit>" );
63 * @v argc Argument count
64 * @v argv Argument list
65 * @ret rc Return status code
67 static int cpuid_exec ( int argc, char **argv ) {
68 struct cpuid_options opts;
69 struct x86_features features;
70 struct x86_feature_registers *feature_regs;
76 if ( ( rc = parse_options ( argc, argv, &cpuid_cmd, &opts ) ) != 0 )
79 /* Parse bit number */
80 if ( ( rc = parse_integer ( argv[optind], &bit ) ) != 0 )
83 /* Get CPU features */
84 x86_features ( &features );
86 /* Extract relevant feature register */
87 feature_regs = ( opts.amd ? &features.amd : &features.intel );
88 feature_reg = ( opts.ecx ? feature_regs->ecx : feature_regs->edx );
90 /* Check presence of specified feature */
91 return ( ( feature_reg & ( 1 << bit ) ) ? 0 : -ENOENT );
94 /** x86 CPU feature detection command */
95 struct command cpuid_command __command = {