~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060105152040-b72i5pq1a82z22yi
Tags: upstream-1.92
ImportĀ upstreamĀ versionĀ 1.92

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  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 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program 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, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <grub/normal.h>
 
22
#include <grub/dl.h>
 
23
#include <grub/arg.h>
 
24
#include <grub/env.h>
 
25
#include <grub/misc.h>
 
26
#include <grub/term.h>
 
27
#include <grub/machine/init.h>
 
28
#include <grub/machine/vbe.h>
 
29
#include <grub/err.h>
 
30
 
 
31
static grub_err_t
 
32
grub_cmd_vbetest (struct grub_arg_list *state __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
  /* Restore old video mode.  */
 
161
  grub_vbe_set_video_mode (old_mode, 0);
 
162
 
 
163
  return grub_errno;
 
164
}
 
165
 
 
166
GRUB_MOD_INIT(vbetest)
 
167
{
 
168
  (void) mod;                   /* To stop warning.  */
 
169
  grub_register_command ("vbetest",
 
170
                         grub_cmd_vbetest,
 
171
                         GRUB_COMMAND_FLAG_BOTH,
 
172
                         "vbetest",
 
173
                         "Test VESA BIOS Extension 2.0+ support",
 
174
                         0);
 
175
}
 
176
 
 
177
GRUB_MOD_FINI(vbetest)
 
178
{
 
179
  grub_unregister_command ("vbetest");
 
180
}