~ubuntu-branches/debian/sid/grub2/sid-200907171837

« back to all changes in this revision

Viewing changes to commands/i386/pc/vbeinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060105152040-1ab076d4n3y2o5yf
Tags: 1.92-1
* New upstream release.
  - Add support for GPT partition table format.
  - Add a new command "play" to play an audio file on PC.
  - Add support for Linux/ADFS partition table format.
  - Add support for BASH-like scripting.
  - Add support for Apple HFS+ filesystems.
* 01_fix_grub-install.patch: Added. Fix grub-install to use
  /bin/grub-mkimage instead of /sbin/grub-mkimage. Closes: #338824
* Do not use CDBS tarball mode anymore. Closes: #344272  

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vbeinfo.c - command to list compatible VBE video modes.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2005  Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB; if not, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <grub/normal.h>
 
22
#include <grub/dl.h>
 
23
#include <grub/arg.h>
 
24
#include <grub/env.h>
 
25
#include <grub/misc.h>
 
26
#include <grub/machine/init.h>
 
27
#include <grub/machine/vbe.h>
 
28
#include <grub/mm.h>
 
29
 
 
30
static void *
 
31
real2pm (grub_vbe_farptr_t ptr)
 
32
{
 
33
  return (void *) ((((unsigned long) ptr & 0xFFFF0000) >> 12UL)
 
34
                   + ((unsigned long) ptr & 0x0000FFFF));
 
35
}
 
36
 
 
37
static grub_err_t
 
38
grub_cmd_vbeinfo (struct grub_arg_list *state __attribute__ ((unused)),
 
39
                  int argc __attribute__ ((unused)),
 
40
                  char **args __attribute__ ((unused)))
 
41
{
 
42
  struct grub_vbe_info_block controller_info;
 
43
  struct grub_vbe_mode_info_block mode_info_tmp;
 
44
  grub_uint32_t use_mode = GRUB_VBE_DEFAULT_VIDEO_MODE;
 
45
  grub_uint16_t *video_mode_list;
 
46
  grub_uint16_t *p;
 
47
  grub_uint16_t *saved_video_mode_list;
 
48
  grub_size_t video_mode_list_size;
 
49
  grub_err_t err;
 
50
  char *modevar;
 
51
 
 
52
  grub_printf ("List of compatible video modes:\n");
 
53
 
 
54
  err = grub_vbe_probe (&controller_info);
 
55
  if (err != GRUB_ERR_NONE)
 
56
    return err;
 
57
 
 
58
  /* Because the information on video modes is stored in a temporary place,
 
59
     it is better to copy it to somewhere safe.  */
 
60
  p = video_mode_list = real2pm (controller_info.video_mode_ptr);
 
61
  while (*p++ != 0xFFFF)
 
62
    ;
 
63
  
 
64
  video_mode_list_size = (grub_addr_t) p - (grub_addr_t) video_mode_list;
 
65
  saved_video_mode_list = grub_malloc (video_mode_list_size);
 
66
  if (! saved_video_mode_list)
 
67
    return grub_errno;
 
68
 
 
69
  grub_memcpy (saved_video_mode_list, video_mode_list, video_mode_list_size);
 
70
  
 
71
  /* Walk through all video modes listed.  */
 
72
  for (p = saved_video_mode_list; *p != 0xFFFF; p++)
 
73
    {
 
74
      const char *memory_model = 0;
 
75
      grub_uint32_t mode = (grub_uint32_t) *p;
 
76
      
 
77
      err = grub_vbe_get_video_mode_info (mode, &mode_info_tmp);
 
78
      if (err != GRUB_ERR_NONE)
 
79
        {
 
80
          grub_errno = GRUB_ERR_NONE;
 
81
          continue;
 
82
        }
 
83
 
 
84
      if ((mode_info_tmp.mode_attributes & 0x001) == 0)
 
85
        /* If not available, skip it.  */
 
86
        continue;
 
87
 
 
88
      if ((mode_info_tmp.mode_attributes & 0x002) == 0)
 
89
        /* Not enough information.  */
 
90
        continue;
 
91
 
 
92
      if ((mode_info_tmp.mode_attributes & 0x008) == 0)
 
93
        /* Monochrome is unusable.  */
 
94
        continue;
 
95
 
 
96
      if ((mode_info_tmp.mode_attributes & 0x080) == 0)
 
97
        /* We support only linear frame buffer modes.  */
 
98
        continue;
 
99
 
 
100
      if ((mode_info_tmp.mode_attributes & 0x010) == 0)
 
101
        /* We allow only graphical modes.  */
 
102
        continue;
 
103
 
 
104
      switch (mode_info_tmp.memory_model)
 
105
        {
 
106
        case 0x04:
 
107
          memory_model = "Packed Pixel";
 
108
          break;
 
109
        case 0x06:
 
110
          memory_model = "Direct Color";
 
111
          break;
 
112
 
 
113
        default:
 
114
          break;
 
115
        }
 
116
 
 
117
      if (! memory_model)
 
118
        continue;
 
119
 
 
120
      grub_printf ("0x%03x: %d x %d x %d bpp (%s)\n",
 
121
                   mode,
 
122
                   mode_info_tmp.x_resolution,
 
123
                   mode_info_tmp.y_resolution,
 
124
                   mode_info_tmp.bits_per_pixel,
 
125
                   memory_model);
 
126
    }
 
127
 
 
128
  grub_free (saved_video_mode_list);
 
129
  
 
130
  /* Check existence of vbe_mode environment variable.  */
 
131
  modevar = grub_env_get ("vbe_mode");
 
132
 
 
133
  if (modevar != 0)
 
134
    {
 
135
      unsigned long value;
 
136
 
 
137
      value = grub_strtoul (modevar, 0, 0);
 
138
      if (grub_errno == GRUB_ERR_NONE)
 
139
        use_mode = value;
 
140
      else
 
141
        grub_errno = GRUB_ERR_NONE;
 
142
    }
 
143
 
 
144
  grub_printf ("Configured VBE mode (vbe_mode) = 0x%03x\n", use_mode);
 
145
 
 
146
  return 0;
 
147
}
 
148
 
 
149
GRUB_MOD_INIT(vbeinfo)
 
150
{
 
151
  (void) mod;                   /* To stop warning.  */
 
152
  grub_register_command ("vbeinfo",
 
153
                         grub_cmd_vbeinfo,
 
154
                         GRUB_COMMAND_FLAG_BOTH,
 
155
                         "vbeinfo",
 
156
                         "List compatible VESA BIOS extension video modes.",
 
157
                         0);
 
158
}
 
159
 
 
160
GRUB_MOD_FINI(vbeinfo)
 
161
{
 
162
  grub_unregister_command ("vbeinfo");
 
163
}