iPXE
Data Structures | Functions | Variables
cpuid_cmd.c File Reference

x86 CPU feature detection command More...

#include <stdint.h>
#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/cpuid.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>

Go to the source code of this file.

Data Structures

struct  cpuid_options
 "cpuid" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int cpuid_exec (int argc, char **argv)
 The "cpuid" command.

Variables

static struct option_descriptor cpuid_opts []
 "cpuid" option list
static struct command_descriptor cpuid_cmd
 "cpuid" command descriptor
struct command cpuid_command __command
 x86 CPU feature detection command

Detailed Description

x86 CPU feature detection command

Definition in file cpuid_cmd.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static int cpuid_exec ( int  argc,
char **  argv 
) [static]

The "cpuid" command.

Parameters:
argcArgument count
argvArgument list
Return values:
rcReturn status code

Definition at line 70 of file cpuid_cmd.c.

References x86_features::amd, cpuid_options::amd, x86_feature_registers::ecx, cpuid_options::ecx, x86_feature_registers::edx, ENOENT, x86_features::intel, optind, parse_integer(), parse_options(), rc, and x86_features().

                                                {
        struct cpuid_options opts;
        struct x86_features features;
        struct x86_feature_registers *feature_regs;
        uint32_t feature_reg;
        unsigned int bit;
        int rc;

        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, &cpuid_cmd, &opts ) ) != 0 )
                return rc;

        /* Parse bit number */
        if ( ( rc = parse_integer ( argv[optind], &bit ) ) != 0 )
                return rc;

        /* Get CPU features */
        x86_features ( &features );

        /* Extract relevant feature register */
        feature_regs = ( opts.amd ? &features.amd : &features.intel );
        feature_reg = ( opts.ecx ? feature_regs->ecx : feature_regs->edx );

        /* Check presence of specified feature */
        return ( ( feature_reg & ( 1 << bit ) ) ? 0 : -ENOENT );
}

Variable Documentation

struct option_descriptor cpuid_opts[] [static]
Initial value:
 {
        OPTION_DESC ( "ext", 'e', no_argument,
                      struct cpuid_options, amd, parse_flag ),
        
        OPTION_DESC ( "amd", 'a', no_argument,
                      struct cpuid_options, amd, parse_flag ),
        OPTION_DESC ( "ecx", 'c', no_argument,
                      struct cpuid_options, ecx, parse_flag ),
}

"cpuid" option list

Definition at line 49 of file cpuid_cmd.c.

struct command_descriptor cpuid_cmd [static]
Initial value:
        COMMAND_DESC ( struct cpuid_options, cpuid_opts, 1, 1, "<bit>" )

"cpuid" command descriptor

Definition at line 60 of file cpuid_cmd.c.

struct command cpuid_command __command
Initial value:
 {
        .name = "cpuid",
        .exec = cpuid_exec,
}

x86 CPU feature detection command

Definition at line 98 of file cpuid_cmd.c.