[PATCH] [yeeloong] 64-bit disassemble and disassemble cache instruction

Vladimir 'φ-coder/phcoder' Serbinenko phcoder at gmail.com
Mon Sep 27 11:08:39 UTC 2010


On 09/27/2010 09:12 AM, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>   


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

-------------- next part --------------
=== modified file 'mips/mips/db_disasm.c'
--- mips/mips/db_disasm.c	2010-08-13 22:16:49 +0000
+++ mips/mips/db_disasm.c	2010-08-13 22:20:49 +0000
@@ -53,6 +53,17 @@
 #include <ddb/ddb.h>
 #include <ddb/db_output.h>
 
+static char *cache_op_suffix[4] = {
+	"i", "d", "s", "si"
+};
+
+static char *cache_op_type[8] = {
+	"Index_Writeback_Invalidate", "Index_Load_Tag",
+	"Index_Store_Tag", "Create_Dirty_EXCL",
+	"Hit_Invalidate", "Hit_Writeback_Invalidate",
+	"Hit_Writeback", "Hit_Set_Virtual"
+};
+
 static char *op_name[64] = {
 /* 0 */ "spec", "bcond","j",	"jal",	"beq",	"bne",	"blez",	"bgtz",
 /* 8 */ "addi", "addiu","slti",	"sltiu","andi",	"ori",	"xori",	"lui",
@@ -373,6 +384,14 @@
 		    reg_name[i.IType.rt], i.IType.imm);
 		break;
 
+	case OP_CACHE:
+		db_printf("%s%s\t%s, %d(%s)", op_name[i.IType.op],
+			  cache_op_suffix[i.IType.rt & 3],
+			  cache_op_type[i.IType.rt >> 2],
+			  (short)i.IType.imm, reg_name[i.IType.rs]
+			);
+		break;
+		
 	case OP_ADDI:
 	case OP_DADDI:
 	case OP_ADDIU:

=== modified file 'mips/mips/db_trace.c'
--- mips/mips/db_trace.c	2010-08-13 22:16:49 +0000
+++ mips/mips/db_trace.c	2010-08-13 23:39:56 +0000
@@ -49,9 +49,19 @@
 #define	MIPS_END_OF_FUNCTION(ins)	((ins) == 0x03e00008)
 
 /*
- * kdbpeekD(addr) - skip one word starting at 'addr', then read the second word
+ * kdbpeekD(addr) - read double word.
  */
-#define	kdbpeekD(addr)	kdbpeek(((int *)(addr)) + 1)
+
+static inline register_t
+kdbpeekD (uintptr_t addr) {
+#ifdef __MIPSEL__
+	return ((uint64_t) kdbpeek ((int *) addr))
+		| (((uint64_t) kdbpeek ((int *) addr + 1)) << 32);
+#else
+	return ((uint64_t) kdbpeek ((int *) addr + 1))
+		| (((uint64_t) kdbpeek ((int *) addr)) << 32);
+#endif
+}
 
 /*
  * Functions ``special'' enough to print by name
@@ -105,6 +115,9 @@
 }
 
 void
+kproc_shutdown(void *arg, int howto);
+
+void
 stacktrace_subr(register_t pc, register_t sp, register_t ra,
 	int (*printfn) (const char *,...))
 {
@@ -119,6 +132,8 @@
 	unsigned instr, mask;
 	unsigned int frames = 0;
 	int more, stksize, j;
+	const uintptr_t kseg0_start = sizeof (uintptr_t) == 8
+		? 0x8000000000000000ULL : 0x80000000;
 
 /* Jump here when done with a frame, to start a new one */
 loop:
@@ -140,7 +155,7 @@
 	}
 	/* check for bad SP: could foul up next frame */
 	/*XXX MIPS64 bad: this hard-coded SP is lame */
