1
/* vbetest.c - command to test VESA BIOS Extension 2.0+ support. */
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>
23
#include <grub/misc.h>
24
#include <grub/term.h>
25
#include <grub/machine/init.h>
26
#include <grub/machine/vbe.h>
27
#include <grub/video.h>
29
#include <grub/i18n.h>
32
grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)),
33
int argc __attribute__ ((unused)),
34
char **args __attribute__ ((unused)))
38
struct grub_vbe_mode_info_block mode_info;
39
struct grub_vbe_info_block controller_info;
40
grub_uint32_t use_mode = GRUB_VBE_DEFAULT_VIDEO_MODE;
41
grub_uint32_t old_mode;
42
grub_uint8_t *framebuffer = 0;
43
grub_uint32_t bytes_per_scan_line = 0;
47
grub_printf ("Probing for VESA BIOS Extension ... ");
49
/* Check if VESA BIOS exists. */
50
err = grub_vbe_probe (&controller_info);
51
if (err != GRUB_ERR_NONE)
54
grub_printf ("found!\n");
56
/* Dump out controller information. */
57
grub_printf ("VBE signature = %c%c%c%c\n",
58
controller_info.signature[0],
59
controller_info.signature[1],
60
controller_info.signature[2],
61
controller_info.signature[3]);
63
grub_printf ("VBE version = %d.%d\n",
64
controller_info.version >> 8,
65
controller_info.version & 0xFF);
66
grub_printf ("OEM string ptr = %08x\n",
67
controller_info.oem_string_ptr);
68
grub_printf ("Total memory = %d\n",
69
controller_info.total_memory);
71
err = grub_vbe_get_video_mode (&old_mode);
72
grub_printf ("Get video mode err = %04x\n", err);
74
if (err == GRUB_ERR_NONE)
75
grub_printf ("Old video mode = %04x\n", old_mode);
77
grub_errno = GRUB_ERR_NONE;
79
/* Check existence of vbe_mode environment variable. */
80
modevar = grub_env_get ("vbe_mode");
85
value = grub_strtoul (modevar, 0, 0);
86
if (grub_errno == GRUB_ERR_NONE)
89
grub_errno = GRUB_ERR_NONE;
92
err = grub_vbe_get_video_mode_info (use_mode, &mode_info);
93
if (err != GRUB_ERR_NONE)
96
/* Dump out details about the mode being tested. */
97
grub_printf ("mode: 0x%03x\n",
99
grub_printf ("width : %d\n",
100
mode_info.x_resolution);
101
grub_printf ("height: %d\n",
102
mode_info.y_resolution);
103
grub_printf ("memory model: %02x\n",
104
mode_info.memory_model);
105
grub_printf ("bytes/scanline: %d\n",
106
mode_info.bytes_per_scan_line);
107
grub_printf ("bytes/scanline (lin): %d\n",
108
mode_info.lin_bytes_per_scan_line);
109
grub_printf ("base address: %08x\n",
110
mode_info.phys_base_addr);
111
grub_printf ("red mask/pos: %d/%d\n",
112
mode_info.red_mask_size,
113
mode_info.red_field_position);
114
grub_printf ("green mask/pos: %d/%d\n",
115
mode_info.green_mask_size,
116
mode_info.green_field_position);
117
grub_printf ("blue mask/pos: %d/%d\n",
118
mode_info.blue_mask_size,
119
mode_info.blue_field_position);
121
grub_printf ("Press any key to continue.\n");
125
/* Setup GFX mode. */
126
err = grub_vbe_set_video_mode (use_mode, &mode_info);
127
if (err != GRUB_ERR_NONE)
130
/* Determine framebuffer address and how many bytes are in scan line. */
131
framebuffer = (grub_uint8_t *) mode_info.phys_base_addr;
134
if (controller_info.version >= 0x300)
136
bytes_per_scan_line = mode_info.lin_bytes_per_scan_line;
140
bytes_per_scan_line = mode_info.bytes_per_scan_line;
143
/* Draw some random data to screen. */
144
for (i = 0; i < 256 * 256; i++)
149
/* Draw white line to screen. */
150
for (i = 0; i < 100; i++)
152
ptr[mode_info.bytes_per_scan_line * 50 + i] = 0x0F;
155
/* Draw another white line to screen. */
156
grub_memset (ptr + bytes_per_scan_line * 51, 0x0f, bytes_per_scan_line);
160
grub_video_restore ();
162
/* Restore old video mode. */
163
grub_vbe_set_video_mode (old_mode, 0);
168
static grub_command_t cmd;
170
GRUB_MOD_INIT(vbetest)
172
cmd = grub_register_command ("vbetest", grub_cmd_vbetest,
173
0, N_("Test VESA BIOS Extension 2.0+ support."));
176
GRUB_MOD_FINI(vbetest)
178
grub_unregister_command (cmd);