vga_init.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010,2011 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __mips__
  19. #include <grub/pci.h>
  20. #include <grub/mm.h>
  21. #endif
  22. #include <grub/machine/kernel.h>
  23. #include <grub/misc.h>
  24. #include <grub/vga.h>
  25. static struct {grub_uint8_t r, g, b, a; } colors[] =
  26. {
  27. // {R, G, B, A}
  28. {0x00, 0x00, 0x00, 0xFF}, // 0 = black
  29. {0x00, 0x00, 0xA8, 0xFF}, // 1 = blue
  30. {0x00, 0xA8, 0x00, 0xFF}, // 2 = green
  31. {0x00, 0xA8, 0xA8, 0xFF}, // 3 = cyan
  32. {0xA8, 0x00, 0x00, 0xFF}, // 4 = red
  33. {0xA8, 0x00, 0xA8, 0xFF}, // 5 = magenta
  34. {0xA8, 0x54, 0x00, 0xFF}, // 6 = brown
  35. {0xA8, 0xA8, 0xA8, 0xFF}, // 7 = light gray
  36. {0x54, 0x54, 0x54, 0xFF}, // 8 = dark gray
  37. {0x54, 0x54, 0xFE, 0xFF}, // 9 = bright blue
  38. {0x54, 0xFE, 0x54, 0xFF}, // 10 = bright green
  39. {0x54, 0xFE, 0xFE, 0xFF}, // 11 = bright cyan
  40. {0xFE, 0x54, 0x54, 0xFF}, // 12 = bright red
  41. {0xFE, 0x54, 0xFE, 0xFF}, // 13 = bright magenta
  42. {0xFE, 0xFE, 0x54, 0xFF}, // 14 = yellow
  43. {0xFE, 0xFE, 0xFE, 0xFF} // 15 = white
  44. };
  45. #include <ascii.h>
  46. #ifdef __mips__
  47. #define VGA_ADDR 0xb00a0000
  48. #else
  49. #define VGA_ADDR 0xa0000
  50. #endif
  51. static void
  52. load_font (void)
  53. {
  54. unsigned i;
  55. grub_vga_gr_write (0 << 2, GRUB_VGA_GR_GR6);
  56. grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_NORMAL, GRUB_VGA_SR_MEMORY_MODE);
  57. grub_vga_sr_write (1 << GRUB_VGA_TEXT_FONT_PLANE,
  58. GRUB_VGA_SR_MAP_MASK_REGISTER);
  59. grub_vga_gr_write (0, GRUB_VGA_GR_DATA_ROTATE);
  60. grub_vga_gr_write (0, GRUB_VGA_GR_MODE);
  61. grub_vga_gr_write (0xff, GRUB_VGA_GR_BITMASK);
  62. for (i = 0; i < 128; i++)
  63. grub_memcpy ((void *) (VGA_ADDR + 32 * i), ascii_bitmaps + 16 * i, 16);
  64. }
  65. static void
  66. load_palette (void)
  67. {
  68. unsigned i;
  69. for (i = 0; i < 16; i++)
  70. grub_vga_write_arx (i, i);
  71. for (i = 0; i < ARRAY_SIZE (colors); i++)
  72. grub_vga_palette_write (i, colors[i].r, colors[i].g, colors[i].b);
  73. }
  74. void
  75. grub_qemu_init_cirrus (void)
  76. {
  77. grub_outb (GRUB_VGA_IO_MISC_COLOR,
  78. GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_MISC_WRITE);
  79. load_font ();
  80. grub_vga_gr_write (GRUB_VGA_GR_GR6_MMAP_CGA, GRUB_VGA_GR_GR6);
  81. grub_vga_gr_write (GRUB_VGA_GR_MODE_ODD_EVEN, GRUB_VGA_GR_MODE);
  82. grub_vga_sr_write (GRUB_VGA_SR_MEMORY_MODE_NORMAL, GRUB_VGA_SR_MEMORY_MODE);
  83. grub_vga_sr_write ((1 << GRUB_VGA_TEXT_TEXT_PLANE)
  84. | (1 << GRUB_VGA_TEXT_ATTR_PLANE),
  85. GRUB_VGA_SR_MAP_MASK_REGISTER);
  86. grub_vga_cr_write (15, GRUB_VGA_CR_CELL_HEIGHT);
  87. grub_vga_cr_write (79, GRUB_VGA_CR_HORIZ_END);
  88. grub_vga_cr_write (40, GRUB_VGA_CR_PITCH);
  89. int vert = 25 * 16;
  90. grub_vga_cr_write (vert & 0xff, GRUB_VGA_CR_VDISPLAY_END);
  91. grub_vga_cr_write (((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT1_SHIFT)
  92. & GRUB_VGA_CR_OVERFLOW_HEIGHT1_MASK)
  93. | ((vert >> GRUB_VGA_CR_OVERFLOW_HEIGHT2_SHIFT)
  94. & GRUB_VGA_CR_OVERFLOW_HEIGHT2_MASK),
  95. GRUB_VGA_CR_OVERFLOW);
  96. load_palette ();
  97. grub_vga_write_arx (GRUB_VGA_ARX_MODE_TEXT, GRUB_VGA_ARX_MODE);
  98. grub_vga_write_arx (0, GRUB_VGA_ARX_COLOR_SELECT);
  99. grub_vga_sr_write (GRUB_VGA_SR_CLOCKING_MODE_8_DOT_CLOCK,
  100. GRUB_VGA_SR_CLOCKING_MODE);
  101. grub_vga_cr_write (14, GRUB_VGA_CR_CURSOR_START);
  102. grub_vga_cr_write (15, GRUB_VGA_CR_CURSOR_END);
  103. grub_outb (0x20, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_ARX);
  104. }