a5bd9f6
From e720300246bd79d0cdb36dc9df4491557ee48663 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Sun, 24 Feb 2013 19:44:17 +0100
a5bd9f6
Subject: [PATCH 154/364] 	Implement new command cmosdump.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                          |  4 +++
a5bd9f6
 grub-core/Makefile.core.def        |  6 ++++
a5bd9f6
 grub-core/commands/i386/cmosdump.c | 64 ++++++++++++++++++++++++++++++++++++++
a5bd9f6
 include/grub/cmos.h                | 24 +++++++++++---
a5bd9f6
 include/grub/i386/cmos.h           |  2 ++
a5bd9f6
 include/grub/mips/loongson/cmos.h  |  2 ++
a5bd9f6
 include/grub/mips/qemu_mips/cmos.h |  2 ++
a5bd9f6
 7 files changed, 100 insertions(+), 4 deletions(-)
a5bd9f6
 create mode 100644 grub-core/commands/i386/cmosdump.c
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 654ebcb..2faef5b 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,3 +1,7 @@
a5bd9f6
+2013-02-24  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
+	Implement new command cmosdump.
a5bd9f6
+
a5bd9f6
 2013-02-19  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
a5bd9f6
 
a5bd9f6
 	Support Openfirmware disks with non-512B sectors.
a5bd9f6
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
a5bd9f6
index c006abf..4b0e6e6 100644
a5bd9f6
--- a/grub-core/Makefile.core.def
a5bd9f6
+++ b/grub-core/Makefile.core.def
a5bd9f6
@@ -510,6 +510,12 @@ module = {
a5bd9f6
 };
a5bd9f6
 
