grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Julius Werner <jwerner@chromium.org>
To: grub-devel@gnu.org
Cc: Paul Menzel <paulepanter@users.sourceforge.net>,
	Vladimir Serbinenko <phcoder@google.com>,
	Julius Werner <jwerner@chromium.org>
Subject: [PATCH v2] grub-core/term/i386/coreboot/cbmemc.c: Update console format
Date: Tue, 25 Apr 2017 13:18:25 -0700	[thread overview]
Message-ID: <20170425201825.15337-1-jwerner@chromium.org> (raw)
In-Reply-To: <20170425000008.10286-1-jwerner@chromium.org>

Changed cbmemc to support updated console format from coreboot.
---
 grub-core/term/i386/coreboot/cbmemc.c | 50 ++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 15 deletions(-)

diff --git a/grub-core/term/i386/coreboot/cbmemc.c b/grub-core/term/i386/coreboot/cbmemc.c
index 25e64a05c..436eda52a 100644
--- a/grub-core/term/i386/coreboot/cbmemc.c
+++ b/grub-core/term/i386/coreboot/cbmemc.c
@@ -29,11 +29,14 @@
 
 GRUB_MOD_LICENSE ("GPLv3+");
 
+#define CURSOR_MASK ((1 << 28) - 1)
+#define OVERFLOW (1 << 31)
+
 struct grub_linuxbios_cbmemc
 {
   grub_uint32_t size;
-  grub_uint32_t pointer;
-  char data[0];
+  grub_uint32_t cursor;
+  char body[0];
 };
 
 static struct grub_linuxbios_cbmemc *cbmemc;
@@ -41,11 +44,20 @@ static struct grub_linuxbios_cbmemc *cbmemc;
 static void
 put (struct grub_term_output *term __attribute__ ((unused)), const int c)
 {
+  grub_uint32_t flags, cursor;
   if (!cbmemc)
     return;
-  if (cbmemc->pointer < cbmemc->size)
-    cbmemc->data[cbmemc->pointer] = c;
-  cbmemc->pointer++;
+  flags = cbmemc->cursor & ~CURSOR_MASK;
+  cursor = cbmemc->cursor & CURSOR_MASK;
+  if (cursor >= cbmemc->size)
+    return;
+  cbmemc->body[cursor++] = c;
+  if (cursor >= cbmemc->size)
+    {
+      cursor = 0;
+      flags |= OVERFLOW;
+    }
+  cbmemc->cursor = flags | cursor;
 }
 
 struct grub_terminfo_output_state grub_cbmemc_terminfo_output =
@@ -87,21 +99,29 @@ grub_cmd_cbmemc (struct grub_command *cmd __attribute__ ((unused)),
 		 int argc __attribute__ ((unused)),
 		 char *argv[] __attribute__ ((unused)))
 {
-  grub_size_t len;
-  char *str;
-  struct grub_linuxbios_cbmemc *cbmemc_saved;
+  grub_size_t size, cursor;
+  struct grub_linuxbios_cbmemc *real_cbmemc;
 
   if (!cbmemc)
     return grub_error (GRUB_ERR_IO, "no CBMEM console found");
 
-  len = cbmemc->pointer;
-  if (len > cbmemc->size)
-    len = cbmemc->size;
-  str = cbmemc->data;
-  cbmemc_saved = cbmemc;
+  real_cbmemc = cbmemc;
   cbmemc = 0;
-  grub_xnputs (str, len);
-  cbmemc = cbmemc_saved;
+  cursor = real_cbmemc->cursor & CURSOR_MASK;
+  if (!(real_cbmemc->cursor & OVERFLOW) && cursor < real_cbmemc->size)
+    size = cursor;
+  else
+    size = real_cbmemc->size;
+  if (real_cbmemc->cursor & OVERFLOW)
+    {
+      if (cursor > size)
+        cursor = 0;
+      grub_xnputs(real_cbmemc->body + cursor, size - cursor);
+      grub_xnputs(real_cbmemc->body, cursor);
+    }
+  else
+    grub_xnputs(real_cbmemc->body, size);
+  cbmemc = real_cbmemc;
   return 0;
 }
 
-- 
2.12.2



  reply	other threads:[~2017-04-25 20:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25  0:00 [PATCH] grub-core/term/i386/coreboot/cbmemc.c: Update console format Julius Werner
2017-04-25 20:18 ` Julius Werner [this message]
2017-05-09  7:03   ` [PATCH v2] " Vladimir 'phcoder' Serbinenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170425201825.15337-1-jwerner@chromium.org \
    --to=jwerner@chromium.org \
    --cc=grub-devel@gnu.org \
    --cc=paulepanter@users.sourceforge.net \
    --cc=phcoder@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).