1
/* vbeinfo.c - command to list compatible VBE video modes. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2005 Free Software Foundation, Inc.
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.
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.
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.
21
#include <grub/normal.h>
25
#include <grub/misc.h>
26
#include <grub/machine/init.h>
27
#include <grub/machine/vbe.h>
31
real2pm (grub_vbe_farptr_t ptr)
33
return (void *) ((((unsigned long) ptr & 0xFFFF0000) >> 12UL)
34
+ ((unsigned long) ptr & 0x0000FFFF));
38
grub_cmd_vbeinfo (struct grub_arg_list *state __attribute__ ((unused)),
39
int argc __attribute__ ((unused)),
40
char **args __attribute__ ((unused)))
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;
47
grub_uint16_t *saved_video_mode_list;
48
grub_size_t video_mode_list_size;
52
grub_printf ("List of compatible video modes:\n");
54
err = grub_vbe_probe (&controller_info);
55
if (err != GRUB_ERR_NONE)
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)
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)
69
grub_memcpy (saved_video_mode_list, video_mode_list, video_mode_list_size);
71
/* Walk through all video modes listed. */
72
for (p = saved_video_mode_list; *p != 0xFFFF; p++)
74
const char *memory_model = 0;
75
grub_uint32_t mode = (grub_uint32_t) *p;
77
err = grub_vbe_get_video_mode_info (mode, &mode_info_tmp);
78
if (err != GRUB_ERR_NONE)
80
grub_errno = GRUB_ERR_NONE;
84
if ((mode_info_tmp.mode_attributes & 0x001) == 0)
85
/* If not available, skip it. */
88
if ((mode_info_tmp.mode_attributes & 0x002) == 0)
89
/* Not enough information. */
92
if ((mode_info_tmp.mode_attributes & 0x008) == 0)
93
/* Monochrome is unusable. */
96
if ((mode_info_tmp.mode_attributes & 0x080) == 0)
97
/* We support only linear frame buffer modes. */
100
if ((mode_info_tmp.mode_attributes & 0x010) == 0)
101
/* We allow only graphical modes. */
104
switch (mode_info_tmp.memory_model)
107
memory_model = "Packed Pixel";
110
memory_model = "Direct Color";
120
grub_printf ("0x%03x: %d x %d x %d bpp (%s)\n",
122
mode_info_tmp.x_resolution,
123
mode_info_tmp.y_resolution,
124
mode_info_tmp.bits_per_pixel,
128
grub_free (saved_video_mode_list);
130
/* Check existence of vbe_mode environment variable. */
131
modevar = grub_env_get ("vbe_mode");
137
value = grub_strtoul (modevar, 0, 0);
138
if (grub_errno == GRUB_ERR_NONE)
141
grub_errno = GRUB_ERR_NONE;
144
grub_printf ("Configured VBE mode (vbe_mode) = 0x%03x\n", use_mode);
149
GRUB_MOD_INIT(vbeinfo)
151
(void) mod; /* To stop warning. */
152
grub_register_command ("vbeinfo",
154
GRUB_COMMAND_FLAG_BOTH,
156
"List compatible VESA BIOS extension video modes.",
160
GRUB_MOD_FINI(vbeinfo)
162
grub_unregister_command ("vbeinfo");