video-vga.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 volatile(INT10
  43. : : "a" (0x1202), "b" (0x0030)
  44. : "ecx", "edx", "esi", "edi");
  45. }
  46. #endif
  47. ax = 0x0f00;
  48. asm volatile(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. ax = mode;
  63. asm volatile(INT10
  64. : "+a" (ax)
  65. : : "ebx", "ecx", "edx", "esi", "edi");
  66. do_restore = 1;
  67. return mode;
  68. }
  69. static void vga_set_8font(void)
  70. {
  71. /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
  72. /* Set 8x8 font */
  73. asm volatile(INT10 : : "a" (0x1112), "b" (0));
  74. /* Use alternate print screen */
  75. asm volatile(INT10 : : "a" (0x1200), "b" (0x20));
  76. /* Turn off cursor emulation */
  77. asm volatile(INT10 : : "a" (0x1201), "b" (0x34));
  78. /* Cursor is scan lines 6-7 */
  79. asm volatile(INT10 : : "a" (0x0100), "c" (0x0607));
  80. }
  81. static void vga_set_14font(void)
  82. {
  83. /* Set 9x14 font - 80x28 on VGA */
  84. /* Set 9x14 font */
  85. asm volatile(INT10 : : "a" (0x1111), "b" (0));
  86. /* Turn off cursor emulation */
  87. asm volatile(INT10 : : "a" (0x1201), "b" (0x34));
  88. /* Cursor is scan lines 11-12 */
  89. asm volatile(INT10 : : "a" (0x0100), "c" (0x0b0c));
  90. }
  91. static void vga_set_80x43(void)
  92. {
  93. /* Set 80x43 mode on VGA (not EGA) */
  94. /* Set 350 scans */
  95. asm volatile(INT10 : : "a" (0x1201), "b" (0x30));
  96. /* Reset video mode */
  97. asm volatile(INT10 : : "a" (0x0003));
  98. vga_set_8font();
  99. }
  100. /* I/O address of the VGA CRTC */
  101. u16 vga_crtc(void)
  102. {
  103. return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
  104. }
  105. static void vga_set_480_scanlines(int end)
  106. {
  107. u16 crtc;
  108. u8 csel;
  109. crtc = vga_crtc();
  110. out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
  111. out_idx(0x0b, crtc, 0x06); /* Vertical total */
  112. out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
  113. out_idx(0xea, crtc, 0x10); /* Vertical sync start */
  114. out_idx(end, crtc, 0x12); /* Vertical display end */
  115. out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
  116. out_idx(0x04, crtc, 0x16); /* Vertical blank end */
  117. csel = inb(0x3cc);
  118. csel &= 0x0d;
  119. csel |= 0xe2;
  120. outb(csel, 0x3cc);
  121. }
  122. static void vga_set_80x30(void)
  123. {
  124. vga_set_480_scanlines(0xdf);
  125. }
  126. static void vga_set_80x34(void)
  127. {
  128. vga_set_14font();
  129. vga_set_480_scanlines(0xdb);
  130. }
  131. static void vga_set_80x60(void)
  132. {
  133. vga_set_8font();
  134. vga_set_480_scanlines(0xdf);
  135. }
  136. static int vga_set_mode(struct mode_info *mode)
  137. {
  138. /* Set the basic mode */
  139. vga_set_basic_mode();
  140. /* Override a possibly broken BIOS */
  141. force_x = mode->x;
  142. force_y = mode->y;
  143. switch (mode->mode) {
  144. case VIDEO_80x25:
  145. break;
  146. case VIDEO_8POINT:
  147. vga_set_8font();
  148. break;
  149. case VIDEO_80x43:
  150. vga_set_80x43();
  151. break;
  152. case VIDEO_80x28:
  153. vga_set_14font();
  154. break;
  155. case VIDEO_80x30:
  156. vga_set_80x30();
  157. break;
  158. case VIDEO_80x34:
  159. vga_set_80x34();
  160. break;
  161. case VIDEO_80x60:
  162. vga_set_80x60();
  163. break;
  164. }
  165. return 0;
  166. }
  167. /*
  168. * Note: this probe includes basic information required by all
  169. * systems. It should be executed first, by making sure
  170. * video-vga.c is listed first in the Makefile.
  171. */
  172. static int vga_probe(void)
  173. {
  174. static const char *card_name[] = {
  175. "CGA/MDA/HGC", "EGA", "VGA"
  176. };
  177. static struct mode_info *mode_lists[] = {
  178. cga_modes,
  179. ega_modes,
  180. vga_modes,
  181. };
  182. static int mode_count[] = {
  183. sizeof(cga_modes)/sizeof(struct mode_info),
  184. sizeof(ega_modes)/sizeof(struct mode_info),
  185. sizeof(vga_modes)/sizeof(struct mode_info),
  186. };
  187. u8 vga_flag;
  188. asm(INT10
  189. : "=b" (boot_params.screen_info.orig_video_ega_bx)
  190. : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
  191. : "ecx", "edx", "esi", "edi");
  192. /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
  193. if ((u8)boot_params.screen_info.orig_video_ega_bx != 0x10) {
  194. /* EGA/VGA */
  195. asm(INT10
  196. : "=a" (vga_flag)
  197. : "a" (0x1a00)
  198. : "ebx", "ecx", "edx", "esi", "edi");
  199. if (vga_flag == 0x1a) {
  200. adapter = ADAPTER_VGA;
  201. boot_params.screen_info.orig_video_isVGA = 1;
  202. } else {
  203. adapter = ADAPTER_EGA;
  204. }
  205. } else {
  206. adapter = ADAPTER_CGA;
  207. }
  208. video_vga.modes = mode_lists[adapter];
  209. video_vga.card_name = card_name[adapter];
  210. return mode_count[adapter];
  211. }
  212. __videocard video_vga =
  213. {
  214. .card_name = "VGA",
  215. .probe = vga_probe,
  216. .set_mode = vga_set_mode,
  217. };