[PATCH 2/2] xmon io space read

Jake Moilanen moilanen at austin.ibm.com
Thu Jan 6 07:57:57 EST 2005


Here is the support code for xmon to read IO space.  

It should come in handy to debug driver and bringup issues.

Signed-off-by: Jake Moilanen <moilanen at austin.ibm.com>

---


diff -puN arch/ppc64/xmon/xmon.c~xmon-io-read arch/ppc64/xmon/xmon.c
--- linux-2.6-bk/arch/ppc64/xmon/xmon.c~xmon-io-read	Wed Jan  5 11:50:57 2005
+++ linux-2.6-bk-moilanen/arch/ppc64/xmon/xmon.c	Wed Jan  5 14:19:57 2005
@@ -93,6 +93,7 @@ static int mwrite(unsigned long, void *,
 static int handle_fault(struct pt_regs *);
 static void byterev(unsigned char *, int);
 static void memex(void);
+static void iomemex(void);
 static int bsesc(void);
 static void dump(void);
 static void prdump(unsigned long, long);
@@ -175,6 +176,7 @@ Commands:\n\
   di	dump instructions\n\
   df	dump float values\n\
   dd	dump double values\n\
+  i	IO memory dump\n\
   e	print exception information\n\
   f	flush cache\n\
   la	lookup symbol+offset of specified address\n\
@@ -794,6 +796,9 @@ cmds(struct pt_regs *excp)
 				memex();
 			}
 			break;
+		case 'i':
+			iomemex();
+			break;
 		case 'd':
 			dump();
 			break;
@@ -1855,6 +1860,130 @@ memex(void)
 		}
 		adrs += inc;
 	}
+}
+
+static char *iomemex_help_string = 
+    "IO Memory examine command usage:\n"
+    "i addr [size] [options]\n"
+    "  size may include chars from this set:\n"
+    "    1   examine byte  (default)\n"
+    "    2   examine short (2 byte)\n"
+    "    4   examine int   (4 byte)\n"
+    "    8   examine long  (8 byte)\n"
+    "  options may include chars from this set:\n"
+    "    l   little endian (default)\n"
+    "    b   big endian\n"
+    "    a   absolute address - does not add on pci_io_base\n"
+    "NOTE: Defaults to adding on pci_io_base\n"
+    "";
+
+
+#define LE 0
+#define BE 1
+
+static void
+ioread(unsigned long addr, int size, int endiness)
+{
+	int i;
+	long data;
+	
+	if (setjmp(bus_error_jmp) == 0) {
+		catch_memory_errors = 1;
+		sync();
+		switch (size) {
+		case 1:
+			data = in_8((char *)addr);
+			sync();
+			__delay(200);
+			printf("%.16lx: 0x%.2x\n", addr, data);
+			break;
+
+		case 2:
+			data = endiness ? in_be16((short *)addr) : in_le16((short *)addr);
+			sync();
+			__delay(200);
+			printf("%.16lx: 0x%.4x\n", addr, data);
+			break;
+		case 4:
+			data = endiness ? in_be32((int *)addr) : in_le32((int *)addr);
+			sync();
+			__delay(200);
+			printf("%.16lx: 0x%.8x\n", addr, data);
+			break;
+		case 8:
+			data = endiness ? in_be64((long *)addr) : in_le64((long *)addr);
+			sync();
+			__delay(200);
+			printf("%.16lx: 0x%.16x\n", addr, data);
+			break;
+		default:
+			printf("ioread: invalid size (%d)\n", size);
+		}
+	} else {
+		printf("%.16lx: ", addr);
+		for (i = 0; i < size; i++)
+			printf("%s", fault_chars[fault_type]);
+		printf("\n");
+	}
+	
+	catch_memory_errors = 0;
+
+}
+
+static void
+iomemex(void)
+{
+	int size = 1;
+	int cmd;
+	int endiness = LE;
+	int absolute = 0;
+
+	scanhex((void *)&adrs);
+	cmd = skipbl();
+	if (cmd == '?') {
+		printf(iomemex_help_string);
+		return;
+	} else if (cmd == '\n' && !adrs) {
+		printf("pci_io_base: 0x%lx\n", pci_io_base);
+		return;
+	}
+
+	termch = cmd;
+
+	while ((cmd = skipbl()) != '\n') {
+		switch (cmd) {
+		case '1':	size = 1;	break;
+		case '2':	size = 2;	break;
+		case '4':	size = 4;	break;
+		case '8':	size = 8;	break;
+		case 'l':	endiness = LE; break;
+		case 'b':	endiness = BE; break;
+		case 'a':	absolute = 1; break;
+		}
+	} 
+
+	if(size <= 0)
+		size = 1;
+	else if(size > 8)
+		size = 8;
+
+	if (!absolute)
+		adrs += pci_io_base;
+
+	printf("Will attempt to read:\n");
+	printf("address:\t0x%lx\n", adrs);
+	printf("size:\t\t0x%lx\n", size);
+	printf("endiness:\t%s\n", endiness ? "Big" : "Little");
+	printf("Are you sure (Y/n): ");
+	fflush(stdout);
+	flush_input();
+
+	cmd = skipbl();
+
+	if (cmd == 'n')
+		return;
+
+	ioread(adrs, size, endiness);
 }
 
 int
diff -puN arch/ppc64/mm/fault.c~xmon-io-read arch/ppc64/mm/fault.c
--- linux-2.6-bk/arch/ppc64/mm/fault.c~xmon-io-read	Wed Jan  5 13:27:30 2005
+++ linux-2.6-bk-moilanen/arch/ppc64/mm/fault.c	Wed Jan  5 13:27:38 2005
@@ -297,6 +297,9 @@ void bad_page_fault(struct pt_regs *regs
 		return;
 	}
 
+	if (debugger_fault_handler(regs))
+		return;
+
 	/* kernel has accessed a bad area */
 	die("Kernel access of bad area", regs, sig);
 }

_



More information about the Linuxppc64-dev mailing list