Blame SOURCES/0343-grub-core-term-arc-console.c-Assume-that-console-is-.patch

f96e0b
From 03e23ea91dfeb59bfcdf6545275e6bea68b6f6a8 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Wed, 24 Apr 2013 18:39:00 +0200
f96e0b
Subject: [PATCH 343/482] 	* grub-core/term/arc/console.c: Assume that
f96e0b
 console is 80x24 vt100 if 	it's serial.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                    |  5 +++
f96e0b
 grub-core/term/arc/console.c | 77 ++++++++++++++++++++++++++++++++++++++++++--
f96e0b
 include/grub/arc/arc.h       |  2 +-
f96e0b
 3 files changed, 80 insertions(+), 4 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 2f55104..6c27f76 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,5 +1,10 @@
f96e0b
 2013-04-24  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
+	* grub-core/term/arc/console.c: Assume that console is 80x24 vt100 if
f96e0b
+	it's serial.
f96e0b
+
f96e0b
+2013-04-24  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
 	* util/grub-install.in: Fix target fo qemu_mips.
f96e0b
 	Fix extension on EFI.
f96e0b
 
f96e0b
diff --git a/grub-core/term/arc/console.c b/grub-core/term/arc/console.c
f96e0b
index 0ccaebe..13478ea 100644
f96e0b
--- a/grub-core/term/arc/console.c
f96e0b
+++ b/grub-core/term/arc/console.c
f96e0b
@@ -50,10 +50,72 @@ put (struct grub_term_output *term __attribute__ ((unused)), const int c)
f96e0b
 
f96e0b
 static struct grub_terminfo_output_state grub_console_terminfo_output;
f96e0b
 
f96e0b
-static grub_err_t
f96e0b
-grub_console_init_output (struct grub_term_output *term)
f96e0b
+static int
f96e0b
+check_is_serial (void)
f96e0b
+{
f96e0b
+  static int is_serial = -1;
f96e0b
+
f96e0b
+  if (is_serial != -1)
f96e0b
+    return is_serial;
f96e0b
+
f96e0b
+  const char *consout = 0;
f96e0b
+
f96e0b
+  /* Check for serial. It works unless user manually overrides ConsoleOut
f96e0b
+     variable. If he does there is nothing we can do. Fortunately failure
f96e0b
+     isn't critical.
f96e0b
+  */
f96e0b
+  if (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmware_vector_length
f96e0b
+      >= ((char *) (&GRUB_ARC_FIRMWARE_VECTOR->getenvironmentvariable + 1)
f96e0b
+	  - (char *) GRUB_ARC_FIRMWARE_VECTOR)
f96e0b
+      && GRUB_ARC_FIRMWARE_VECTOR->getenvironmentvariable)
f96e0b
+    consout = GRUB_ARC_FIRMWARE_VECTOR->getenvironmentvariable ("ConsoleOut");
f96e0b
+  if (!consout)
f96e0b
+    return is_serial = 0;
f96e0b
+  if (consout[0] == '\0')
f96e0b
+    return is_serial = 0;
f96e0b
+
f96e0b
+  const char *ptr = consout + grub_strlen (consout) - 1;
f96e0b
+  int i;
f96e0b
+  /*
f96e0b
+    Recognize:
f96e0b
+    serial(N)
f96e0b
+    serial(N)other(M)
f96e0b
+   */
f96e0b
+  for (i = 0; i < 2; i++)
f96e0b
+    {
f96e0b
+      if (*ptr != ')')
f96e0b
+	return is_serial = 0;
f96e0b
+      ptr--;
f96e0b
+      for (; ptr >= consout && grub_isdigit (*ptr); ptr--);
f96e0b
+      if (ptr < consout)
f96e0b
+	return is_serial = 0;
f96e0b
+      if (*ptr != '(')
f96e0b
+	return is_serial = 0;
f96e0b
+      if (ptr >= consout + sizeof ("serial") - 1
f96e0b
+	  && grub_memcmp (ptr - (sizeof ("serial") - 1),
f96e0b
+			  "serial", sizeof ("serial") - 1) == 0)
f96e0b
+	return is_serial = 1;
f96e0b
+      if (!(ptr >= consout + sizeof ("other") - 1
f96e0b
+	    && grub_memcmp (ptr - (sizeof ("other") - 1),
f96e0b
+			    "other", sizeof ("other") - 1) == 0))
f96e0b
+	return is_serial = 0;
f96e0b
+      ptr -= sizeof ("other");
f96e0b
+    }
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+    
f96e0b
+static void
f96e0b
+set_console_dimensions (void)
f96e0b
 {
f96e0b
   struct grub_arc_display_status *info = NULL;
f96e0b
+
f96e0b
+  if (check_is_serial ())
f96e0b
+    {
f96e0b
+      grub_console_terminfo_output.width = 80;
f96e0b
+      grub_console_terminfo_output.height = 24;
f96e0b
+      return;
f96e0b
+    }
f96e0b
+
f96e0b
   if (GRUB_ARC_SYSTEM_PARAMETER_BLOCK->firmware_vector_length
f96e0b
       >= ((char *) (&GRUB_ARC_FIRMWARE_VECTOR->getdisplaystatus + 1)
f96e0b
 	  - (char *) GRUB_ARC_FIRMWARE_VECTOR)
f96e0b
@@ -64,6 +126,12 @@ grub_console_init_output (struct grub_term_output *term)
f96e0b
       grub_console_terminfo_output.width = info->w + 1;
f96e0b
       grub_console_terminfo_output.height = info->h + 1;
f96e0b
     }
f96e0b
+}
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_console_init_output (struct grub_term_output *term)
f96e0b
+{
f96e0b
+  set_console_dimensions ();
f96e0b
   grub_terminfo_output_init (term);
f96e0b
 
f96e0b
   return 0;
f96e0b
@@ -115,5 +183,8 @@ void
f96e0b
 grub_console_init_lately (void)
f96e0b
 {
f96e0b
   grub_terminfo_init ();
f96e0b
-  grub_terminfo_output_register (&grub_console_term_output, "arc");
f96e0b
+  if (check_is_serial ())
f96e0b
+    grub_terminfo_output_register (&grub_console_term_output, "vt100");
f96e0b
+  else
f96e0b
+    grub_terminfo_output_register (&grub_console_term_output, "arc");
f96e0b
 }
f96e0b
diff --git a/include/grub/arc/arc.h b/include/grub/arc/arc.h
f96e0b
index 739926f..8f86500 100644
f96e0b
--- a/include/grub/arc/arc.h
f96e0b
+++ b/include/grub/arc/arc.h
f96e0b
@@ -210,7 +210,7 @@ struct grub_arc_firmware_vector
f96e0b
   grub_arc_err_t (*seek) (grub_arc_fileno_t fileno,
f96e0b
 			  grub_arc_ularge_t *pos, grub_arc_enum_t mode);
f96e0b
   void *mount;
f96e0b
-  void *getenvironmentvariable;
f96e0b
+  const char * (*getenvironmentvariable) (const char *name);
f96e0b
   void *setenvironmentvariable;
f96e0b
 
f96e0b
   /* 0x80. */
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b