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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-02-08 11:39:26 UTC
  • mfrom: (17.6.26 experimental)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 104.
  • Revision ID: james.westby@ubuntu.com-20110208113926-clfs90haboyk9zip
Tags: 1.99~rc1-2
* Merge 1.98+20100804-13 and 1.98+20100804-14, updating translations:
  - Kazakh (Baurzhan Muftakhidinov / Timur Birsh).
* mkconfig_skip_dmcrypt.patch: Refer to GRUB_PRELOAD_MODULES rather than
  suggesting people write a /etc/grub.d/01_modules script (thanks, Jordan
  Uggla).
* Handle empty dir passed to grub_find_root_device_from_mountinfo; fixes
  grub-mkrelpath on btrfs subvolumes (LP: #712029).
* Add rootflags=subvol=<name> if / is on a btrfs subvolume (LP: #712029).
* Upload to unstable.

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