-	if (sp & 3 || (uintptr_t)sp < 0x80000000u) {
+	if (sp & 3 || (uintptr_t)sp < kseg0_start) {
 		(*printfn) ("SP 0x%x: not in kernel\n", sp);
 		ra = 0;
 		subr = 0;
@@ -156,7 +171,9 @@
 	 * preceding "j ra" at the tail of the preceding function. Depends
 	 * on relative ordering of functions in exception.S, swtch.S.
 	 */
-	if (pcBetween(MipsKernGenException, MipsUserGenException))
+	if (pcBetween(panic, shutdown_nice))
+		subr = (uintptr_t) panic;
+	else if (pcBetween(MipsKernGenException, MipsUserGenException))
 		subr = (uintptr_t)MipsKernGenException;
 	else if (pcBetween(MipsUserGenException, MipsKernIntr))
 		subr = (uintptr_t)MipsUserGenException;
@@ -181,7 +198,7 @@
 	}
 	/* check for bad PC */
 	/*XXX MIPS64 bad: These hard coded constants are lame */
-	if (pc & 3 || pc < (uintptr_t)0x80000000) {
+	if (pc & 3 || (uintptr_t)pc < kseg0_start) {
 		(*printfn) ("PC 0x%x: not in kernel\n", pc);
 		ra = 0;
 		goto done;
@@ -303,32 +320,34 @@
 			mask |= (1 << i.IType.rt);
 			switch (i.IType.rt) {
 			case 4:/* a0 */
-				args[0] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+				args[0] = kdbpeekD((sp + (short)i.IType.imm));
 				valid_args[0] = 1;
 				break;
 
 			case 5:/* a1 */
-				args[1] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+				args[1] = kdbpeekD((sp + (short)i.IType.imm));
 				valid_args[1] = 1;
 				break;
 
 			case 6:/* a2 */
-				args[2] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+				args[2] = kdbpeekD((sp + (short)i.IType.imm));
 				valid_args[2] = 1;
 				break;
 
 			case 7:/* a3 */
-				args[3] = kdbpeekD((int *)(sp + (short)i.IType.imm));
+				args[3] = kdbpeekD((sp + (short)i.IType.imm));
 				valid_args[3] = 1;
 				break;
 
 			case 31:	/* ra */
-				ra = kdbpeekD((int *)(sp + (short)i.IType.imm));
+				ra = kdbpeekD((sp + (short)i.IType.imm));
 			}
 			break;
 
 		case OP_ADDI:
 		case OP_ADDIU:
+  		case OP_DADDIU:
+  		case OP_DADDI:
 			/* look for stack pointer adjustment */
 			if (i.IType.rs != 29 || i.IType.rt != 29)
 				break;
@@ -337,17 +356,18 @@
 	}
 
 done:
-	(*printfn) ("%s+%x (", fn_name(subr), pc - subr);
+	(*printfn) ("%s+%lx (", fn_name(subr), (unsigned long) (pc - subr));
 	for (j = 0; j < 4; j ++) {
 		if (j > 0)
 			(*printfn)(",");
 		if (valid_args[j])
-			(*printfn)("%x", args[j]);
+			(*printfn)("%lx", (unsigned long) args[j]);
 		else
 			(*printfn)("?");
 	}
 
-	(*printfn) (") ra %x sp %x sz %d\n", ra, sp, stksize);
+	(*printfn) (") ra %lx sp %lx sz %ld\n", (unsigned long) ra,
+		    (unsigned long) sp, (long) stksize);
 
 	if (ra) {
 		if (pc == ra && stksize == 0)
@@ -403,8 +423,12 @@
 	struct pcb *ctx;
 
 	if (thr == curthread) {
-		sp = (register_t)(intptr_t)__builtin_frame_address(0);
-		ra = (register_t)(intptr_t)__builtin_return_address(0);
+        	__asm __volatile(
+                         "move %0, $sp\n"
+                         : "=r" (sp));
+        	__asm __volatile(
+                         "move %0, $ra\n"
+                         : "=r" (ra));
 
         	__asm __volatile(
 			"jal 99f\n"


More information about the freebsd-mips mailing list