~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to grub-core/commands/i386/cpuid.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* cpuid.c - test for CPU features */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2006, 2007, 2009  Free Software Foundation, Inc.
 
5
 *  Based on gcc/gcc/config/i386/driver-i386.c
 
6
 *
 
7
 *  GRUB is free software: you can redistribute it and/or modify
 
8
 *  it under the terms of the GNU General Public License as published by
 
9
 *  the Free Software Foundation, either version 3 of the License, or
 
10
 *  (at your option) any later version.
 
11
 *
 
12
 *  GRUB is distributed in the hope that it will be useful,
 
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *  GNU General Public License for more details.
 
16
 *
 
17
 *  You should have received a copy of the GNU General Public License
 
18
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#include <grub/dl.h>
 
22
#include <grub/misc.h>
 
23
#include <grub/mm.h>
 
24
#include <grub/env.h>
 
25
#include <grub/command.h>
 
26
#include <grub/extcmd.h>
 
27
#include <grub/i386/cpuid.h>
 
28
#include <grub/i18n.h>
 
29
 
 
30
#define cpuid(num,a,b,c,d) \
 
31
  asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \
 
32
                : "=a" (a), "=r" (b), "=c" (c), "=d" (d)  \
 
33
                : "0" (num))
 
34
 
 
35
static const struct grub_arg_option options[] =
 
36
  {
 
37
    {"long-mode", 'l', 0, N_("Check for long mode flag (default)."), 0, 0},
 
38
    {0, 0, 0, 0, 0, 0}
 
39
  };
 
40
 
 
41
#define bit_LM (1 << 29)
 
42
 
 
43
unsigned char grub_cpuid_has_longmode = 0;
 
44
 
 
45
static grub_err_t
 
46
grub_cmd_cpuid (grub_extcmd_context_t ctxt __attribute__ ((unused)),
 
47
                int argc __attribute__ ((unused)),
 
48
                char **args __attribute__ ((unused)))
 
49
{
 
50
  return grub_cpuid_has_longmode ? GRUB_ERR_NONE
 
51
    : grub_error (GRUB_ERR_TEST_FAILURE, "false");
 
52
}
 
53
 
 
54
static grub_extcmd_t cmd;
 
55
 
 
56
GRUB_MOD_INIT(cpuid)
 
57
{
 
58
#ifdef __x86_64__
 
59
  /* grub-emu */
 
60
  grub_cpuid_has_longmode = 1;
 
61
#else
 
62
  unsigned int eax, ebx, ecx, edx;
 
63
  unsigned int max_level;
 
64
  unsigned int ext_level;
 
65
 
 
66
  /* See if we can use cpuid.  */
 
67
  asm volatile ("pushfl; pushfl; popl %0; movl %0,%1; xorl %2,%0;"
 
68
                "pushl %0; popfl; pushfl; popl %0; popfl"
 
69
                : "=&r" (eax), "=&r" (ebx)
 
70
                : "i" (0x00200000));
 
71
  if (((eax ^ ebx) & 0x00200000) == 0)
 
72
    goto done;
 
73
 
 
74
  /* Check the highest input value for eax.  */
 
75
  cpuid (0, eax, ebx, ecx, edx);
 
76
  /* We only look at the first four characters.  */
 
77
  max_level = eax;
 
78
  if (max_level == 0)
 
79
    goto done;
 
80
 
 
81
  cpuid (0x80000000, eax, ebx, ecx, edx);
 
82
  ext_level = eax;
 
83
  if (ext_level < 0x80000000)
 
84
    goto done;
 
85
 
 
86
  cpuid (0x80000001, eax, ebx, ecx, edx);
 
87
  grub_cpuid_has_longmode = !!(edx & bit_LM);
 
88
done:
 
89
#endif
 
90
 
 
91
  cmd = grub_register_extcmd ("cpuid", grub_cmd_cpuid, 0,
 
92
                              "[-l]", N_("Check for CPU features."), options);
 
93
}
 
94
 
 
95
GRUB_MOD_FINI(cpuid)
 
96
{
 
97
  grub_unregister_extcmd (cmd);
 
98
}