~ilya-yanok/ubuntu/precise/grub2/fix-for-948716

« back to all changes in this revision

Viewing changes to commands/i386/cpuid.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Millan
  • Date: 2009-07-25 19:00:53 UTC
  • mfrom: (1.6.3 upstream)
  • mto: (17.4.13 sid)
  • mto: This revision was merged to the branch mainline in revision 53.
  • Revision ID: james.westby@ubuntu.com-20090725190053-uv3lm6ya3zxs77ep
ImportĀ upstreamĀ versionĀ 1.96+20090725

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* cpuid.c - test for CPU features */
2
2
/*
3
3
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2006, 2007, 2009  Free Software Foundation, Inc.
 
4
 *  Copyright (C) 2006, 2007  Free Software Foundation, Inc.
5
5
 *  Based on gcc/gcc/config/i386/driver-i386.c
6
6
 *
7
7
 *  GRUB is free software: you can redistribute it and/or modify
23
23
#include <grub/mm.h>
24
24
#include <grub/env.h>
25
25
#include <grub/command.h>
26
 
#include <grub/extcmd.h>
27
 
#include <grub/i386/cpuid.h>
28
26
 
29
27
#define cpuid(num,a,b,c,d) \
30
28
  asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
31
29
                : "=a" (a), "=r" (b), "=c" (c), "=d" (d)  \
32
30
                : "0" (num))
33
31
 
34
 
static const struct grub_arg_option options[] =
35
 
  {
36
 
    {"long-mode", 'l', 0, "check for long mode flag (default)", 0, 0},
37
 
    {0, 0, 0, 0, 0, 0}
38
 
  };
39
 
 
40
32
#define bit_LM (1 << 29)
41
33
 
42
 
unsigned char grub_cpuid_has_longmode = 0;
 
34
static unsigned char has_longmode = 0;
43
35
 
44
36
static grub_err_t
45
 
grub_cmd_cpuid (grub_extcmd_t cmd __attribute__ ((unused)),
46
 
                int argc __attribute__ ((unused)),
47
 
                char **args __attribute__ ((unused)))
 
37
grub_cmd_cpuid (struct grub_command *cmd __attribute__ ((unused)),
 
38
               int argc __attribute__ ((unused)),
 
39
               char **args __attribute__ ((unused)))
48
40
{
49
 
  return grub_cpuid_has_longmode ? GRUB_ERR_NONE
50
 
    : grub_error (GRUB_ERR_TEST_FAILURE, "false");
 
41
  return !has_longmode;
51
42
}
52
43
 
53
 
static grub_extcmd_t cmd;
 
44
static grub_command_t cmd;
54
45
 
55
46
GRUB_MOD_INIT(cpuid)
56
47
{
57
48
#ifdef __x86_64__
58
49
  /* grub-emu */
59
 
  grub_cpuid_has_longmode = 1;
 
50
  has_longmode = 1;
60
51
#else
61
52
  unsigned int eax, ebx, ecx, edx;
62
53
  unsigned int max_level;
83
74
    goto done;
84
75
 
85
76
  cpuid (0x80000001, eax, ebx, ecx, edx);
86
 
  grub_cpuid_has_longmode = !!(edx & bit_LM);
 
77
  has_longmode = !!(edx & bit_LM);
87
78
done:
88
79
#endif
89
80
 
90
 
  cmd = grub_register_extcmd ("cpuid", grub_cmd_cpuid, GRUB_COMMAND_FLAG_BOTH,
91
 
                              "cpuid [-l]", "Check for CPU features", options);
 
81
  cmd = grub_register_command ("cpuid", grub_cmd_cpuid,
 
82
                               0, "Check for CPU features");
92
83
}
93
84
 
94
85
GRUB_MOD_FINI(cpuid)
95
86
{
96
 
  grub_unregister_extcmd (cmd);
 
87
  grub_unregister_command (cmd);
97
88
}