[PATCH]display-modify i/o port for kdb-v0.6

masahiro adegawa (adegawa@zerosoft.co.jp)
Thu, 09 Dec 1999 01:16:14 +0900


hi,

I have 2 patchs about i/o port for kdb-v0.6.
(http://oss.sgi.com/projects/kdb)

1st patch is a small bug fix.
I'm using kdb with serial console or HHK that haven't LED. :-p
2nd patch is added commands display-modify i/o port.
iob <port> [<contents>] Display/Modify i/o port(8bit)
iow <port> [<contents>] Display/Modify i/o port(16bit)
iol <port> [<contents>] Display/Modify i/o port(32bit)
ex.
Entering kdb due to Keyboard Entry
kdb> iob 0x378
in : 0x378 = 0x00
kdb> iob 0x378 0x23
out : 0x378 = 0x23
kdb> iob 0x378
in : 0x378 = 0x23
kdb>

thanks,

--- arch/i386/kdb/kdb_io.c.orig Tue Dec 7 12:05:17 1999
+++ arch/i386/kdb/kdb_io.c Tue Dec 7 12:06:16 1999
@@ -45,7 +45,7 @@
{
while (inb(KBD_STATUS_REG) & KBD_STAT_IBF)
;
- outb(KBD_DATA_REG, byte);
+ outb(byte, KBD_DATA_REG);
}

static void
--- arch/i386/kdb/kdb.c.orig Tue Dec 7 12:05:17 1999
+++ arch/i386/kdb/kdb.c Tue Dec 7 12:06:16 1999
@@ -23,6 +23,7 @@
#endif
#include <linux/kdb.h>
#include <asm/system.h>
+#include <asm/io.h>
#include "kdbsupport.h"
#include "kdb_io.h"

@@ -1148,6 +1149,85 @@

return 0;
}
+/*
+ * kdb_io
+ *
+ * This function implements the 'iob','iow' and 'iol' commands.
+ *
+ * iob|iow|iol [<addr arg> [<new value>]]
+ *
+ * Inputs:
+ * argc argument count
+ * argv argument vector
+ * envp environment vector
+ * regs registers at time kdb was entered.
+ * Outputs:
+ * None.
+ * Returns:
+ * zero for success, a kdb diagnostic if error
+ * Locking:
+ * none.
+ * Remarks:
+ * none.
+ */
+
+int
+kdb_io(int argc, const char **argv, const char **envp, struct pt_regs *regs)
+{
+ int diag;
+ unsigned long addr;
+ long offset = 0;
+ unsigned long contents;
+ int nextarg;
+ int mod = 0;
+
+ if (argc == 0) {
+ return KDB_ARGCOUNT;
+ }
+
+ nextarg = 1;
+ diag = kdbgetaddrarg(argc, argv, &nextarg, &addr, &offset, NULL, regs);
+ if (diag)
+ return diag;
+
+ if (nextarg <= argc) {
+ diag = kdbgetaddrarg(argc, argv, &nextarg, &contents, NULL, NULL, regs);
+ if (diag)
+ return diag;
+ mod = 1;
+ if (nextarg != argc + 1)
+ return KDB_ARGCOUNT;
+ }
+
+ /*
+ * To prevent access of invalid addresses, check first.
+ * Hmm...
+ */
+
+ if (strcmp(argv[0], "iob") == 0) {
+ if (mod)
+ outb(contents, addr);
+ else
+ contents = inb(addr);
+ kdb_printf("%s : 0x%x = 0x%2.2x\n", mod?"out":"in", addr, contents);
+ }
+ if (strcmp(argv[0], "iow") == 0) {
+ if (mod)
+ outw(contents, addr);
+ else
+ contents = inw(addr);
+ kdb_printf("%s : 0x%x = 0x%4.4x\n", mod?"out":"in", addr, contents);
+ }
+ if (strcmp(argv[0], "iol") == 0) {
+ if (mod)
+ outl(contents, addr);
+ else
+ contents = inl(addr);
+ kdb_printf("%s : 0x%x = 0x%8.8x\n", mod?"out":"in", addr, contents);
+ }
+
+ return 0;
+}

/*
* kdb_go
@@ -1855,6 +1935,9 @@
kdb_register("cpu", kdb_cpu, "<cpunum>","Switch to new cpu", 0);
#endif /* __SMP__ */
kdb_register("ps", kdb_ps, "", "Display active task list", 0);
+ kdb_register("iob", kdb_io, "<port> [<contents>]", "Display/Modify i/o port(8bit)", 0);
+ kdb_register("iow", kdb_io, "<port> [<contents>]", "Display/Modify i/o port(16bit)", 0);
+ kdb_register("iol", kdb_io, "<port> [<contents>]", "Display/Modify i/o port(32bit)", 0);
kdb_register("reboot", kdb_reboot, "", "Reboot the machine immediately", 0);
#if defined(CONFIG_MAGIC_SYSRQ)
kdb_register("sr", kdb_sr, "<key>", "Magic SysRq key", 0);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/