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>
24 #include <grub/misc.h>
25 #include <grub/term.h>
26 #include <grub/machine/init.h>
27 #include <grub/machine/vbe.h>
31 grub_cmd_vbetest (struct grub_arg_list
*state
__attribute__ ((unused
)),
32 int argc
__attribute__ ((unused
)),
33 char **args
__attribute__ ((unused
)))
37 struct grub_vbe_mode_info_block mode_info
;
38 struct grub_vbe_info_block controller_info
;
39 grub_uint32_t use_mode
= GRUB_VBE_DEFAULT_VIDEO_MODE
;
40 grub_uint32_t old_mode
;
41 grub_uint8_t
*framebuffer
= 0;
42 grub_uint32_t bytes_per_scan_line
= 0;
46 grub_printf ("Probing for VESA BIOS Extension ... ");
48 /* Check if VESA BIOS exists. */
49 err
= grub_vbe_probe (&controller_info
);
50 if (err
!= GRUB_ERR_NONE
)
53 grub_printf ("found!\n");
55 /* Dump out controller information. */
56 grub_printf ("VBE signature = %c%c%c%c\n",
57 controller_info
.signature
[0],
58 controller_info
.signature
[1],
59 controller_info
.signature
[2],
60 controller_info
.signature
[3]);
62 grub_printf ("VBE version = %d.%d\n",
63 controller_info
.version
>> 8,
64 controller_info
.version
& 0xFF);
65 grub_printf ("OEM string ptr = %08x\n",
66 controller_info
.oem_string_ptr
);
67 grub_printf ("Total memory = %d\n",
68 controller_info
.total_memory
);
70 err
= grub_vbe_get_video_mode (&old_mode
);
71 grub_printf ("Get video mode err = %04x\n", err
);
73 if (err
== GRUB_ERR_NONE
)
74 grub_printf ("Old video mode = %04x\n", old_mode
);
76 grub_errno
= GRUB_ERR_NONE
;
78 /* Check existence of vbe_mode environment variable. */
79 modevar
= grub_env_get ("vbe_mode");
84 value
= grub_strtoul (modevar
, 0, 0);
85 if (grub_errno
== GRUB_ERR_NONE
)
88 grub_errno
= GRUB_ERR_NONE
;
91 err
= grub_vbe_get_video_mode_info (use_mode
, &mode_info
);
92 if (err
!= GRUB_ERR_NONE
)
95 /* Dump out details about the mode being tested. */
96 grub_printf ("mode: 0x%03x\n",
98 grub_printf ("width : %d\n",
99 mode_info
.x_resolution
);
100 grub_printf ("height: %d\n",
101 mode_info
.y_resolution
);
102 grub_printf ("memory model: %02x\n",
103 mode_info
.memory_model
);
104 grub_printf ("bytes/scanline: %d\n",
105 mode_info
.bytes_per_scan_line
);
106 grub_printf ("bytes/scanline (lin): %d\n",
107 mode_info
.lin_bytes_per_scan_line
);
108 grub_printf ("base address: %08x\n",
109 mode_info
.phys_base_addr
);
110 grub_printf ("red mask/pos: %d/%d\n",
111 mode_info
.red_mask_size
,
112 mode_info
.red_field_position
);
113 grub_printf ("green mask/pos: %d/%d\n",
114 mode_info
.green_mask_size
,
115 mode_info
.green_field_position
);
116 grub_printf ("blue mask/pos: %d/%d\n",
117 mode_info
.blue_mask_size
,
118 mode_info
.blue_field_position
);
120 grub_printf ("Press any key to continue.\n");
124 /* Setup GFX mode. */
125 err
= grub_vbe_set_video_mode (use_mode
, &mode_info
);
126 if (err
!= GRUB_ERR_NONE
)
129 /* Determine framebuffer address and how many bytes are in scan line. */
130 framebuffer
= (grub_uint8_t
*) mode_info
.phys_base_addr
;
133 if (controller_info
.version
>= 0x300)
135 bytes_per_scan_line
= mode_info
.lin_bytes_per_scan_line
;
139 bytes_per_scan_line
= mode_info
.bytes_per_scan_line
;
142 /* Draw some random data to screen. */
143 for (i
= 0; i
< 256 * 256; i
++)
148 /* Draw white line to screen. */
149 for (i
= 0; i
< 100; i
++)
151 ptr
[mode_info
.bytes_per_scan_line
* 50 + i
] = 0x0F;
154 /* Draw another white line to screen. */
155 grub_memset (ptr
+ bytes_per_scan_line
* 51, 0x0f, bytes_per_scan_line
);
159 /* Restore old video mode. */
160 grub_vbe_set_video_mode (old_mode
, 0);
165 GRUB_MOD_INIT(vbetest
)
167 (void) mod
; /* To stop warning. */
168 grub_register_command ("vbetest",
170 GRUB_COMMAND_FLAG_BOTH
,
172 "Test VESA BIOS Extension 2.0+ support",
176 GRUB_MOD_FINI(vbetest
)
178 grub_unregister_command ("vbetest");