sh: convert /proc/cpu/aligmnent, /proc/cpu/kernel_alignment to seq_file
[safe/jmp/linux-2.6] / arch / sh / kernel / traps_32.c
index 6aba9af..3da5a12 100644 (file)
@@ -25,6 +25,8 @@
 #include <linux/kexec.h>
 #include <linux/limits.h>
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <linux/sysfs.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/fpu.h>
@@ -54,8 +56,8 @@ static unsigned long se_multi;
 /* bitfield: 1: warn 2: fixup 4: signal -> combinations 2|4 && 1|2|4 are not
    valid! */
 static int se_usermode = 3;
-/* 0: no warning 1: print a warning message */
-static int se_kernmode_warn = 1;
+/* 0: no warning 1: print a warning message, disabled by default */
+static int se_kernmode_warn;
 
 #ifdef CONFIG_PROC_FS
 static const char *se_usermode_action[] = {
@@ -67,61 +69,49 @@ static const char *se_usermode_action[] = {
        "signal+warn"
 };
 
-static int
-proc_alignment_read(char *page, char **start, off_t off, int count, int *eof,
-                   void *data)
+static int alignment_proc_show(struct seq_file *m, void *v)
 {
-       char *p = page;
-       int len;
-
-       p += sprintf(p, "User:\t\t%lu\n", se_user);
-       p += sprintf(p, "System:\t\t%lu\n", se_sys);
-       p += sprintf(p, "Half:\t\t%lu\n", se_half);
-       p += sprintf(p, "Word:\t\t%lu\n", se_word);
-       p += sprintf(p, "DWord:\t\t%lu\n", se_dword);
-       p += sprintf(p, "Multi:\t\t%lu\n", se_multi);
-       p += sprintf(p, "User faults:\t%i (%s)\n", se_usermode,
+       seq_printf(m, "User:\t\t%lu\n", se_user);
+       seq_printf(m, "System:\t\t%lu\n", se_sys);
+       seq_printf(m, "Half:\t\t%lu\n", se_half);
+       seq_printf(m, "Word:\t\t%lu\n", se_word);
+       seq_printf(m, "DWord:\t\t%lu\n", se_dword);
+       seq_printf(m, "Multi:\t\t%lu\n", se_multi);
+       seq_printf(m, "User faults:\t%i (%s)\n", se_usermode,
                        se_usermode_action[se_usermode]);
-       p += sprintf(p, "Kernel faults:\t%i (fixup%s)\n", se_kernmode_warn,
+       seq_printf(m, "Kernel faults:\t%i (fixup%s)\n", se_kernmode_warn,
                        se_kernmode_warn ? "+warn" : "");
-
-       len = (p - page) - off;
-       if (len < 0)
-               len = 0;
-
-       *eof = (len <= count) ? 1 : 0;
-       *start = page + off;
-
-       return len;
+       return 0;
 }
 
-static int proc_alignment_write(struct file *file, const char __user *buffer,
-                               unsigned long count, void *data)
+static int alignment_proc_open(struct inode *inode, struct file *file)
 {
-       char mode;
-
-       if (count > 0) {
-               if (get_user(mode, buffer))
-                       return -EFAULT;
-               if (mode >= '0' && mode <= '5')
-                       se_usermode = mode - '0';
-       }
-       return count;
+       return single_open(file, alignment_proc_show, NULL);
 }
 
-static int proc_alignment_kern_write(struct file *file, const char __user *buffer,
-                                    unsigned long count, void *data)
+static ssize_t alignment_proc_write(struct file *file,
+               const char __user *buffer, size_t count, loff_t *pos)
 {
+       int *data = PDE(file->f_path.dentry->d_inode)->data;
        char mode;
 
        if (count > 0) {
                if (get_user(mode, buffer))
                        return -EFAULT;
-               if (mode >= '0' && mode <= '1')
-                       se_kernmode_warn = mode - '0';
+               if (mode >= '0' && mode <= '5')
+                       *data = mode - '0';
        }
        return count;
 }
+
+static const struct file_operations alignment_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = alignment_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .write          = alignment_proc_write,
+};
 #endif
 
 static void dump_mem(const char *str, unsigned long bottom, unsigned long top)
@@ -159,12 +149,12 @@ void die(const char * str, struct pt_regs * regs, long err)
 
        oops_enter();
 
-       console_verbose();
        spin_lock_irq(&die_lock);
+       console_verbose();
        bust_spinlocks(1);
 
        printk("%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
-
+       sysfs_printk_last_file();
        print_modules();
        show_regs(regs);
 
@@ -180,6 +170,7 @@ void die(const char * str, struct pt_regs * regs, long err)
        bust_spinlocks(0);
        add_taint(TAINT_DIE);
        spin_unlock_irq(&die_lock);
+       oops_exit();
 
        if (kexec_should_crash(current))
                crash_kexec(regs);
@@ -190,7 +181,6 @@ void die(const char * str, struct pt_regs * regs, long err)
        if (panic_on_oops)
                panic("Fatal exception");
 
-       oops_exit();
        do_exit(SIGSEGV);
 }
 
@@ -452,6 +442,12 @@ int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs,
        u_int rm;
        int ret, index;
 
+       /*
+        * XXX: We can't handle mixed 16/32-bit instructions yet
+        */
+       if (instruction_size(instruction) != 2)
+               return -EINVAL;
+
        index = (instruction>>8)&15;    /* 0x0F00 */
        rm = regs->regs[index];
 
@@ -619,9 +615,9 @@ asmlinkage void do_address_error(struct pt_regs *regs,
 
                se_user += 1;
 
-#ifndef CONFIG_CPU_SH2A
                set_fs(USER_DS);
-               if (copy_from_user(&instruction, (u16 *)(regs->pc & ~1), 2)) {
+               if (copy_from_user(&instruction, (insn_size_t *)(regs->pc & ~1),
+                                  sizeof(instruction))) {
                        set_fs(oldfs);
                        goto uspace_segv;
                }
@@ -633,7 +629,6 @@ asmlinkage void do_address_error(struct pt_regs *regs,
                               "in \"%s\" pid=%d pc=0x%p ins=0x%04hx\n",
                               current->comm, current->pid, (void *)regs->pc,
                               instruction);
-#endif
 
                if (se_usermode & 2)
                        goto fixup;
@@ -673,12 +668,6 @@ uspace_segv:
        } else {
                se_sys += 1;
 
-               if (se_kernmode_warn)
-                       printk(KERN_NOTICE "Unaligned kernel access "
-                              "on behalf of \"%s\" pid=%d pc=0x%p ins=0x%04hx\n",
-                              current->comm, current->pid, (void *)regs->pc,
-                              instruction);
-
                if (regs->pc & 1)
                        die("unaligned program counter", regs, error_code);
 
@@ -692,6 +681,12 @@ uspace_segv:
                        die("insn faulting in do_address_error", regs, 0);
                }
 
+               if (se_kernmode_warn)
+                       printk(KERN_NOTICE "Unaligned kernel access "
+                              "on behalf of \"%s\" pid=%d pc=0x%p ins=0x%04hx\n",
+                              current->comm, current->pid, (void *)regs->pc,
+                              instruction);
+
                handle_unaligned_access(instruction, regs,
                                        &user_mem_access, 0);
                set_fs(oldfs);
@@ -939,14 +934,9 @@ void __init trap_init(void)
        set_exception_table_evt(0x800, do_reserved_inst);
        set_exception_table_evt(0x820, do_illegal_slot_inst);
 #elif defined(CONFIG_SH_FPU)
-#ifdef CONFIG_CPU_SUBTYPE_SHX3
-       set_exception_table_evt(0xd80, fpu_state_restore_trap_handler);
-       set_exception_table_evt(0xda0, fpu_state_restore_trap_handler);
-#else
        set_exception_table_evt(0x800, fpu_state_restore_trap_handler);
        set_exception_table_evt(0x820, fpu_state_restore_trap_handler);
 #endif
-#endif
 
 #ifdef CONFIG_CPU_SH2
        set_exception_table_vec(TRAP_ADDRESS_ERROR, address_error_trap_handler);
@@ -1005,20 +995,16 @@ static int __init alignment_init(void)
        if (!dir)
                return -ENOMEM;
 
-       res = create_proc_entry("alignment", S_IWUSR | S_IRUGO, dir);
+       res = proc_create_data("alignment", S_IWUSR | S_IRUGO, dir,
+                              &alignment_proc_fops, &se_usermode);
        if (!res)
                return -ENOMEM;
 
-       res->read_proc = proc_alignment_read;
-       res->write_proc = proc_alignment_write;
-
-        res = create_proc_entry("kernel_alignment", S_IWUSR | S_IRUGO, dir);
+        res = proc_create_data("kernel_alignment", S_IWUSR | S_IRUGO, dir,
+                              &alignment_proc_fops, &se_kernmode_warn);
         if (!res)
                 return -ENOMEM;
 
-        res->read_proc = proc_alignment_read;
-        res->write_proc = proc_alignment_kern_write;
-
        return 0;
 }