a5bd9f6
 module = {
a5bd9f6
+  name = cmosdump;
a5bd9f6
+  common = commands/i386/cmosdump.c;
a5bd9f6
+  enable = cmos;
a5bd9f6
+};
a5bd9f6
+
a5bd9f6
+module = {
a5bd9f6
   name = iorw;
a5bd9f6
   common = commands/iorw.c;
a5bd9f6
   enable = x86;
a5bd9f6
diff --git a/grub-core/commands/i386/cmosdump.c b/grub-core/commands/i386/cmosdump.c
a5bd9f6
new file mode 100644
a5bd9f6
index 0000000..952d200
a5bd9f6
--- /dev/null
a5bd9f6
+++ b/grub-core/commands/i386/cmosdump.c
a5bd9f6
@@ -0,0 +1,64 @@
a5bd9f6
+/*
a5bd9f6
+ *  GRUB  --  GRand Unified Bootloader
a5bd9f6
+ *  Copyright (C) 2009,2013  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/dl.h>
a5bd9f6
+#include <grub/command.h>
a5bd9f6
+#include <grub/misc.h>
a5bd9f6
+#include <grub/cmos.h>
a5bd9f6
+#include <grub/i18n.h>
a5bd9f6
+
a5bd9f6
+GRUB_MOD_LICENSE ("GPLv3+");
a5bd9f6
+
a5bd9f6
+static grub_err_t
a5bd9f6
+grub_cmd_cmosdump (struct grub_command *cmd __attribute__ ((unused)),
a5bd9f6
+		   int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused)))
a5bd9f6
+{
a5bd9f6
+  int i;
a5bd9f6
+
a5bd9f6
+  for (i = 0; i < 256; i++)
a5bd9f6
+    {
a5bd9f6
+      grub_err_t err;
a5bd9f6
+      grub_uint8_t value;
a5bd9f6
+      if ((i & 0xf) == 0)
a5bd9f6
+	grub_printf ("%02x: ", i);
a5bd9f6
+
a5bd9f6
+      err = grub_cmos_read (i, &value);
a5bd9f6
+      if (err)
a5bd9f6
+	return err;
a5bd9f6
+
a5bd9f6
+      grub_printf ("%02x ", value);
a5bd9f6
+      if ((i & 0xf) == 0xf)
a5bd9f6
+	grub_printf ("\n");
a5bd9f6
+    }
a5bd9f6
+  return GRUB_ERR_NONE;
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+static grub_command_t cmd;
a5bd9f6
+
a5bd9f6
+
a5bd9f6
+GRUB_MOD_INIT(cmosdump)
a5bd9f6
+{
a5bd9f6
+  cmd = grub_register_command ("cmosdump", grub_cmd_cmosdump,
a5bd9f6
+			       0,
a5bd9f6
+			       N_("Dump CMOS contents."));
a5bd9f6
+}
a5bd9f6
+
a5bd9f6
+GRUB_MOD_FINI(cmosdump)
a5bd9f6
+{
a5bd9f6
+  grub_unregister_command (cmd);
a5bd9f6
+}
a5bd9f6
diff --git a/include/grub/cmos.h b/include/grub/cmos.h
a5bd9f6
index 331513c..aa2b233 100644
a5bd9f6
--- a/include/grub/cmos.h
a5bd9f6
+++ b/include/grub/cmos.h
a5bd9f6
@@ -61,16 +61,32 @@ grub_num_to_bcd (grub_uint8_t a)
a5bd9f6
 static inline grub_err_t
a5bd9f6
 grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
a5bd9f6
 {
a5bd9f6
-  grub_outb (index, GRUB_CMOS_ADDR_REG);
a5bd9f6
-  *val = grub_inb (GRUB_CMOS_DATA_REG);
a5bd9f6
+  if (index & 0x80)
a5bd9f6
+    {
a5bd9f6
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
a5bd9f6
+      *val = grub_inb (GRUB_CMOS_DATA_REG_HI);
a5bd9f6
+    }
a5bd9f6
+  else
a5bd9f6
+    {
a5bd9f6
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
a5bd9f6
+      *val = grub_inb (GRUB_CMOS_DATA_REG);
a5bd9f6
+    }
a5bd9f6
   return GRUB_ERR_NONE;
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static inline grub_err_t
a5bd9f6
 grub_cmos_write (grub_uint8_t index, grub_uint8_t value)
a5bd9f6
 {
a5bd9f6
-  grub_outb (index, GRUB_CMOS_ADDR_REG);
a5bd9f6
-  grub_outb (value, GRUB_CMOS_DATA_REG);
a5bd9f6
+  if (index & 0x80)
a5bd9f6
+    {
a5bd9f6
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
a5bd9f6
+      grub_outb (value, GRUB_CMOS_DATA_REG_HI);
a5bd9f6
+    }
a5bd9f6
+  else
a5bd9f6
+    {
a5bd9f6
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
a5bd9f6
+      grub_outb (value, GRUB_CMOS_DATA_REG);
a5bd9f6
+    }
a5bd9f6
   return GRUB_ERR_NONE;
a5bd9f6
 }
a5bd9f6
 #else
a5bd9f6
diff --git a/include/grub/i386/cmos.h b/include/grub/i386/cmos.h
a5bd9f6
index 8b1fa35..27a2b21 100644
a5bd9f6
--- a/include/grub/i386/cmos.h
a5bd9f6
+++ b/include/grub/i386/cmos.h
a5bd9f6
@@ -24,5 +24,7 @@
a5bd9f6
 
a5bd9f6
 #define GRUB_CMOS_ADDR_REG	0x70
a5bd9f6
 #define GRUB_CMOS_DATA_REG	0x71
a5bd9f6
+#define GRUB_CMOS_ADDR_REG_HI	0x72
a5bd9f6
+#define GRUB_CMOS_DATA_REG_HI	0x73
a5bd9f6
 
a5bd9f6
 #endif /* GRUB_CPU_CMOS_H */
a5bd9f6
diff --git a/include/grub/mips/loongson/cmos.h b/include/grub/mips/loongson/cmos.h
a5bd9f6
index f2a32d7..96d50f2 100644
a5bd9f6
--- a/include/grub/mips/loongson/cmos.h
a5bd9f6
+++ b/include/grub/mips/loongson/cmos.h
a5bd9f6
@@ -24,5 +24,7 @@
a5bd9f6
 
a5bd9f6
 #define GRUB_CMOS_ADDR_REG	0xbfd00070
a5bd9f6
 #define GRUB_CMOS_DATA_REG	0xbfd00071
a5bd9f6
+#define GRUB_CMOS_ADDR_REG	0xbfd00072
a5bd9f6
+#define GRUB_CMOS_DATA_REG	0xbfd00073
a5bd9f6
 
a5bd9f6
 #endif /* GRUB_CPU_CMOS_H */
a5bd9f6
diff --git a/include/grub/mips/qemu_mips/cmos.h b/include/grub/mips/qemu_mips/cmos.h
a5bd9f6
index 4aef40e..0759704 100644
a5bd9f6
--- a/include/grub/mips/qemu_mips/cmos.h
a5bd9f6
+++ b/include/grub/mips/qemu_mips/cmos.h
a5bd9f6
@@ -24,5 +24,7 @@
a5bd9f6
 
a5bd9f6
 #define GRUB_CMOS_ADDR_REG	0xb4000070
a5bd9f6
 #define GRUB_CMOS_DATA_REG	0xb4000071
a5bd9f6
+#define GRUB_CMOS_ADDR_REG_HI	0xb4000072
a5bd9f6
+#define GRUB_CMOS_DATA_REG_HI	0xb4000073
a5bd9f6
 
a5bd9f6
 #endif /* GRUB_CPU_CMOS_H */
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6