Blame SOURCES/0155-Implement-new-command-cmosdump.patch

f96e0b
From 69209411d039be9bc278e12c7b6736b7a1101229 Mon Sep 17 00:00:00 2001
f96e0b
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
f96e0b
Date: Sun, 24 Feb 2013 19:44:17 +0100
f96e0b
Subject: [PATCH 155/482] 	Implement new command cmosdump.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                          |  4 +++
f96e0b
 grub-core/Makefile.core.def        |  6 ++++
f96e0b
 grub-core/commands/i386/cmosdump.c | 64 ++++++++++++++++++++++++++++++++++++++
f96e0b
 include/grub/cmos.h                | 24 +++++++++++---
f96e0b
 include/grub/i386/cmos.h           |  2 ++
f96e0b
 include/grub/mips/loongson/cmos.h  |  2 ++
f96e0b
 include/grub/mips/qemu_mips/cmos.h |  2 ++
f96e0b
 7 files changed, 100 insertions(+), 4 deletions(-)
f96e0b
 create mode 100644 grub-core/commands/i386/cmosdump.c
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index 654ebcb..2faef5b 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,7 @@
f96e0b
+2013-02-24  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
+
f96e0b
+	Implement new command cmosdump.
f96e0b
+
f96e0b
 2013-02-19  Paulo Flabiano Smorigo <pfsmorigo@br.ibm.com>
f96e0b
 
f96e0b
 	Support Openfirmware disks with non-512B sectors.
f96e0b
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
f96e0b
index c006abf..4b0e6e6 100644
f96e0b
--- a/grub-core/Makefile.core.def
f96e0b
+++ b/grub-core/Makefile.core.def
f96e0b
@@ -510,6 +510,12 @@ module = {
f96e0b
 };
f96e0b
 
