x86, kgdb, init: Add early and late debug states
[sfrench/cifs-2.6.git] / arch / x86 / kernel / kgdb.c
index b2258ca9100349c2618d00e4aadf8c7cdd62bb26..2b71ec41869ff5df2a6e2cd99d594e7698ec311f 100644 (file)
 #include <asm/debugreg.h>
 #include <asm/apicdef.h>
 #include <asm/system.h>
-
 #include <asm/apic.h>
 
-/*
- * Put the error code here just in case the user cares:
- */
-static int gdb_x86errcode;
-
-/*
- * Likewise, the vector number here (since GDB only gets the signal
- * number through the usual means, and that's not very specific):
- */
-static int gdb_x86vector = -1;
-
 /**
  *     pt_regs_to_gdb_regs - Convert ptrace regs to GDB regs
  *     @gdb_regs: A pointer to hold the registers in the order GDB wants.
@@ -399,23 +387,6 @@ void kgdb_disable_hw_debug(struct pt_regs *regs)
        }
 }
 
-/**
- *     kgdb_post_primary_code - Save error vector/code numbers.
- *     @regs: Original pt_regs.
- *     @e_vector: Original error vector.
- *     @err_code: Original error code.
- *
- *     This is needed on architectures which support SMP and KGDB.
- *     This function is called after all the slave cpus have been put
- *     to a know spin state and the primary CPU has control over KGDB.
- */
-void kgdb_post_primary_code(struct pt_regs *regs, int e_vector, int err_code)
-{
-       /* primary processor is completely in the debugger */
-       gdb_x86vector = e_vector;
-       gdb_x86errcode = err_code;
-}
-
 #ifdef CONFIG_SMP
 /**
  *     kgdb_roundup_cpus - Get other CPUs into a holding pattern
@@ -567,7 +538,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
                        return NOTIFY_DONE;
        }
 
-       if (kgdb_handle_exception(args->trapnr, args->signr, args->err, regs))
+       if (kgdb_handle_exception(args->trapnr, args->signr, cmd, regs))
                return NOTIFY_DONE;
 
        /* Must touch watchdog before return to normal operation */
@@ -575,6 +546,26 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
        return NOTIFY_STOP;
 }
 
+#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
+int kgdb_ll_trap(int cmd, const char *str,
+                struct pt_regs *regs, long err, int trap, int sig)
+{
+       struct die_args args = {
+               .regs   = regs,
+               .str    = str,
+               .err    = err,
+               .trapnr = trap,
+               .signr  = sig,
+
+       };
+
+       if (!kgdb_io_module_registered)
+               return NOTIFY_DONE;
+
+       return __kgdb_notify(&args, cmd);
+}
+#endif /* CONFIG_KGDB_LOW_LEVEL_TRAP */
+
 static int
 kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
 {
@@ -604,15 +595,16 @@ static struct notifier_block kgdb_notifier = {
  *     specific callbacks.
  */
 int kgdb_arch_init(void)
+{
+       return register_die_notifier(&kgdb_notifier);
+}
+
+void kgdb_arch_late(void)
 {
        int i, cpu;
-       int ret;
        struct perf_event_attr attr;
        struct perf_event **pevent;
 
-       ret = register_die_notifier(&kgdb_notifier);
-       if (ret != 0)
-               return ret;
        /*
         * Pre-allocate the hw breakpoint structions in the non-atomic
         * portion of kgdb because this operation requires mutexs to
@@ -624,12 +616,15 @@ int kgdb_arch_init(void)
        attr.bp_type = HW_BREAKPOINT_W;
        attr.disabled = 1;
        for (i = 0; i < 4; i++) {
+               if (breakinfo[i].pev)
+                       continue;
                breakinfo[i].pev = register_wide_hw_breakpoint(&attr, NULL);
                if (IS_ERR(breakinfo[i].pev)) {
-                       printk(KERN_ERR "kgdb: Could not allocate hw breakpoints\n");
+                       printk(KERN_ERR "kgdb: Could not allocate hw"
+                              "breakpoints\nDisabling the kernel debugger\n");
                        breakinfo[i].pev = NULL;
                        kgdb_arch_exit();
-                       return -1;
+                       return;
                }
                for_each_online_cpu(cpu) {
                        pevent = per_cpu_ptr(breakinfo[i].pev, cpu);
@@ -640,7 +635,6 @@ int kgdb_arch_init(void)
                        }
                }
        }
-       return ret;
 }
 
 /**
@@ -690,6 +684,11 @@ unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
        return instruction_pointer(regs);
 }
 
+void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
+{
+       regs->ip = ip;
+}
+
 struct kgdb_arch arch_kgdb_ops = {
        /* Breakpoint instruction: */
        .gdb_bpt_instr          = { 0xcc },