1 /* vbeinfo.c - command to list compatible VBE video modes. */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2007 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 3 of the License, or
9 * (at your option) any later version.
11 * GRUB 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, see <http://www.gnu.org/licenses/>.
20 #include <grub/normal.h>
24 #include <grub/misc.h>
25 #include <grub/machine/init.h>
26 #include <grub/machine/vbe.h>
30 real2pm (grub_vbe_farptr_t ptr
)
32 return (void *) ((((unsigned long) ptr
& 0xFFFF0000) >> 12UL)
33 + ((unsigned long) ptr
& 0x0000FFFF));
37 grub_cmd_vbeinfo (struct grub_arg_list
*state
__attribute__ ((unused
)),
38 int argc
__attribute__ ((unused
)),
39 char **args
__attribute__ ((unused
)))
41 struct grub_vbe_info_block controller_info
;
42 struct grub_vbe_mode_info_block mode_info_tmp
;
43 grub_uint32_t use_mode
= GRUB_VBE_DEFAULT_VIDEO_MODE
;
44 grub_uint16_t
*video_mode_list
;
46 grub_uint16_t
*saved_video_mode_list
;
47 grub_size_t video_mode_list_size
;
51 err
= grub_vbe_probe (&controller_info
);
52 if (err
!= GRUB_ERR_NONE
)
55 grub_printf ("VBE info: version: %d.%d OEM software rev: %d.%d\n",
56 controller_info
.version
>> 8,
57 controller_info
.version
& 0xFF,
58 controller_info
.oem_software_rev
>> 8,
59 controller_info
.oem_software_rev
& 0xFF);
61 /* The total_memory field is in 64 KiB units. */
62 grub_printf (" total memory: %d KiB\n",
63 (controller_info
.total_memory
<< 16) / 1024);
65 /* Because the information on video modes is stored in a temporary place,
66 it is better to copy it to somewhere safe. */
67 p
= video_mode_list
= real2pm (controller_info
.video_mode_ptr
);
68 while (*p
++ != 0xFFFF)
71 video_mode_list_size
= (grub_addr_t
) p
- (grub_addr_t
) video_mode_list
;
72 saved_video_mode_list
= grub_malloc (video_mode_list_size
);
73 if (! saved_video_mode_list
)
76 grub_memcpy (saved_video_mode_list
, video_mode_list
, video_mode_list_size
);
78 grub_printf ("List of compatible video modes:\n");
79 grub_printf ("Legend: P=Packed pixel, D=Direct color, "
80 "mask/pos=R/G/B/reserved\n");
82 /* Walk through all video modes listed. */
83 for (p
= saved_video_mode_list
; *p
!= 0xFFFF; p
++)
85 const char *memory_model
= 0;
86 grub_uint32_t mode
= (grub_uint32_t
) *p
;
88 err
= grub_vbe_get_video_mode_info (mode
, &mode_info_tmp
);
89 if (err
!= GRUB_ERR_NONE
)
91 grub_errno
= GRUB_ERR_NONE
;
95 if ((mode_info_tmp
.mode_attributes
& GRUB_VBE_MODEATTR_SUPPORTED
) == 0)
96 /* If not available, skip it. */
99 if ((mode_info_tmp
.mode_attributes
& GRUB_VBE_MODEATTR_RESERVED_1
) == 0)
100 /* Not enough information. */
103 if ((mode_info_tmp
.mode_attributes
& GRUB_VBE_MODEATTR_COLOR
) == 0)
104 /* Monochrome is unusable. */
107 if ((mode_info_tmp
.mode_attributes
& GRUB_VBE_MODEATTR_LFB_AVAIL
) == 0)
108 /* We support only linear frame buffer modes. */
111 if ((mode_info_tmp
.mode_attributes
& GRUB_VBE_MODEATTR_GRAPHICS
) == 0)
112 /* We allow only graphical modes. */
115 switch (mode_info_tmp
.memory_model
)
117 case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL
:
118 memory_model
= "Packed";
120 case GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR
:
121 memory_model
= "Direct";
131 grub_printf ("0x%03x: %4d x %4d x %2d %s",
133 mode_info_tmp
.x_resolution
,
134 mode_info_tmp
.y_resolution
,
135 mode_info_tmp
.bits_per_pixel
,
138 /* Show mask and position details for direct color modes. */
139 if (mode_info_tmp
.memory_model
== GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR
)
140 grub_printf (", mask: %d/%d/%d/%d pos: %d/%d/%d/%d",
141 mode_info_tmp
.red_mask_size
,
142 mode_info_tmp
.green_mask_size
,
143 mode_info_tmp
.blue_mask_size
,
144 mode_info_tmp
.rsvd_mask_size
,
145 mode_info_tmp
.red_field_position
,
146 mode_info_tmp
.green_field_position
,
147 mode_info_tmp
.blue_field_position
,
148 mode_info_tmp
.rsvd_field_position
);
152 grub_free (saved_video_mode_list
);
154 /* Check existence of vbe_mode environment variable. */
155 modevar
= grub_env_get ("vbe_mode");
161 value
= grub_strtoul (modevar
, 0, 0);
162 if (grub_errno
== GRUB_ERR_NONE
)
165 grub_errno
= GRUB_ERR_NONE
;
168 grub_printf ("Configured VBE mode (vbe_mode) = 0x%03x\n", use_mode
);
173 GRUB_MOD_INIT(vbeinfo
)
175 (void) mod
; /* To stop warning. */
176 grub_register_command ("vbeinfo",
178 GRUB_COMMAND_FLAG_BOTH
,
180 "List compatible VESA BIOS extension video modes.",
184 GRUB_MOD_FINI(vbeinfo
)
186 grub_unregister_command ("vbeinfo");