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. More...
 

Variables

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

Detailed Description

x86 CPU feature detection command

Definition in file cpuid_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ cpuid_exec()

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.

70  {
71  struct cpuid_options opts;
72  struct x86_features features;
73  struct x86_feature_registers *feature_regs;
74  uint32_t feature_reg;
75  unsigned int bit;
76  int rc;
77 
78  /* Parse options */
79  if ( ( rc = parse_options ( argc, argv, &cpuid_cmd, &opts ) ) != 0 )
80  return rc;
81 
82  /* Parse bit number */
83  if ( ( rc = parse_integer ( argv[optind], &bit ) ) != 0 )
84  return rc;
85 
86  /* Get CPU features */
88 
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 );
92 
93  /* Check presence of specified feature */
94  return ( ( feature_reg & ( 1 << bit ) ) ? 0 : -ENOENT );
95 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:88
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int optind
Current option index.
Definition: getopt.c:51
static unsigned int unsigned int bit
Definition: bigint.h:205
#define ENOENT
No such file or directory.
Definition: errno.h:514
void x86_features(struct x86_features *features)
Get x86 CPU features.
Definition: cpuid.c:163
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
x86 CPU features
Definition: cpuid.h:23
static union @423 opts
"cert<xxx>" option list
uint32_t ecx
Features returned via ecx.
Definition: cpuid.h:17
uint32_t features
Supported features.
Definition: ena.h:16
"cpuid" options
Definition: cpuid_cmd.c:41
unsigned int uint32_t
Definition: stdint.h:12
uint32_t edx
Features returned via edx.
Definition: cpuid.h:19
static struct command_descriptor cpuid_cmd
"cpuid" command descriptor
Definition: cpuid_cmd.c:60
An x86 CPU feature register set.
Definition: cpuid.h:15

References bit, cpuid_cmd, x86_feature_registers::ecx, x86_feature_registers::edx, ENOENT, features, optind, opts, parse_integer(), parse_options(), rc, and x86_features().

Variable Documentation

◆ cpuid_opts

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,
}
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition: parseopt.c:200
static uint32_t uint32_t uint32_t uint32_t * ecx
Definition: cpuid.h:77
Option does not take an argument.
Definition: getopt.h:16
"cpuid" options
Definition: cpuid_cmd.c:41
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:66

"cpuid" option list

Definition at line 49 of file cpuid_cmd.c.

◆ cpuid_cmd

struct command_descriptor cpuid_cmd
static
Initial value:
=
COMMAND_DESC ( struct cpuid_options, cpuid_opts, 1, 1, "<bit>" )
"cpuid" options
Definition: cpuid_cmd.c:41
static struct option_descriptor cpuid_opts[]
"cpuid" option list
Definition: cpuid_cmd.c:49
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107

"cpuid" command descriptor

Definition at line 60 of file cpuid_cmd.c.

Referenced by cpuid_exec().

◆ __command

struct command cpuid_command __command
Initial value:
= {
.name = "cpuid",
.exec = cpuid_exec,
}
static int cpuid_exec(int argc, char **argv)
The "cpuid" command.
Definition: cpuid_cmd.c:70

x86 CPU feature detection command

Definition at line 98 of file cpuid_cmd.c.