f96e0b
 module = {
f96e0b
+  name = cmosdump;
f96e0b
+  common = commands/i386/cmosdump.c;
f96e0b
+  enable = cmos;
f96e0b
+};
f96e0b
+
f96e0b
+module = {
f96e0b
   name = iorw;
f96e0b
   common = commands/iorw.c;
f96e0b
   enable = x86;
f96e0b
diff --git a/grub-core/commands/i386/cmosdump.c b/grub-core/commands/i386/cmosdump.c
f96e0b
new file mode 100644
f96e0b
index 0000000..952d200
f96e0b
--- /dev/null
f96e0b
+++ b/grub-core/commands/i386/cmosdump.c
f96e0b
@@ -0,0 +1,64 @@
f96e0b
+/*
f96e0b
+ *  GRUB  --  GRand Unified Bootloader
f96e0b
+ *  Copyright (C) 2009,2013  Free Software Foundation, Inc.
f96e0b
+ *
f96e0b
+ *  GRUB is free software: you can redistribute it and/or modify
f96e0b
+ *  it under the terms of the GNU General Public License as published by
f96e0b
+ *  the Free Software Foundation, either version 3 of the License, or
f96e0b
+ *  (at your option) any later version.
f96e0b
+ *
f96e0b
+ *  GRUB is distributed in the hope that it will be useful,
f96e0b
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
f96e0b
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f96e0b
+ *  GNU General Public License for more details.
f96e0b
+ *
f96e0b
+ *  You should have received a copy of the GNU General Public License
f96e0b
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
f96e0b
+ */
f96e0b
+
f96e0b
+#include <grub/dl.h>
f96e0b
+#include <grub/command.h>
f96e0b
+#include <grub/misc.h>
f96e0b
+#include <grub/cmos.h>
f96e0b
+#include <grub/i18n.h>
f96e0b
+
f96e0b
+GRUB_MOD_LICENSE ("GPLv3+");
f96e0b
+
f96e0b
+static grub_err_t
f96e0b
+grub_cmd_cmosdump (struct grub_command *cmd __attribute__ ((unused)),
f96e0b
+		   int argc __attribute__ ((unused)), char *argv[] __attribute__ ((unused)))
f96e0b
+{
f96e0b
+  int i;
f96e0b
+
f96e0b
+  for (i = 0; i < 256; i++)
f96e0b
+    {
f96e0b
+      grub_err_t err;
f96e0b
+      grub_uint8_t value;
f96e0b
+      if ((i & 0xf) == 0)
f96e0b
+	grub_printf ("%02x: ", i);
f96e0b
+
f96e0b
+      err = grub_cmos_read (i, &value);
f96e0b
+      if (err)
f96e0b
+	return err;
f96e0b
+
f96e0b
+      grub_printf ("%02x ", value);
f96e0b
+      if ((i & 0xf) == 0xf)
f96e0b
+	grub_printf ("\n");
f96e0b
+    }
f96e0b
+  return GRUB_ERR_NONE;
f96e0b
+}
f96e0b
+
f96e0b
+static grub_command_t cmd;
f96e0b
+
f96e0b
+
f96e0b
+GRUB_MOD_INIT(cmosdump)
f96e0b
+{
f96e0b
+  cmd = grub_register_command ("cmosdump", grub_cmd_cmosdump,
f96e0b
+			       0,
f96e0b
+			       N_("Dump CMOS contents."));
f96e0b
+}
f96e0b
+
f96e0b
+GRUB_MOD_FINI(cmosdump)
f96e0b
+{
f96e0b
+  grub_unregister_command (cmd);
f96e0b
+}
f96e0b
diff --git a/include/grub/cmos.h b/include/grub/cmos.h
f96e0b
index 331513c..aa2b233 100644
f96e0b
--- a/include/grub/cmos.h
f96e0b
+++ b/include/grub/cmos.h
f96e0b
@@ -61,16 +61,32 @@ grub_num_to_bcd (grub_uint8_t a)
f96e0b
 static inline grub_err_t
f96e0b
 grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
f96e0b
 {
f96e0b
-  grub_outb (index, GRUB_CMOS_ADDR_REG);
f96e0b
-  *val = grub_inb (GRUB_CMOS_DATA_REG);
f96e0b
+  if (index & 0x80)
f96e0b
+    {
f96e0b
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
f96e0b
+      *val = grub_inb (GRUB_CMOS_DATA_REG_HI);
f96e0b
+    }
f96e0b
+  else
f96e0b
+    {
f96e0b
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
f96e0b
+      *val = grub_inb (GRUB_CMOS_DATA_REG);
f96e0b
+    }
f96e0b
   return GRUB_ERR_NONE;
f96e0b
 }
f96e0b
 
f96e0b
 static inline grub_err_t
f96e0b
 grub_cmos_write (grub_uint8_t index, grub_uint8_t value)
f96e0b
 {
f96e0b
-  grub_outb (index, GRUB_CMOS_ADDR_REG);
f96e0b
-  grub_outb (value, GRUB_CMOS_DATA_REG);
f96e0b
+  if (index & 0x80)
f96e0b
+    {
f96e0b
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
f96e0b
+      grub_outb (value, GRUB_CMOS_DATA_REG_HI);
f96e0b
+    }
f96e0b
+  else
f96e0b
+    {
f96e0b
+      grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
f96e0b
+      grub_outb (value, GRUB_CMOS_DATA_REG);
f96e0b
+    }
f96e0b
   return GRUB_ERR_NONE;
f96e0b
 }
f96e0b
 #else
f96e0b
diff --git a/include/grub/i386/cmos.h b/include/grub/i386/cmos.h
f96e0b
index 8b1fa35..27a2b21 100644
f96e0b
--- a/include/grub/i386/cmos.h
f96e0b
+++ b/include/grub/i386/cmos.h
f96e0b
@@ -24,5 +24,7 @@
f96e0b
 
f96e0b
 #define GRUB_CMOS_ADDR_REG	0x70
f96e0b
 #define GRUB_CMOS_DATA_REG	0x71
f96e0b
+#define GRUB_CMOS_ADDR_REG_HI	0x72
f96e0b
+#define GRUB_CMOS_DATA_REG_HI	0x73
f96e0b
 
f96e0b
 #endif /* GRUB_CPU_CMOS_H */
f96e0b
diff --git a/include/grub/mips/loongson/cmos.h b/include/grub/mips/loongson/cmos.h
f96e0b
index f2a32d7..96d50f2 100644
f96e0b
--- a/include/grub/mips/loongson/cmos.h
f96e0b
+++ b/include/grub/mips/loongson/cmos.h
f96e0b
@@ -24,5 +24,7 @@
f96e0b
 
f96e0b
 #define GRUB_CMOS_ADDR_REG	0xbfd00070
f96e0b
 #define GRUB_CMOS_DATA_REG	0xbfd00071
f96e0b
+#define GRUB_CMOS_ADDR_REG	0xbfd00072
f96e0b
+#define GRUB_CMOS_DATA_REG	0xbfd00073
f96e0b
 
f96e0b
 #endif /* GRUB_CPU_CMOS_H */
f96e0b
diff --git a/include/grub/mips/qemu_mips/cmos.h b/include/grub/mips/qemu_mips/cmos.h
f96e0b
index 4aef40e..0759704 100644
f96e0b
--- a/include/grub/mips/qemu_mips/cmos.h
f96e0b
+++ b/include/grub/mips/qemu_mips/cmos.h
f96e0b
@@ -24,5 +24,7 @@
f96e0b
 
f96e0b
 #define GRUB_CMOS_ADDR_REG	0xb4000070
f96e0b
 #define GRUB_CMOS_DATA_REG	0xb4000071
f96e0b
+#define GRUB_CMOS_ADDR_REG_HI	0xb4000072
f96e0b
+#define GRUB_CMOS_DATA_REG_HI	0xb4000073
f96e0b
 
f96e0b
 #endif /* GRUB_CPU_CMOS_H */
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b