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
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
30 #include <ipxe/cpuid.h>
31 #include <ipxe/command.h>
32 #include <ipxe/parseopt.h>
36 * x86 CPU feature detection command
40 /** "cpuid" options */
41 struct cpuid_options {
42 /** Check AMD-defined features (%eax=0x80000001) */
44 /** Check features defined via %ecx */
48 /** "cpuid" option list */
49 static struct option_descriptor cpuid_opts[] = {
50 OPTION_DESC ( "ext", 'e', no_argument,
51 struct cpuid_options, amd, parse_flag ),
52 /* "--amd" retained for backwards compatibility */
53 OPTION_DESC ( "amd", 'a', no_argument,
54 struct cpuid_options, amd, parse_flag ),
55 OPTION_DESC ( "ecx", 'c', no_argument,
56 struct cpuid_options, ecx, parse_flag ),
59 /** "cpuid" command descriptor */
60 static struct command_descriptor cpuid_cmd =
61 COMMAND_DESC ( struct cpuid_options, cpuid_opts, 1, 1, "<bit>" );
66 * @v argc Argument count
67 * @v argv Argument list
68 * @ret rc Return status code
70 static int cpuid_exec ( int argc, char **argv ) {
71 struct cpuid_options opts;
72 struct x86_features features;
73 struct x86_feature_registers *feature_regs;
79 if ( ( rc = parse_options ( argc, argv, &cpuid_cmd, &opts ) ) != 0 )
82 /* Parse bit number */
83 if ( ( rc = parse_integer ( argv[optind], &bit ) ) != 0 )
86 /* Get CPU features */
87 x86_features ( &features );
89 /* Extract relevant feature register */
90 feature_regs = ( opts.amd ? &features.amd : &features.intel );
91 feature_reg = ( opts.ecx ? feature_regs->ecx : feature_regs->edx );
93 /* Check presence of specified feature */
94 return ( ( feature_reg & ( 1 << bit ) ) ? 0 : -ENOENT );
97 /** x86 CPU feature detection command */
98 struct command cpuid_command __command = {