a5bd9f6
From 8c5886df17cdfb148d4e17bddf38143ed65fe674 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Thu, 28 Jun 2012 15:27:54 +0200
a5bd9f6
Subject: [PATCH 001/364] 	Add monochrome text support (mda_text, aka
a5bd9f6
 `hercules' in grub-legacy).
a5bd9f6
a5bd9f6
	* grub-core/Makefile.core.def (mda_text): New module.
a5bd9f6
	* grub-core/lib/legacy_parse.c (grub_legacy_parse): Support `hercules'.
a5bd9f6
	* grub-core/term/i386/vga_common.c (grub_console_cur_color): Moved to ..
a5bd9f6
	* grub-core/term/i386/pc/vga_text.c (cur_color): ... here
a5bd9f6
	* grub-core/term/i386/pc/console.c (grub_console_cur_color): ... and
a5bd9f6
	here.
a5bd9f6
	* grub-core/term/i386/vga_common.c (grub_console_getwh): Moved to ..
a5bd9f6
	* grub-core/term/i386/pc/vga_text.c (grub_console_getwh): ... here
a5bd9f6
	* grub-core/term/i386/pc/console.c (grub_console_getwh): ... and
a5bd9f6
	here.
a5bd9f6
	* grub-core/term/i386/vga_common.c (grub_console_setcolorstate): Moved
a5bd9f6
	to ..
a5bd9f6
	* grub-core/term/i386/pc/vga_text.c (grub_console_setcolorstate):
a5bd9f6
	... here
a5bd9f6
	* grub-core/term/i386/pc/console.c (grub_console_setcolorstate): ... and
a5bd9f6
	here.
a5bd9f6
	* grub-core/term/i386/vga_common.c: Removed.
a5bd9f6
	* include/grub/i386/vga_common.h: Likewise.
a5bd9f6
	* include/grub/vga.h (grub_vga_cr_bw_write): New function.
a5bd9f6
	(grub_vga_cr_bw_read): Likewise.
a5bd9f6
	* include/grub/vgaregs.h (GRUB_VGA_IO_CR_BW_INDEX): New enum value.
a5bd9f6
	(GRUB_VGA_IO_CR_BW_DATA): Likewise.
a5bd9f6
	* grub-core/term/i386/pc/vga_text.c [MODE_MDA]: Call
a5bd9f6
	grub_vga_cr_bw_read/grub_vga_cr_bw_write instead of
a5bd9f6
	grub_vga_cr_read/grub_vga_cr_write.
a5bd9f6
	(grub_vga_text_setcolorstate) [MODE_MDA]: Ignore color.
a5bd9f6
---
a5bd9f6
 ChangeLog                         |  31 +++++++++
a5bd9f6
 grub-core/Makefile.core.def       |  12 ++--
a5bd9f6
 grub-core/lib/legacy_parse.c      |  15 ++--
a5bd9f6
 grub-core/term/i386/pc/console.c  |  27 ++++++++
a5bd9f6
 grub-core/term/i386/pc/vga_text.c | 141 +++++++++++++++++++++++++++++++++-----
a5bd9f6
 grub-core/term/i386/vga_common.c  |  48 -------------
a5bd9f6
 include/grub/i386/pc/console.h    |   1 -
a5bd9f6
 include/grub/i386/vga_common.h    |  32 ---------
a5bd9f6
 include/grub/vga.h                |  14 ++++
a5bd9f6
 include/grub/vgaregs.h            |   2 +
a5bd9f6
 10 files changed, 213 insertions(+), 110 deletions(-)
a5bd9f6
 delete mode 100644 grub-core/term/i386/vga_common.c
a5bd9f6
 delete mode 100644 include/grub/i386/vga_common.h
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 81bdae9..f6e864a 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,3 +1,34 @@
a5bd9f6
+2012-06-28  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
+	Add monochrome text support (mda_text, aka `hercules' in grub-legacy).
a5bd9f6
+
a5bd9f6
+	* grub-core/Makefile.core.def (mda_text): New module.
a5bd9f6
+	* grub-core/lib/legacy_parse.c (grub_legacy_parse): Support `hercules'.
a5bd9f6
+	* grub-core/term/i386/vga_common.c (grub_console_cur_color): Moved to ..
a5bd9f6
+	* grub-core/term/i386/pc/vga_text.c (cur_color): ... here
a5bd9f6
+	* grub-core/term/i386/pc/console.c (grub_console_cur_color): ... and
a5bd9f6
+	here.
a5bd9f6
+	* grub-core/term/i386/vga_common.c (grub_console_getwh): Moved to ..
a5bd9f6
+	* grub-core/term/i386/pc/vga_text.c (grub_console_getwh): ... here
a5bd9f6
+	* grub-core/term/i386/pc/console.c (grub_console_getwh): ... and
a5bd9f6
+	here.
a5bd9f6
+	* grub-core/term/i386/vga_common.c (grub_console_setcolorstate): Moved
a5bd9f6
+	to ..
a5bd9f6
+	* grub-core/term/i386/pc/vga_text.c (grub_console_setcolorstate):
a5bd9f6
+	... here
a5bd9f6
+	* grub-core/term/i386/pc/console.c (grub_console_setcolorstate): ... and
a5bd9f6
+	here.
a5bd9f6
+	* grub-core/term/i386/vga_common.c: Removed.
a5bd9f6
+	* include/grub/i386/vga_common.h: Likewise.
a5bd9f6
+	* include/grub/vga.h (grub_vga_cr_bw_write): New function.
a5bd9f6
+	(grub_vga_cr_bw_read): Likewise.
a5bd9f6
+	* include/grub/vgaregs.h (GRUB_VGA_IO_CR_BW_INDEX): New enum value.
a5bd9f6
+	(GRUB_VGA_IO_CR_BW_DATA): Likewise.
a5bd9f6
+	* grub-core/term/i386/pc/vga_text.c [MODE_MDA]: Call
a5bd9f6
+	grub_vga_cr_bw_read/grub_vga_cr_bw_write instead of
a5bd9f6
+	grub_vga_cr_read/grub_vga_cr_write.
a5bd9f6
+	(grub_vga_text_setcolorstate) [MODE_MDA]: Ignore color.
a5bd9f6
+
a5bd9f6
 2012-06-27  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
 	* configure.ac: Bump version to 2.00.
a5bd9f6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
a5bd9f6
index 39e77a4..5c2fcc2 100644
a5bd9f6
--- a/grub-core/Makefile.core.def
a5bd9f6
+++ b/grub-core/Makefile.core.def
a5bd9f6
@@ -123,9 +123,6 @@ kernel = {
a5bd9f6
   i386_coreboot_multiboot_qemu = kern/i386/coreboot/init.c;
a5bd9f6
   i386_coreboot_multiboot_qemu = term/i386/pc/vga_text.c;
a5bd9f6
 
a5bd9f6
-  i386_coreboot_multiboot_qemu = term/i386/vga_common.c;
a5bd9f6
-  i386_pc = term/i386/vga_common.c;
a5bd9f6
-
a5bd9f6
   x86 = kern/i386/pit.c;
a5bd9f6
 
a5bd9f6
   efi = disk/efi/efidisk.c;
a5bd9f6
@@ -175,7 +172,6 @@ kernel = {
a5bd9f6
   mips_qemu_mips = term/at_keyboard.c;
a5bd9f6
   mips_qemu_mips = commands/keylayouts.c;
a5bd9f6
   mips_qemu_mips = term/i386/pc/vga_text.c;
a5bd9f6
-  mips_qemu_mips = term/i386/vga_common.c;
a5bd9f6
   mips_qemu_mips = kern/vga_init.c;
a5bd9f6
 
a5bd9f6
   mips_arc = kern/mips/arc/init.c;
a5bd9f6
@@ -1591,11 +1587,17 @@ module = {
a5bd9f6
 module = {
a5bd9f6
   name = vga_text;
a5bd9f6
   common = term/i386/pc/vga_text.c;
a5bd9f6
-  common = term/i386/vga_common.c;
a5bd9f6
   enable = i386_pc;
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
 module = {
a5bd9f6
+  name = mda_text;
a5bd9f6
+  common = term/i386/pc/mda_text.c;
a5bd9f6
+  enable = i386_pc;
a5bd9f6
+  enable = i386_coreboot_multiboot_qemu;
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
+module = {
a5bd9f6
   name = video_cirrus;
a5bd9f6
   x86 = video/cirrus.c;
a5bd9f6
   enable = x86;
a5bd9f6
diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c
a5bd9f6
index 775eaad..14768b8 100644
a5bd9f6
--- a/grub-core/lib/legacy_parse.c
a5bd9f6
+++ b/grub-core/lib/legacy_parse.c
a5bd9f6
@@ -1,6 +1,6 @@
a5bd9f6
 /*
a5bd9f6
  *  GRUB  --  GRand Unified Bootloader
a5bd9f6
- *  Copyright (C) 1999,2000,2001,2002,2003,2004,2010  Free Software Foundation, Inc.
a5bd9f6
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2010,2012  Free Software Foundation, Inc.
a5bd9f6
  *
a5bd9f6
  *  GRUB is free software: you can redistribute it and/or modify
a5bd9f6
  *  it under the terms of the GNU General Public License as published by
a5bd9f6
@@ -290,7 +290,7 @@ static struct legacy_command legacy_commands[] =
a5bd9f6
      " default values are COM1, 9600, 8N1."},
a5bd9f6
     /* FIXME: setkey unsupported.  */    /* NUL_TERMINATE */
a5bd9f6
     /* NOTE: setup unsupported.  */
a5bd9f6
-    /* FIXME: --no-echo, --no-edit, hercules unsupported.  */
a5bd9f6
+    /* FIXME: --no-echo, --no-edit unsupported.  */
a5bd9f6
     /* NOTE: both terminals are activated so --silent and --timeout
a5bd9f6
        are useless.  */
a5bd9f6
     {"terminal", NULL, NULL, 0, 0, {}, FLAG_TERMINAL | FLAG_IGNORE_REST,
a5bd9f6
@@ -507,8 +507,8 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
a5bd9f6
       int dumb = 0, lines = 24;
a5bd9f6
 #ifdef TODO
a5bd9f6
       int no_echo = 0, no_edit = 0;
a5bd9f6
-      int hercules = 0;
a5bd9f6
 #endif
a5bd9f6
+      int hercules = 0;
a5bd9f6
       int console = 0, serial = 0;
a5bd9f6
       /* Big enough for any possible resulting command. */
a5bd9f6
       char outbuf[256] = "";
a5bd9f6
@@ -541,10 +541,8 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
a5bd9f6
 
a5bd9f6
 	  if (grub_memcmp (ptr, "serial", sizeof ("serial") - 1) == 0)
a5bd9f6
 	    serial = 1;
a5bd9f6
-#ifdef TODO
a5bd9f6
 	  if (grub_memcmp (ptr, "hercules", sizeof ("hercules") - 1) == 0)
a5bd9f6
 	    hercules = 1;
a5bd9f6
-#endif
a5bd9f6
 	  while (*ptr && !grub_isspace (*ptr))
a5bd9f6
 	    ptr++;
a5bd9f6
 	  while (*ptr && grub_isspace (*ptr))
a5bd9f6
@@ -561,7 +559,7 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
a5bd9f6
 	  grub_strcpy (outptr, "serial ");
a5bd9f6
 	  outptr += grub_strlen (outptr);
a5bd9f6
 	}
a5bd9f6
-      if (console)
a5bd9f6
+      if (console || hercules)
a5bd9f6
 	{
a5bd9f6
 	  grub_strcpy (outptr, "console ");
a5bd9f6
 	  outptr += grub_strlen (outptr);
a5bd9f6
@@ -578,6 +576,11 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
a5bd9f6
 	  grub_strcpy (outptr, "console ");
a5bd9f6
 	  outptr += grub_strlen (outptr);
a5bd9f6
 	}
a5bd9f6
+      if (hercules)
a5bd9f6
+	{
a5bd9f6
+	  grub_strcpy (outptr, "mda_text ");
a5bd9f6
+	  outptr += grub_strlen (outptr);
a5bd9f6
+	}
a5bd9f6
       grub_strcpy (outptr, "; ");
a5bd9f6
       outptr += grub_strlen (outptr);
a5bd9f6
       if (serial)
a5bd9f6
diff --git a/grub-core/term/i386/pc/console.c b/grub-core/term/i386/pc/console.c
a5bd9f6
index 7cf5ffc..a681435 100644
a5bd9f6
--- a/grub-core/term/i386/pc/console.c
a5bd9f6
+++ b/grub-core/term/i386/pc/console.c
a5bd9f6
@@ -22,6 +22,8 @@
a5bd9f6
 #include <grub/types.h>
a5bd9f6
 #include <grub/machine/int.h>
a5bd9f6
 
a5bd9f6
+static grub_uint8_t grub_console_cur_color = 0x7;
a5bd9f6
+
a5bd9f6
 static void
a5bd9f6
 int10_9 (grub_uint8_t ch, grub_uint16_t n)
a5bd9f6
 {
a5bd9f6
@@ -250,6 +252,31 @@ grub_console_getkeystatus (struct grub_term_input *term __attribute__ ((unused))
a5bd9f6
   return bios_data_area->keyboard_flag_lower & ~0x80;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
+static grub_uint16_t
a5bd9f6
+grub_console_getwh (struct grub_term_output *term __attribute__ ((unused)))
a5bd9f6
+{
a5bd9f6
+  return (80 << 8) | 25;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static void
a5bd9f6
+grub_console_setcolorstate (struct grub_term_output *term,
a5bd9f6
+			    grub_term_color_state state)
a5bd9f6
+{
a5bd9f6
+  switch (state) {
a5bd9f6
+    case GRUB_TERM_COLOR_STANDARD:
a5bd9f6
+      grub_console_cur_color = GRUB_TERM_DEFAULT_STANDARD_COLOR & 0x7f;
a5bd9f6
+      break;
a5bd9f6
+    case GRUB_TERM_COLOR_NORMAL:
a5bd9f6
+      grub_console_cur_color = term->normal_color & 0x7f;
a5bd9f6
+      break;
a5bd9f6
+    case GRUB_TERM_COLOR_HIGHLIGHT:
a5bd9f6
+      grub_console_cur_color = term->highlight_color & 0x7f;
a5bd9f6
+      break;
a5bd9f6
+    default:
a5bd9f6
+      break;
a5bd9f6
+  }
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
 static struct grub_term_input grub_console_term_input =
a5bd9f6
   {
a5bd9f6
     .name = "console",
a5bd9f6
diff --git a/grub-core/term/i386/pc/vga_text.c b/grub-core/term/i386/pc/vga_text.c
a5bd9f6
index c934c68..d1e4ef9 100644
a5bd9f6
--- a/grub-core/term/i386/pc/vga_text.c
a5bd9f6
+++ b/grub-core/term/i386/pc/vga_text.c
a5bd9f6
@@ -17,10 +17,17 @@
a5bd9f6
  */
a5bd9f6
 
a5bd9f6
 #include <grub/dl.h>
a5bd9f6
-#include <grub/i386/vga_common.h>
a5bd9f6
 #include <grub/cpu/io.h>
a5bd9f6
 #include <grub/types.h>
a5bd9f6
 #include <grub/vga.h>
a5bd9f6
+#include <grub/term.h>
a5bd9f6
+
a5bd9f6
+/* MODESET is used for testing to force monochrome or colour mode.
a5bd9f6
+   You shouldn't use mda_text on vga.
a5bd9f6
+ */
a5bd9f6
+#ifdef MODESET
a5bd9f6
+#include <grub/machine/int.h>
a5bd9f6
+#endif
a5bd9f6
 
a5bd9f6
 #if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
a5bd9f6
 #include <grub/machine/console.h>
a5bd9f6
@@ -35,10 +42,21 @@ static int grub_curr_x, grub_curr_y;
a5bd9f6
 
a5bd9f6
 #ifdef __mips__
a5bd9f6
 #define VGA_TEXT_SCREEN		((grub_uint16_t *) 0xb00b8000)
a5bd9f6
+#define cr_read grub_vga_cr_read
a5bd9f6
+#define cr_write grub_vga_cr_write
a5bd9f6
+#elif defined (MODE_MDA)
a5bd9f6
+#define VGA_TEXT_SCREEN		((grub_uint16_t *) 0xb0000)
a5bd9f6
+#define cr_read grub_vga_cr_bw_read
a5bd9f6
+#define cr_write grub_vga_cr_bw_write
a5bd9f6
+static grub_uint8_t cur_color;
a5bd9f6
 #else
a5bd9f6
 #define VGA_TEXT_SCREEN		((grub_uint16_t *) 0xb8000)
a5bd9f6
+#define cr_read grub_vga_cr_read
a5bd9f6
+#define cr_write grub_vga_cr_write
a5bd9f6
 #endif
a5bd9f6
 
a5bd9f6
+static grub_uint8_t cur_color = 0x7;
a5bd9f6
+
a5bd9f6
 static void
a5bd9f6
 screen_write_char (int x, int y, short c)
a5bd9f6
 {
a5bd9f6
@@ -55,8 +73,8 @@ static void
a5bd9f6
 update_cursor (void)
a5bd9f6
 {
a5bd9f6
   unsigned int pos = grub_curr_y * COLS + grub_curr_x;
a5bd9f6
-  grub_vga_cr_write (pos >> 8, GRUB_VGA_CR_CURSOR_ADDR_HIGH);
a5bd9f6
-  grub_vga_cr_write (pos & 0xFF, GRUB_VGA_CR_CURSOR_ADDR_LOW);
a5bd9f6
+  cr_write (pos >> 8, GRUB_VGA_CR_CURSOR_ADDR_HIGH);
a5bd9f6
+  cr_write (pos & 0xFF, GRUB_VGA_CR_CURSOR_ADDR_LOW);
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static void
a5bd9f6
@@ -72,7 +90,7 @@ inc_y (void)
a5bd9f6
         for (x = 0; x < COLS; x++)
a5bd9f6
           screen_write_char (x, y, screen_read_char (x, y + 1));
a5bd9f6
       for (x = 0; x < COLS; x++)
a5bd9f6
-	screen_write_char (x, ROWS - 1, ' ' | (grub_console_cur_color << 8));
a5bd9f6
+	screen_write_char (x, ROWS - 1, ' ' | (cur_color << 8));
a5bd9f6
     }
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
@@ -103,7 +121,7 @@ grub_vga_text_putchar (struct grub_term_output *term __attribute__ ((unused)),
a5bd9f6
 	break;
a5bd9f6
       default:
a5bd9f6
 	screen_write_char (grub_curr_x, grub_curr_y,
a5bd9f6
-			   c->base | (grub_console_cur_color << 8));
a5bd9f6
+			   c->base | (cur_color << 8));
a5bd9f6
 	inc_x ();
a5bd9f6
     }
a5bd9f6
 
a5bd9f6
@@ -130,7 +148,7 @@ grub_vga_text_cls (struct grub_term_output *term)
a5bd9f6
 {
a5bd9f6
   int i;
a5bd9f6
   for (i = 0; i < ROWS * COLS; i++)
a5bd9f6
-    VGA_TEXT_SCREEN[i] = grub_cpu_to_le16 (' ' | (grub_console_cur_color << 8));
a5bd9f6
+    VGA_TEXT_SCREEN[i] = grub_cpu_to_le16 (' ' | (cur_color << 8));
a5bd9f6
   grub_vga_text_gotoxy (term, 0, 0);
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
@@ -139,49 +157,136 @@ grub_vga_text_setcursor (struct grub_term_output *term __attribute__ ((unused)),
a5bd9f6
 			 int on)
a5bd9f6
 {
a5bd9f6
   grub_uint8_t old;
a5bd9f6
-  old = grub_vga_cr_read (GRUB_VGA_CR_CURSOR_START);
a5bd9f6
+  old = cr_read (GRUB_VGA_CR_CURSOR_START);
a5bd9f6
   if (on)
a5bd9f6
-    grub_vga_cr_write (old & ~GRUB_VGA_CR_CURSOR_START_DISABLE,
a5bd9f6
-		       GRUB_VGA_CR_CURSOR_START);
a5bd9f6
+    cr_write (old & ~GRUB_VGA_CR_CURSOR_START_DISABLE,
a5bd9f6
+	      GRUB_VGA_CR_CURSOR_START);
a5bd9f6
   else
a5bd9f6
-    grub_vga_cr_write (old | GRUB_VGA_CR_CURSOR_START_DISABLE,
a5bd9f6
-		       GRUB_VGA_CR_CURSOR_START);
a5bd9f6
+    cr_write (old | GRUB_VGA_CR_CURSOR_START_DISABLE,
a5bd9f6
+	      GRUB_VGA_CR_CURSOR_START);
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static grub_err_t
a5bd9f6
-grub_vga_text_init_fini (struct grub_term_output *term)
a5bd9f6
+grub_vga_text_init (struct grub_term_output *term)
a5bd9f6
 {
a5bd9f6
+#ifdef MODESET
a5bd9f6
+  struct grub_bios_int_registers regs;
a5bd9f6
+  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
a5bd9f6
+
a5bd9f6
+#ifdef MODE_MDA
a5bd9f6
+  regs.eax = 7;
a5bd9f6
+#else
a5bd9f6
+  regs.eax = 3;
a5bd9f6
+#endif
a5bd9f6
+  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
a5bd9f6
+  grub_bios_interrupt (0x10, ®s;;
a5bd9f6
+#endif
a5bd9f6
   grub_vga_text_cls (term);
a5bd9f6
   return 0;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_vga_text_fini (struct grub_term_output *term)
a5bd9f6
+{
a5bd9f6
+#ifdef MODESET
a5bd9f6
+  struct grub_bios_int_registers regs;
a5bd9f6
+  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
a5bd9f6
+
a5bd9f6
+  regs.eax = 3;
a5bd9f6
+  regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
a5bd9f6
+  grub_bios_interrupt (0x10, ®s;;
a5bd9f6
+#endif
a5bd9f6
+  grub_vga_text_cls (term);
a5bd9f6
+  return 0;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_uint16_t
a5bd9f6
+grub_vga_text_getwh (struct grub_term_output *term __attribute__ ((unused)))
a5bd9f6
+{
a5bd9f6
+  return (80 << 8) | 25;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+#ifndef MODE_MDA
a5bd9f6
+
a5bd9f6
+static void
a5bd9f6
+grub_vga_text_setcolorstate (struct grub_term_output *term,
a5bd9f6
+			    grub_term_color_state state)
a5bd9f6
+{
a5bd9f6
+  switch (state) {
a5bd9f6
+    case GRUB_TERM_COLOR_STANDARD:
a5bd9f6
+      cur_color = GRUB_TERM_DEFAULT_STANDARD_COLOR & 0x7f;
a5bd9f6
+      break;
a5bd9f6
+    case GRUB_TERM_COLOR_NORMAL:
a5bd9f6
+      cur_color = term->normal_color & 0x7f;
a5bd9f6
+      break;
a5bd9f6
+    case GRUB_TERM_COLOR_HIGHLIGHT:
a5bd9f6
+      cur_color = term->highlight_color & 0x7f;
a5bd9f6
+      break;
a5bd9f6
+    default:
a5bd9f6
+      break;
a5bd9f6
+  }
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+#else
a5bd9f6
+static void
a5bd9f6
+grub_vga_text_setcolorstate (struct grub_term_output *term __attribute__ ((unused)),
a5bd9f6
+			     grub_term_color_state state)
a5bd9f6
+{
a5bd9f6
+  switch (state) {
a5bd9f6
+    case GRUB_TERM_COLOR_STANDARD:
a5bd9f6
+      cur_color = 0x07;
a5bd9f6
+      break;
a5bd9f6
+    case GRUB_TERM_COLOR_NORMAL:
a5bd9f6
+      cur_color = 0x07;
a5bd9f6
+      break;
a5bd9f6
+    case GRUB_TERM_COLOR_HIGHLIGHT:
a5bd9f6
+      cur_color = 0x70;
a5bd9f6
+      break;
a5bd9f6
+    default:
a5bd9f6
+      break;
a5bd9f6
+  }
a5bd9f6
+}
a5bd9f6
+#endif
a5bd9f6
+
a5bd9f6
 static struct grub_term_output grub_vga_text_term =
a5bd9f6
   {
a5bd9f6
+#ifdef MODE_MDA
a5bd9f6
+    .name = "mda_text",
a5bd9f6
+#else
a5bd9f6
     .name = "vga_text",
a5bd9f6
-    .init = grub_vga_text_init_fini,
a5bd9f6
-    .fini = grub_vga_text_init_fini,
a5bd9f6
+#endif
a5bd9f6
+    .init = grub_vga_text_init,
a5bd9f6
+    .fini = grub_vga_text_fini,
a5bd9f6
     .putchar = grub_vga_text_putchar,
a5bd9f6
-    .getwh = grub_console_getwh,
a5bd9f6
+    .getwh = grub_vga_text_getwh,
a5bd9f6
     .getxy = grub_vga_text_getxy,
a5bd9f6
     .gotoxy = grub_vga_text_gotoxy,
a5bd9f6
     .cls = grub_vga_text_cls,
a5bd9f6
-    .setcolorstate = grub_console_setcolorstate,
a5bd9f6
+    .setcolorstate = grub_vga_text_setcolorstate,
a5bd9f6
     .setcursor = grub_vga_text_setcursor,
a5bd9f6
     .flags = GRUB_TERM_CODE_TYPE_CP437,
a5bd9f6
     .normal_color = GRUB_TERM_DEFAULT_NORMAL_COLOR,
a5bd9f6
     .highlight_color = GRUB_TERM_DEFAULT_HIGHLIGHT_COLOR,
a5bd9f6
   };
a5bd9f6
 
a5bd9f6
-#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
a5bd9f6
+#ifdef MODE_MDA
a5bd9f6
+GRUB_MOD_INIT(mda_text)
a5bd9f6
+#elif defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
a5bd9f6
 void grub_vga_text_init (void)
a5bd9f6
 #else
a5bd9f6
 GRUB_MOD_INIT(vga_text)
a5bd9f6
 #endif
a5bd9f6
 {
a5bd9f6
+#ifdef MODE_MDA
a5bd9f6
+  grub_term_register_output ("mda_text", &grub_vga_text_term);
a5bd9f6
+#else
a5bd9f6
   grub_term_register_output ("vga_text", &grub_vga_text_term);
a5bd9f6
+#endif
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
-#if defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
a5bd9f6
+#ifdef MODE_MDA
a5bd9f6
+GRUB_MOD_FINI(mda_text)
a5bd9f6
+#elif defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) || defined (GRUB_MACHINE_MIPS_QEMU_MIPS) || defined (GRUB_MACHINE_MULTIBOOT)
a5bd9f6
 void grub_vga_text_fini (void)
a5bd9f6
 #else
a5bd9f6
 GRUB_MOD_FINI(vga_text)
a5bd9f6
diff --git a/grub-core/term/i386/vga_common.c b/grub-core/term/i386/vga_common.c
a5bd9f6
deleted file mode 100644
a5bd9f6
index 0c21769..0000000
a5bd9f6
--- a/grub-core/term/i386/vga_common.c
a5bd9f6
+++ /dev/null
a5bd9f6
@@ -1,48 +0,0 @@
a5bd9f6
-/*
a5bd9f6
- *  GRUB  --  GRand Unified Bootloader
a5bd9f6
- *  Copyright (C) 2002,2003,2005,2007,2008  Free Software Foundation, Inc.
a5bd9f6
- *
a5bd9f6
- *  GRUB is free software: you can redistribute it and/or modify
a5bd9f6
- *  it under the terms of the GNU General Public License as published by
a5bd9f6
- *  the Free Software Foundation, either version 3 of the License, or
a5bd9f6
- *  (at your option) any later version.
a5bd9f6
- *
a5bd9f6
- *  GRUB is distributed in the hope that it will be useful,
a5bd9f6
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a5bd9f6
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a5bd9f6
- *  GNU General Public License for more details.
a5bd9f6
- *
a5bd9f6
- *  You should have received a copy of the GNU General Public License
a5bd9f6
- *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
a5bd9f6
- */
a5bd9f6
-
a5bd9f6
-#include <grub/i386/vga_common.h>
a5bd9f6
-#include <grub/term.h>
a5bd9f6
-#include <grub/types.h>
a5bd9f6
-
a5bd9f6
-grub_uint8_t grub_console_cur_color = 0x7;
a5bd9f6
-
a5bd9f6
-grub_uint16_t
a5bd9f6
-grub_console_getwh (struct grub_term_output *term __attribute__ ((unused)))
a5bd9f6
-{
a5bd9f6
-  return (80 << 8) | 25;
a5bd9f6
-}
a5bd9f6
-
a5bd9f6
-void
a5bd9f6
-grub_console_setcolorstate (struct grub_term_output *term,
a5bd9f6
-			    grub_term_color_state state)
a5bd9f6
-{
a5bd9f6
-  switch (state) {
a5bd9f6
-    case GRUB_TERM_COLOR_STANDARD:
a5bd9f6
-      grub_console_cur_color = GRUB_TERM_DEFAULT_STANDARD_COLOR & 0x7f;
a5bd9f6
-      break;
a5bd9f6
-    case GRUB_TERM_COLOR_NORMAL:
a5bd9f6
-      grub_console_cur_color = term->normal_color & 0x7f;
a5bd9f6
-      break;
a5bd9f6
-    case GRUB_TERM_COLOR_HIGHLIGHT:
a5bd9f6
-      grub_console_cur_color = term->highlight_color & 0x7f;
a5bd9f6
-      break;
a5bd9f6
-    default:
a5bd9f6
-      break;
a5bd9f6
-  }
a5bd9f6
-}
a5bd9f6
diff --git a/include/grub/i386/pc/console.h b/include/grub/i386/pc/console.h
a5bd9f6
index f752b9a..191964f 100644
a5bd9f6
--- a/include/grub/i386/pc/console.h
a5bd9f6
+++ b/include/grub/i386/pc/console.h
a5bd9f6
@@ -24,7 +24,6 @@
a5bd9f6
 #include <grub/types.h>
a5bd9f6
 #include <grub/symbol.h>
a5bd9f6
 #include <grub/term.h>
a5bd9f6
-#include <grub/i386/vga_common.h>
a5bd9f6
 
a5bd9f6
 /* Initialize the console system.  */
a5bd9f6
 void grub_console_init (void);
a5bd9f6
diff --git a/include/grub/i386/vga_common.h b/include/grub/i386/vga_common.h
a5bd9f6
deleted file mode 100644
a5bd9f6
index 8727903..0000000
a5bd9f6
--- a/include/grub/i386/vga_common.h
a5bd9f6
+++ /dev/null
a5bd9f6
@@ -1,32 +0,0 @@
a5bd9f6
-/*
a5bd9f6
- *  GRUB  --  GRand Unified Bootloader
a5bd9f6
- *  Copyright (C) 2002,2005,2007,2008  Free Software Foundation, Inc.
a5bd9f6
- *
a5bd9f6
- *  GRUB is free software: you can redistribute it and/or modify
a5bd9f6
- *  it under the terms of the GNU General Public License as published by
a5bd9f6
- *  the Free Software Foundation, either version 3 of the License, or
a5bd9f6
- *  (at your option) any later version.
a5bd9f6
- *
a5bd9f6
- *  GRUB is distributed in the hope that it will be useful,
a5bd9f6
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a5bd9f6
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a5bd9f6
- *  GNU General Public License for more details.
a5bd9f6
- *
a5bd9f6
- *  You should have received a copy of the GNU General Public License
a5bd9f6
- *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
a5bd9f6
- */
a5bd9f6
-
a5bd9f6
-#ifndef GRUB_VGA_COMMON_CPU_HEADER
a5bd9f6
-#define GRUB_VGA_COMMON_CPU_HEADER	1
a5bd9f6
-
a5bd9f6
-#include <grub/types.h>
a5bd9f6
-#include <grub/symbol.h>
a5bd9f6
-#include <grub/term.h>
a5bd9f6
-
a5bd9f6
-extern grub_uint8_t grub_console_cur_color;
a5bd9f6
-
a5bd9f6
-grub_uint16_t grub_console_getwh (struct grub_term_output *term);
a5bd9f6
-void grub_console_setcolorstate (struct grub_term_output *term,
a5bd9f6
-				 grub_term_color_state state);
a5bd9f6
-
a5bd9f6
-#endif /* ! GRUB_VGA_COMMON_CPU_HEADER */
a5bd9f6
diff --git a/include/grub/vga.h b/include/grub/vga.h
a5bd9f6
index 81d40a1..1d8449c 100644
a5bd9f6
--- a/include/grub/vga.h
a5bd9f6
+++ b/include/grub/vga.h
a5bd9f6
@@ -57,6 +57,20 @@ grub_vga_cr_read (grub_uint8_t addr)
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static inline void
a5bd9f6
+grub_vga_cr_bw_write (grub_uint8_t val, grub_uint8_t addr)
a5bd9f6
+{
a5bd9f6
+  grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_INDEX);
a5bd9f6
+  grub_outb (val, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_DATA);
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static inline grub_uint8_t
a5bd9f6
+grub_vga_cr_bw_read (grub_uint8_t addr)
a5bd9f6
+{
a5bd9f6
+  grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_INDEX);
a5bd9f6
+  return grub_inb (GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_CR_BW_DATA);
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static inline void
a5bd9f6
 grub_vga_sr_write (grub_uint8_t val, grub_uint8_t addr)
a5bd9f6
 {
a5bd9f6
   grub_outb (addr, GRUB_MACHINE_PCI_IO_BASE + GRUB_VGA_IO_SR_INDEX);
a5bd9f6
diff --git a/include/grub/vgaregs.h b/include/grub/vgaregs.h
a5bd9f6
index a7b13ee..1a666a1 100644
a5bd9f6
--- a/include/grub/vgaregs.h
a5bd9f6
+++ b/include/grub/vgaregs.h
a5bd9f6
@@ -26,6 +26,8 @@
a5bd9f6
 
a5bd9f6
 enum
a5bd9f6
   {
a5bd9f6
+    GRUB_VGA_IO_CR_BW_INDEX = 0x3b4,
a5bd9f6
+    GRUB_VGA_IO_CR_BW_DATA = 0x3b5,
a5bd9f6
     GRUB_VGA_IO_ARX = 0x3c0,
a5bd9f6
     GRUB_VGA_IO_ARX_READ = 0x3c1,
a5bd9f6
     GRUB_VGA_IO_MISC_WRITE = 0x3c2,
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6