~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

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

Tags: upstream-1.99~20101122
ImportĀ upstreamĀ versionĀ 1.99~20101122

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* vbetest.c - command to test VESA BIOS Extension 2.0+ support.  */
2
 
/*
3
 
 *  GRUB  --  GRand Unified Bootloader
4
 
 *  Copyright (C) 2005,2007  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 3 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
#include <grub/normal.h>
21
 
#include <grub/dl.h>
22
 
#include <grub/env.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/err.h>
28
 
#include <grub/i18n.h>
29
 
 
30
 
static grub_err_t
31
 
grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)),
32
 
                  int argc __attribute__ ((unused)),
33
 
                  char **args __attribute__ ((unused)))
34
 
{
35
 
  grub_err_t err;
36
 
  char *modevar;
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;
43
 
  unsigned char *ptr;
44
 
  int i;
45
 
 
46
 
  grub_printf ("Probing for VESA BIOS Extension ... ");
47
 
 
48
 
  /* Check if VESA BIOS exists.  */
49
 
  err = grub_vbe_probe (&controller_info);
50
 
  if (err != GRUB_ERR_NONE)
51
 
    return err;
52
 
 
53
 
  grub_printf ("found!\n");
54
 
 
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]);
61
 
 
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);
69
 
 
70
 
  err = grub_vbe_get_video_mode (&old_mode);
71
 
  grub_printf ("Get video mode err = %04x\n", err);
72
 
 
73
 
  if (err == GRUB_ERR_NONE)
74
 
    grub_printf ("Old video mode = %04x\n", old_mode);
75
 
  else
76
 
    grub_errno = GRUB_ERR_NONE;
77
 
 
78
 
  /* Check existence of vbe_mode environment variable.  */
79
 
  modevar = grub_env_get ("vbe_mode");
80
 
  if (modevar != 0)
81
 
    {
82
 
      unsigned long value;
83
 
 
84
 
      value = grub_strtoul (modevar, 0, 0);
85
 
      if (grub_errno == GRUB_ERR_NONE)
86
 
        use_mode = value;
87
 
      else
88
 
        grub_errno = GRUB_ERR_NONE;
89
 
    }
90
 
 
91
 
  err = grub_vbe_get_video_mode_info (use_mode, &mode_info);
92
 
  if (err != GRUB_ERR_NONE)
93
 
    return err;
94
 
 
95
 
  /* Dump out details about the mode being tested.  */
96
 
  grub_printf ("mode: 0x%03x\n",
97
 
               use_mode);
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);
119
 
 
120
 
  grub_printf ("Press any key to continue.\n");
121
 
 
122
 
  grub_getkey ();
123
 
 
124
 
  /* Setup GFX mode.  */
125
 
  err = grub_vbe_set_video_mode (use_mode, &mode_info);
126
 
  if (err != GRUB_ERR_NONE)
127
 
    return err;
128
 
 
129
 
  /* Determine framebuffer address and how many bytes are in scan line.  */
130
 
  framebuffer = (grub_uint8_t *) mode_info.phys_base_addr;
131
 
  ptr = framebuffer;
132
 
 
133
 
  if (controller_info.version >= 0x300)
134
 
    {
135
 
      bytes_per_scan_line = mode_info.lin_bytes_per_scan_line;
136
 
    }
137
 
  else
138
 
    {
139
 
      bytes_per_scan_line = mode_info.bytes_per_scan_line;
140
 
    }
141
 
 
142
 
  /* Draw some random data to screen.  */
143
 
  for (i = 0; i < 256 * 256; i++)
144
 
    {
145
 
      ptr[i] = i & 0x0F;
146
 
    }
147
 
 
148
 
  /* Draw white line to screen.  */
149
 
  for (i = 0; i < 100; i++)
150
 
    {
151
 
      ptr[mode_info.bytes_per_scan_line * 50 + i] = 0x0F;
152
 
    }
153
 
 
154
 
  /* Draw another white line to screen.  */
155
 
  grub_memset (ptr + bytes_per_scan_line * 51, 0x0f, bytes_per_scan_line);
156
 
 
157
 
  grub_getkey ();
158
 
 
159
 
  grub_video_restore ();
160
 
 
161
 
  /* Restore old video mode.  */
162
 
  grub_vbe_set_video_mode (old_mode, 0);
163
 
 
164
 
  return grub_errno;
165
 
}
166
 
 
167
 
static grub_command_t cmd;
168
 
 
169
 
GRUB_MOD_INIT(vbetest)
170
 
{
171
 
  cmd = grub_register_command ("vbetest", grub_cmd_vbetest,
172
 
                               0, N_("Test VESA BIOS Extension 2.0+ support."));
173
 
}
174
 
 
175
 
GRUB_MOD_FINI(vbetest)
176
 
{
177
 
  grub_unregister_command (cmd);
178
 
}