video-vga.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. *
  6. * This file is part of the Linux kernel, and is made available under
  7. * the terms of the GNU General Public License version 2.
  8. *
  9. * ----------------------------------------------------------------------- */
  10. /*
  11. * arch/i386/boot/video-vga.c
  12. *
  13. * Common all-VGA modes
  14. */
  15. #include "boot.h"
  16. #include "video.h"
  17. static struct mode_info vga_modes[] = {
  18. { VIDEO_80x25, 80, 25 },
  19. { VIDEO_8POINT, 80, 50 },
  20. { VIDEO_80x43, 80, 43 },
  21. { VIDEO_80x28, 80, 28 },
  22. { VIDEO_80x30, 80, 30 },
  23. { VIDEO_80x34, 80, 34 },
  24. { VIDEO_80x60, 80, 60 },
  25. };
  26. static struct mode_info ega_modes[] = {
  27. { VIDEO_80x25, 80, 25 },
  28. { VIDEO_8POINT, 80, 43 },
  29. };
  30. static struct mode_info cga_modes[] = {
  31. { VIDEO_80x25, 80, 25 },
  32. };
  33. __videocard video_vga;
  34. /* Set basic 80x25 mode */
  35. static u8 vga_set_basic_mode(void)
  36. {
  37. u16 ax;
  38. u8 rows;
  39. u8 mode;
  40. #ifdef CONFIG_VIDEO_400_HACK
  41. if (adapter >= ADAPTER_VGA) {
  42. asm(INT10
  43. : : "a" (0x1202), "b" (0x0030)
  44. : "ecx", "edx", "esi", "edi");
  45. }
  46. #endif
  47. ax = 0x0f00;
  48. asm(INT10
  49. : "+a" (ax)
  50. : : "ebx", "ecx", "edx", "esi", "edi");
  51. mode = (u8)ax;
  52. set_fs(0);
  53. rows = rdfs8(0x484); /* rows minus one */
  54. #ifndef CONFIG_VIDEO_400_HACK
  55. if ((ax == 0x5003 || ax == 0x5007) &&
  56. (rows == 0 || rows == 24))
  57. return mode;
  58. #endif
  59. if (mode != 3 && mode != 7)
  60. mode = 3;
  61. /* Set the mode */
  62. asm volatile(INT10
  63. : : "a" (mode)
  64. : "ebx", "ecx", "edx", "esi", "edi");
  65. do_restore = 1;
  66. return mode;
  67. }
  68. static void vga_set_8font(void)
  69. {
  70. /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
  71. /* Set 8x8 font */
  72. asm volatile(INT10 : : "a" (0x1112), "b" (0));
  73. /* Use alternate print screen */
  74. asm volatile(INT10 : : "a" (0x1200), "b" (0x20));
  75. /* Turn off cursor emulation */
  76. asm volatile(INT10 : : "a" (0x1201), "b" (0x34));
  77. /* Cursor is scan lines 6-7 */
  78. asm volatile(INT10 : : "a" (0x0100), "c" (0x0607));
  79. }
  80. static void vga_set_14font(void)
  81. {
  82. /* Set 9x14 font - 80x28 on VGA */
  83. /* Set 9x14 font */
  84. asm volatile(INT10 : : "a" (0x1111), "b" (0));
  85. /* Turn off cursor emulation */
  86. asm volatile(INT10 : : "a" (0x1201), "b" (0x34));
  87. /* Cursor is scan lines 11-12 */
  88. asm volatile(INT10 : : "a" (0x0100), "c" (0x0b0c));
  89. }
  90. static void vga_set_80x43(void)
  91. {
  92. /* Set 80x43 mode on VGA (not EGA) */
  93. /* Set 350 scans */
  94. asm volatile(INT10 : : "a" (0x1201), "b" (0x30));
  95. /* Reset video mode */
  96. asm volatile(INT10 : : "a" (0x0003));
  97. vga_set_8font();
  98. }
  99. /* I/O address of the VGA CRTC */
  100. u16 vga_crtc(void)
  101. {
  102. return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
  103. }
  104. static void vga_set_480_scanlines(int end)
  105. {
  106. u16 crtc;
  107. u8 csel;
  108. crtc = vga_crtc();
  109. out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
  110. out_idx(0x0b, crtc, 0x06); /* Vertical total */
  111. out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
  112. out_idx(0xea, crtc, 0x10); /* Vertical sync start */
  113. out_idx(end, crtc, 0x12); /* Vertical display end */
  114. out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
  115. out_idx(0x04, crtc, 0x16); /* Vertical blank end */
  116. csel = inb(0x3cc);
  117. csel &= 0x0d;
  118. csel |= 0xe2;
  119. outb(csel, 0x3cc);
  120. }
  121. static void vga_set_80x30(void)
  122. {
  123. vga_set_480_scanlines(0xdf);
  124. }
  125. static void vga_set_80x34(void)
  126. {
  127. vga_set_14font();
  128. vga_set_480_scanlines(0xdb);
  129. }
  130. static void vga_set_80x60(void)
  131. {
  132. vga_set_8font();
  133. vga_set_480_scanlines(0xdf);
  134. }
  135. static int vga_set_mode(struct mode_info *mode)
  136. {
  137. /* Set the basic mode */
  138. vga_set_basic_mode();
  139. /* Override a possibly broken BIOS */
  140. force_x = mode->x;
  141. force_y = mode->y;
  142. switch (mode->mode) {
  143. case VIDEO_80x25:
  144. break;
  145. case VIDEO_8POINT:
  146. vga_set_8font();
  147. break;
  148. case VIDEO_80x43:
  149. vga_set_80x43();
  150. break;
  151. case VIDEO_80x28:
  152. vga_set_14font();
  153. break;
  154. case VIDEO_80x30:
  155. vga_set_80x30();
  156. break;
  157. case VIDEO_80x34:
  158. vga_set_80x34();
  159. break;
  160. case VIDEO_80x60:
  161. vga_set_80x60();
  162. break;
  163. }
  164. return 0;
  165. }
  166. /*
  167. * Note: this probe includes basic information required by all
  168. * systems. It should be executed first, by making sure
  169. * video-vga.c is listed first in the Makefile.
  170. */
  171. static int vga_probe(void)
  172. {
  173. static const char *card_name[] = {
  174. "CGA/MDA/HGC", "EGA", "VGA"
  175. };
  176. static struct mode_info *mode_lists[] = {
  177. cga_modes,
  178. ega_modes,
  179. vga_modes,
  180. };
  181. static int mode_count[] = {
  182. sizeof(cga_modes)/sizeof(struct mode_info),
  183. sizeof(ega_modes)/sizeof(struct mode_info),
  184. sizeof(vga_modes)/sizeof(struct mode_info),
  185. };
  186. u8 vga_flag;
  187. asm(INT10
  188. : "=b" (boot_params.screen_info.orig_video_ega_bx)
  189. : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
  190. : "ecx", "edx", "esi", "edi");
  191. /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
  192. if ((u8)boot_params.screen_info.orig_video_ega_bx != 0x10) {
  193. /* EGA/VGA */
  194. asm(INT10
  195. : "=a" (vga_flag)
  196. : "a" (0x1a00)
  197. : "ebx", "ecx", "edx", "esi", "edi");
  198. if (vga_flag == 0x1a) {
  199. adapter = ADAPTER_VGA;
  200. boot_params.screen_info.orig_video_isVGA = 1;
  201. } else {
  202. adapter = ADAPTER_EGA;
  203. }
  204. } else {
  205. adapter = ADAPTER_CGA;
  206. }
  207. video_vga.modes = mode_lists[adapter];
  208. video_vga.card_name = card_name[adapter];
  209. return mode_count[adapter];
  210. }
  211. __videocard video_vga =
  212. {
  213. .card_name = "VGA",
  214. .probe = vga_probe,
  215. .set_mode = vga_set_mode,
  216. };