vbetest.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #include <grub/dl.h>
  20. #include <grub/env.h>
  21. #include <grub/misc.h>
  22. #include <grub/term.h>
  23. #include <grub/machine/init.h>
  24. #include <grub/machine/vbe.h>
  25. #include <grub/video.h>
  26. #include <grub/err.h>
  27. #include <grub/command.h>
  28. #include <grub/i18n.h>
  29. static grub_err_t
  30. grub_cmd_vbetest (grub_command_t cmd __attribute__ ((unused)),
  31. int argc __attribute__ ((unused)),
  32. char **args __attribute__ ((unused)))
  33. {
  34. grub_err_t err;
  35. char *modevar;
  36. struct grub_vbe_mode_info_block mode_info;
  37. struct grub_vbe_info_block controller_info;
  38. grub_uint32_t use_mode = GRUB_VBE_DEFAULT_VIDEO_MODE;
  39. grub_uint32_t old_mode;
  40. grub_uint8_t *framebuffer = 0;
  41. grub_uint32_t bytes_per_scan_line = 0;
  42. unsigned char *ptr;
  43. int i;
  44. grub_printf ("Probing for VESA BIOS Extension ... ");
  45. /* Check if VESA BIOS exists. */
  46. err = grub_vbe_probe (&controller_info);
  47. if (err != GRUB_ERR_NONE)
  48. return err;
  49. grub_printf ("found!\n");
  50. /* Dump out controller information. */
  51. grub_printf ("VBE signature = %c%c%c%c\n",
  52. controller_info.signature[0],
  53. controller_info.signature[1],
  54. controller_info.signature[2],
  55. controller_info.signature[3]);
  56. grub_printf ("VBE version = %d.%d\n",
  57. controller_info.version >> 8,
  58. controller_info.version & 0xFF);
  59. grub_printf ("OEM string ptr = %08x\n",
  60. controller_info.oem_string_ptr);
  61. grub_printf ("Total memory = %d\n",
  62. controller_info.total_memory);
  63. err = grub_vbe_get_video_mode (&old_mode);
  64. grub_printf ("Get video mode err = %04x\n", err);
  65. if (err == GRUB_ERR_NONE)
  66. grub_printf ("Old video mode = %04x\n", old_mode);
  67. else
  68. grub_errno = GRUB_ERR_NONE;
  69. /* Check existence of vbe_mode environment variable. */
  70. modevar = grub_env_get ("vbe_mode");
  71. if (modevar != 0)
  72. {
  73. unsigned long value;
  74. value = grub_strtoul (modevar, 0, 0);
  75. if (grub_errno == GRUB_ERR_NONE)
  76. use_mode = value;
  77. else
  78. grub_errno = GRUB_ERR_NONE;
  79. }
  80. err = grub_vbe_get_video_mode_info (use_mode, &mode_info);
  81. if (err != GRUB_ERR_NONE)
  82. return err;
  83. /* Dump out details about the mode being tested. */
  84. grub_printf ("mode: 0x%03x\n",
  85. use_mode);
  86. grub_printf ("width : %d\n",
  87. mode_info.x_resolution);
  88. grub_printf ("height: %d\n",
  89. mode_info.y_resolution);
  90. grub_printf ("memory model: %02x\n",
  91. mode_info.memory_model);
  92. grub_printf ("bytes/scanline: %d\n",
  93. mode_info.bytes_per_scan_line);
  94. grub_printf ("bytes/scanline (lin): %d\n",
  95. mode_info.lin_bytes_per_scan_line);
  96. grub_printf ("base address: %08x\n",
  97. mode_info.phys_base_addr);
  98. grub_printf ("red mask/pos: %d/%d\n",
  99. mode_info.red_mask_size,
  100. mode_info.red_field_position);
  101. grub_printf ("green mask/pos: %d/%d\n",
  102. mode_info.green_mask_size,
  103. mode_info.green_field_position);
  104. grub_printf ("blue mask/pos: %d/%d\n",
  105. mode_info.blue_mask_size,
  106. mode_info.blue_field_position);
  107. grub_printf ("Press any key to continue.\n");
  108. grub_getkey ();
  109. /* Setup GFX mode. */
  110. err = grub_vbe_set_video_mode (use_mode, &mode_info);
  111. if (err != GRUB_ERR_NONE)
  112. return err;
  113. /* Determine framebuffer address and how many bytes are in scan line. */
  114. framebuffer = (grub_uint8_t *) mode_info.phys_base_addr;
  115. ptr = framebuffer;
  116. if (controller_info.version >= 0x300)
  117. {
  118. bytes_per_scan_line = mode_info.lin_bytes_per_scan_line;
  119. }
  120. else
  121. {
  122. bytes_per_scan_line = mode_info.bytes_per_scan_line;
  123. }
  124. /* Draw some random data to screen. */
  125. for (i = 0; i < 256 * 256; i++)
  126. {
  127. ptr[i] = i & 0x0F;
  128. }
  129. /* Draw white line to screen. */
  130. for (i = 0; i < 100; i++)
  131. {
  132. ptr[mode_info.bytes_per_scan_line * 50 + i] = 0x0F;
  133. }
  134. /* Draw another white line to screen. */
  135. grub_memset (ptr + bytes_per_scan_line * 51, 0x0f, bytes_per_scan_line);
  136. grub_getkey ();
  137. grub_video_restore ();
  138. /* Restore old video mode. */
  139. grub_vbe_set_video_mode (old_mode, 0);
  140. return grub_errno;
  141. }
  142. static grub_command_t cmd;
  143. GRUB_MOD_INIT(vbetest)
  144. {
  145. cmd = grub_register_command ("vbetest", grub_cmd_vbetest,
  146. 0, N_("Test VESA BIOS Extension 2.0+ support."));
  147. }
  148. GRUB_MOD_FINI(vbetest)
  149. {
  150. grub_unregister_command (cmd);
  151. }