]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[MIPS] Add some debugfs files to debug unaligned accesses
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Fri, 29 Jun 2007 15:55:48 +0000 (00:55 +0900)
committerRalf Baechle <ralf@linux-mips.org>
Tue, 10 Jul 2007 16:33:04 +0000 (17:33 +0100)
Currently a number of unaligned instructions is counted but not used.
Add /debug/mips/unaligned_instructions file to show the value.

And add /debug/mips/unaligned_action to control behavior upon an
unaligned access.  Possible actions are:

0: silently fixup the unaligned access.
1: send SIGBUS.
2: dump registers, process name, etc. and fixup.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/kernel/setup.c
arch/mips/kernel/unaligned.c

index 4975da0bfb634cdf52ebffbfe2bffe68da61ace0..316685fca0592b555acaa46f3b2cdda49c39357a 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/highmem.h>
 #include <linux/console.h>
 #include <linux/pfn.h>
+#include <linux/debugfs.h>
 
 #include <asm/addrspace.h>
 #include <asm/bootinfo.h>
@@ -574,3 +575,18 @@ __setup("nodsp", dsp_disable);
 
 unsigned long kernelsp[NR_CPUS];
 unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
+
+#ifdef CONFIG_DEBUG_FS
+struct dentry *mips_debugfs_dir;
+static int __init debugfs_mips(void)
+{
+       struct dentry *d;
+
+       d = debugfs_create_dir("mips", NULL);
+       if (IS_ERR(d))
+               return PTR_ERR(d);
+       mips_debugfs_dir = d;
+       return 0;
+}
+arch_initcall(debugfs_mips);
+#endif
index 18c4a3c45a31c0df2da34693a349209e2b70cf22..8b9c34ffae184fecf7fe720eaa0b596305194fe9 100644 (file)
@@ -77,6 +77,7 @@
 #include <linux/signal.h>
 #include <linux/smp.h>
 #include <linux/sched.h>
+#include <linux/debugfs.h>
 #include <asm/asm.h>
 #include <asm/branch.h>
 #include <asm/byteorder.h>
 #define STR(x)  __STR(x)
 #define __STR(x)  #x
 
-#ifdef CONFIG_PROC_FS
-unsigned long unaligned_instructions;
+enum {
+       UNALIGNED_ACTION_QUIET,
+       UNALIGNED_ACTION_SIGNAL,
+       UNALIGNED_ACTION_SHOW,
+};
+#ifdef CONFIG_DEBUG_FS
+static u32 unaligned_instructions;
+static u32 unaligned_action;
+#else
+#define unaligned_action UNALIGNED_ACTION_QUIET
 #endif
+extern void show_registers(struct pt_regs *regs);
 
 static inline int emulate_load_store_insn(struct pt_regs *regs,
        void __user *addr, unsigned int __user *pc,
@@ -459,7 +469,7 @@ static inline int emulate_load_store_insn(struct pt_regs *regs,
                goto sigill;
        }
 
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_DEBUG_FS
        unaligned_instructions++;
 #endif
 
@@ -516,6 +526,10 @@ asmlinkage void do_ade(struct pt_regs *regs)
        pc = (unsigned int __user *) exception_epc(regs);
        if (user_mode(regs) && (current->thread.mflags & MF_FIXADE) == 0)
                goto sigbus;
+       if (unaligned_action == UNALIGNED_ACTION_SIGNAL)
+               goto sigbus;
+       else if (unaligned_action == UNALIGNED_ACTION_SHOW)
+               show_registers(regs);
 
        /*
         * Do branch emulation only if we didn't forward the exception.
@@ -546,3 +560,24 @@ sigbus:
         * XXX On return from the signal handler we should advance the epc
         */
 }
+
+#ifdef CONFIG_DEBUG_FS
+extern struct dentry *mips_debugfs_dir;
+static int __init debugfs_unaligned(void)
+{
+       struct dentry *d;
+
+       if (!mips_debugfs_dir)
+               return -ENODEV;
+       d = debugfs_create_u32("unaligned_instructions", S_IRUGO,
+                              mips_debugfs_dir, &unaligned_instructions);
+       if (IS_ERR(d))
+               return PTR_ERR(d);
+       d = debugfs_create_u32("unaligned_action", S_IRUGO | S_IWUSR,
+                              mips_debugfs_dir, &unaligned_action);
+       if (IS_ERR(d))
+               return PTR_ERR(d);
+       return 0;
+}
+__initcall(debugfs_unaligned);
+#endif