[PATCH] kdb: add rdmsr and wrmsr commands for i386

Bernardo Innocenti bernie at codewiz.org
Tue May 15 12:29:48 PDT 2007


The syntax is:
  rdmsr <addr>
  wrmsr <addr> <h> <l>

Signed-off-by: Bernardo Innocenti <bernie at codewiz.org>
---
 arch/i386/kdb/kdbasupport.c |   48 +++++++++++++++++++++++++++++++++++++++---
 kdb/kdbmain.c               |    3 +-
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/arch/i386/kdb/kdbasupport.c b/arch/i386/kdb/kdbasupport.c
index 482b319..5109db9 100644
--- a/arch/i386/kdb/kdbasupport.c
+++ b/arch/i386/kdb/kdbasupport.c
@@ -223,6 +223,47 @@ kdba_removedbreg(kdb_bp_t *bp)
 	kdba_putdr7(dr7);
 }
 
+static int
+kdba_rdmsr(int argc, const char **argv)
+{
+	unsigned long addr;
+	uint64_t val;
+	int diag;
+
+	if (argc != 1) {
+		return KDB_ARGCOUNT;
+	}
+
+	if ((diag = kdbgetularg(argv[1], &addr)))
+		return diag;
+
+	kdb_printf("msr(0x%lx) = ", addr);
+	rdmsrl(addr, val);
+	kdb_printf("0x%llx\n", val);
+
+	return 0;
+}
+
+static int
+kdba_wrmsr(int argc, const char **argv)
+{
+	unsigned long addr;
+	unsigned long l, h;
+	int diag;
+
+	if (argc != 3)
+		return KDB_ARGCOUNT;
+
+	if ((diag = kdbgetularg(argv[1], &addr))
+			|| (diag = kdbgetularg(argv[2], &h))
+			|| (diag = kdbgetularg(argv[3], &l)))
+		return diag;
+
+	wrmsr(addr, l, h);
+
+	return 0;
+}
+
 
 /*
  * kdba_getregcontents
@@ -474,12 +515,11 @@ kdba_setregcontents(const char *regname,
  *	argument is NULL (struct pt_regs).   The alternate register
  *	set types supported by this function:
  *
- *	d 		Debug registers
+ *	d		Debug registers
  *	c		Control registers
  *	u		User registers at most recent entry to kernel
  *			for the process currently selected with "pid" command.
  * Following not yet implemented:
- *	m		Model Specific Registers (extra defines register #)
  *	r		Memory Type Range Registers (extra defines register)
  */
 
@@ -546,8 +586,6 @@ kdba_dumpregs(struct pt_regs *regs,
 			   cr[0], cr[1], cr[2], cr[3], cr[4]);
 		return 0;
 	}
-	case 'm':
-		break;
 	case 'r':
 		break;
 	default:
@@ -899,6 +937,8 @@ kdba_init(void)
 {
 	kdb_register("pt_regs", kdba_pt_regs, "address", "Format struct pt_regs", 0);
 	kdb_register("stackdepth", kdba_stackdepth, "[percentage]", "Print processes using >= stack percentage", 0);
+	kdb_register("rdmsr", kdba_rdmsr, "<maddr>", "Display Model Specific Register", 0);
+	kdb_register("wrmsr", kdba_wrmsr, "<maddr> <h> <l>", "Modify Model Specific Register", 0);
 
 	return;
 }
diff --git a/kdb/kdbmain.c b/kdb/kdbmain.c
index 0b2cb91..88bf14f 100644
--- a/kdb/kdbmain.c
+++ b/kdb/kdbmain.c
@@ -2596,8 +2596,7 @@ kdb_rd(int argc, const char **argv)
  *	none.
  * Remarks:
  *	Currently doesn't allow modification of control or
- *	debug registers, nor does it allow modification
- *	of model-specific registers (MSR).
+ *	debug registers.
  */
 
 static int
-- 
1.5.0.2


-- 
   // Bernardo Innocenti
 \X/  http://www.codewiz.org/
---------------------------
Use http://oss.sgi.com/ecartis to modify your settings or to unsubscribe.


More information about the kdb mailing list