Port-i386 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: cleaning up NMI handling in trap()



On Sat, Mar 19, 2011 at 12:09:13PM +0100, Manuel Bouyer wrote:
> On Fri, Mar 18, 2011 at 05:02:29PM -0500, David Young wrote:
> > On Fri, Mar 18, 2011 at 09:50:10PM +0100, Manuel Bouyer wrote:
> > > The
> > >   printf ("NMI ... going to debugger\n");
> > > 
> > > is usefull in knowing what's going on. Can we please keep it in, in
> > > one form or another ?
> > 
> > Sure.  I can move it into kdb_trap() and kgdb_trap().
> 
> yes please

I've attached a new patch that does that.

Dave

-- 
David Young             OJC Technologies
dyoung%ojctech.com@localhost      Urbana, IL * (217) 344-0444 x24
Index: sys/arch/amd64/amd64/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/db_interface.c,v
retrieving revision 1.22
diff -u -p -r1.22 db_interface.c
--- sys/arch/amd64/amd64/db_interface.c 20 Dec 2010 00:25:24 -0000      1.22
+++ sys/arch/amd64/amd64/db_interface.c 20 Mar 2011 19:56:17 -0000
@@ -176,6 +176,8 @@ kdb_trap(int type, int code, db_regs_t *
        case T_BPTFLT:  /* breakpoint */
        case T_TRCTRAP: /* single_step */
        case T_NMI:     /* NMI */
+               printf("NMI ... going to debugger\n");
+               /*FALLTHROUGH*/
        case -1:        /* keyboard interrupt */
                break;
        default:
Index: sys/arch/amd64/amd64/trap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/trap.c,v
retrieving revision 1.65
diff -u -p -r1.65 trap.c
--- sys/arch/amd64/amd64/trap.c 20 Dec 2010 00:25:24 -0000      1.65
+++ sys/arch/amd64/amd64/trap.c 20 Mar 2011 19:56:17 -0000
@@ -98,9 +98,7 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.6
 #include <machine/reg.h>
 #include <machine/trap.h>
 #include <machine/userret.h>
-#ifdef DDB
 #include <machine/db_machdep.h>
-#endif
 
 #include <x86/nmi.h>
 
@@ -108,9 +106,7 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.6
 #include "isa.h"
 #endif
 
-#ifdef KGDB
 #include <sys/kgdb.h>
-#endif
 
 #ifdef KDTRACE_HOOKS
 #include <sys/dtrace_bsd.h>
@@ -283,24 +279,17 @@ trap(struct trapframe *frame)
                       " %lx cpl %x rsp %lx\n",
                    type, frame->tf_err, (u_long)frame->tf_rip, frame->tf_cs,
                    frame->tf_rflags, rcr2(), curcpu()->ci_ilevel, 
frame->tf_rsp);
-#ifdef DDB
                if (kdb_trap(type, 0, frame))
                        return;
-#endif
-#ifdef KGDB
                if (kgdb_trap(type, frame))
                        return;
-               else {
-                       /*
-                        * If this is a breakpoint, don't panic
-                        * if we're not connected.
-                        */
-                       if (type == T_BPTFLT) {
-                               printf("kgdb: ignored %s\n", trap_type[type]);
-                               return;
-                       }
+               /*
+                * If this is a breakpoint, don't panic if we're not connected.
+                */
+               if (type == T_BPTFLT && kgdb_disconnected()) {
+                       printf("kgdb: ignored %s\n", trap_type[type]);
+                       return;
                }
-#endif
                panic("trap");
                /*NOTREACHED*/
 
@@ -675,32 +664,17 @@ faultcommon:
                break;
 
        case T_NMI:
-#if !defined(XEN)
                if (nmi_dispatch(frame))
                        return;
-#endif /* !defined(XEN) */
-#if    NISA > 0
-#if defined(KGDB) || defined(DDB)
                /* NMI can be hooked up to a pushbutton for debugging */
-               printf ("NMI ... going to debugger\n");
-#ifdef KGDB
-
                if (kgdb_trap(type, frame))
                        return;
-#endif
-#ifdef DDB
                if (kdb_trap(type, 0, frame))
                        return;
-#endif
-#endif /* KGDB || DDB */
                /* machine/parity/power fail/"kitchen sink" faults */
 
-               if (x86_nmi() != 0)
-                       goto we_re_toast;
-               else
-                       return;
-#endif /* NISA > 0 */
-               ;       /* avoid a label at end of compound statement */
+               x86_nmi();
+               return;
        }
 
        if ((type & T_USER) == 0)
Index: sys/arch/i386/i386/db_interface.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/db_interface.c,v
retrieving revision 1.65
diff -u -p -r1.65 db_interface.c
--- sys/arch/i386/i386/db_interface.c   9 Jun 2010 02:48:52 -0000       1.65
+++ sys/arch/i386/i386/db_interface.c   20 Mar 2011 19:56:20 -0000
@@ -185,6 +185,8 @@ kdb_trap(int type, int code, db_regs_t *
        case T_BPTFLT:  /* breakpoint */
        case T_TRCTRAP: /* single_step */
        case T_NMI:     /* NMI */
+               printf("NMI ... going to debugger\n");
+               /*FALLTHROUGH*/
        case -1:        /* keyboard interrupt */
                break;
        default:
Index: sys/arch/i386/i386/kgdb_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/kgdb_machdep.c,v
retrieving revision 1.21
diff -u -p -r1.21 kgdb_machdep.c
--- sys/arch/i386/i386/kgdb_machdep.c   18 Oct 2009 18:14:00 -0000      1.21
+++ sys/arch/i386/i386/kgdb_machdep.c   20 Mar 2011 19:56:20 -0000
@@ -105,6 +105,13 @@ kgdb_acc(vaddr_t va, size_t len)
        return (1);
 }
 
+void
+kgdb_entry_notice(int type, db_regs_t *regs)
+{
+       if (type == T_NMI)
+               printf("NMI ... going to debugger\n");
+}
+
 /*
  * Translate a trap number into a unix compatible signal value.
  * (gdb only understands unix signal numbers).
Index: sys/arch/i386/i386/trap.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/trap.c,v
retrieving revision 1.260
diff -u -p -r1.260 trap.c
--- sys/arch/i386/i386/trap.c   20 Dec 2010 00:25:35 -0000      1.260
+++ sys/arch/i386/i386/trap.c   20 Mar 2011 19:56:20 -0000
@@ -102,22 +102,16 @@ __KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.2
 #include <machine/reg.h>
 #include <machine/trap.h>
 #include <machine/userret.h>
-#ifdef DDB
 #include <machine/db_machdep.h>
-#endif
 
 #include "mca.h"
-#if NMCA > 0
 #include <machine/mca_machdep.h>
-#endif
 
 #include <x86/nmi.h>
 
 #include "isa.h"
 
-#ifdef KGDB
 #include <sys/kgdb.h>
-#endif
 
 #include "npx.h"
 
@@ -388,24 +382,17 @@ trap(struct trapframe *frame)
                        check_dr0();
                else
                        trap_print(type, frame);
-#ifdef DDB
                if (kdb_trap(type, 0, frame))
                        return;
-#endif
-#ifdef KGDB
                if (kgdb_trap(type, frame))
                        return;
-               else {
-                       /*
-                        * If this is a breakpoint, don't panic
-                        * if we're not connected.
-                        */
-                       if (type == T_BPTFLT) {
-                               printf("kgdb: ignored %s\n", trap_type[type]);
-                               return;
-                       }
+               /*
+                * If this is a breakpoint, don't panic if we're not connected.
+                */
+               if (type == T_BPTFLT && kgdb_disconnected()) {
+                       printf("kgdb: ignored %s\n", trap_type[type]);
+                       return;
                }
-#endif
                panic("trap");
                /*NOTREACHED*/
 
@@ -806,40 +793,16 @@ faultcommon:
                break;
 
        case T_NMI:
-#if !defined(XEN)
                if (nmi_dispatch(frame))
                        return;
-#if (NISA > 0 || NMCA > 0)
-#if defined(KGDB) || defined(DDB)
                /* NMI can be hooked up to a pushbutton for debugging */
-               printf ("NMI ... going to debugger\n");
-#ifdef KGDB
-
                if (kgdb_trap(type, frame))
                        return;
-#endif
-#ifdef DDB
                if (kdb_trap(type, 0, frame))
                        return;
-#endif
-#endif /* KGDB || DDB */
                /* machine/parity/power fail/"kitchen sink" faults */
-
-#if NMCA > 0
-               /* mca_nmi() takes care to call x86_nmi() if appropriate */
-               if (mca_nmi() != 0)
-                       goto we_re_toast;
-               else
-                       return;
-#else /* NISA > 0 */
-               if (x86_nmi() != 0)
-                       goto we_re_toast;
-               else
-                       return;
-#endif /* NMCA > 0 */
-#endif /* (NISA > 0 || NMCA > 0) */
-#endif /* !defined(XEN) */
-               ;       /* avoid a label at end of compound statement */
+               mca_nmi();
+               x86_nmi();
        }
 
        if ((type & T_USER) == 0)
Index: sys/arch/i386/include/mca_machdep.h
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/include/mca_machdep.h,v
retrieving revision 1.13
diff -u -p -r1.13 mca_machdep.h
--- sys/arch/i386/include/mca_machdep.h 4 May 2009 12:19:29 -0000       1.13
+++ sys/arch/i386/include/mca_machdep.h 20 Mar 2011 19:56:20 -0000
@@ -42,7 +42,7 @@ extern struct x86_bus_dma_tag mca_bus_dm
 /* set to 1 if MCA bus is detected */
 extern int MCA_system;
 
-int    mca_nmi(void);
+void   mca_nmi(void);
 
 /*
  * Types provided to machine-independent MCA code.
Index: sys/arch/i386/mca/mca_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/mca/mca_machdep.c,v
retrieving revision 1.39
diff -u -p -r1.39 mca_machdep.c
--- sys/arch/i386/mca/mca_machdep.c     23 Mar 2010 21:18:23 -0000      1.39
+++ sys/arch/i386/mca/mca_machdep.c     20 Mar 2011 19:56:20 -0000
@@ -236,7 +236,7 @@ mca_intr_disestablish(mca_chipset_tag_t 
  * Handle a NMI.
  * return true to panic system, false to ignore.
  */
-int
+void
 mca_nmi(void)
 {
        /*
@@ -272,9 +272,8 @@ mca_nmi(void)
    out:
        if (!mcanmi) {
                /* no CHCK bits asserted, assume ISA NMI */
-               return (x86_nmi());
-       } else
-               return(0);
+               x86_nmi();
+       }
 }
 
 /*
Index: sys/arch/x86/conf/files.x86
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/conf/files.x86,v
retrieving revision 1.57
diff -u -p -r1.57 files.x86
--- sys/arch/x86/conf/files.x86 5 Feb 2011 14:00:34 -0000       1.57
+++ sys/arch/x86/conf/files.x86 20 Mar 2011 19:56:22 -0000
@@ -112,6 +112,9 @@ file        arch/x86/x86/coretemp.c         intel_core
 # VIA C7 Temperature sensor
 file   arch/x86/x86/viac7temp.c        via_c7temp
 
+# Stubs for x86 routines not included in the system
+file   arch/x86/x86/x86_stub.c
+
 # IPMI device
 device ipmi: sysmon_envsys, sysmon_wdog
 attach ipmi at ipmibus
Index: sys/arch/x86/include/intr.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/include/intr.h,v
retrieving revision 1.41
diff -u -p -r1.41 intr.h
--- sys/arch/x86/include/intr.h 2 May 2010 18:03:31 -0000       1.41
+++ sys/arch/x86/include/intr.h 20 Mar 2011 19:56:22 -0000
@@ -171,7 +171,7 @@ struct cpu_info;
 struct pcibus_attach_args;
 
 void intr_default_setup(void);
-int x86_nmi(void);
+void x86_nmi(void);
 void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void 
*, bool);
 void intr_disestablish(struct intrhand *);
 void intr_add_pcibus(struct pcibus_attach_args *);
Index: sys/arch/x86/x86/intr.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/intr.c,v
retrieving revision 1.70
diff -u -p -r1.70 intr.c
--- sys/arch/x86/x86/intr.c     22 Jan 2011 14:01:27 -0000      1.70
+++ sys/arch/x86/x86/intr.c     20 Mar 2011 19:56:25 -0000
@@ -222,12 +222,11 @@ intr_default_setup(void)
  * Handle a NMI, possibly a machine check.
  * return true to panic system, false to ignore.
  */
-int
+void
 x86_nmi(void)
 {
 
        log(LOG_CRIT, "NMI port 61 %x, port 70 %x\n", inb(0x61), inb(0x70));
-       return(0);
 }
 
 /*
Index: sys/arch/xen/conf/files.xen
===================================================================
RCS file: /cvsroot/src/sys/arch/xen/conf/files.xen,v
retrieving revision 1.110
diff -u -p -r1.110 files.xen
--- sys/arch/xen/conf/files.xen 2 Dec 2010 23:12:30 -0000       1.110
+++ sys/arch/xen/conf/files.xen 20 Mar 2011 19:56:25 -0000
@@ -270,6 +270,9 @@ file        arch/x86/x86/mpacpi.c           acpi
 file   arch/x86/x86/acpi_machdep.c     acpi
 file   arch/x86/x86/i8259.c
 
+# Stubs for x86 routines not included in the system
+file   arch/x86/x86/x86_stub.c
+
 # MP configuration using Intel SMP specification 1.4
 file   arch/x86/x86/mpbios.c           mpbios
 
@@ -280,6 +283,7 @@ file        arch/x86/pci/pci_bus_fixup.c    pci_bu
 file   arch/x86/pci/pci_addr_fixup.c   pci_addr_fixup
 
 file   arch/x86/x86/apic.c             ioapic
+file   arch/x86/x86/nmi.c
 
 device ioapic
 attach ioapic at ioapicbus
Index: sys/kern/kgdb_stub.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kgdb_stub.c,v
retrieving revision 1.23
diff -u -p -r1.23 kgdb_stub.c
--- sys/kern/kgdb_stub.c        11 Jan 2009 10:20:53 -0000      1.23
+++ sys/kern/kgdb_stub.c        20 Mar 2011 19:56:28 -0000
@@ -94,6 +94,14 @@ static kgdb_reg_t gdb_regs[KGDB_NUMREGS]
  */
 void (*db_trap_callback)(int);
 
+__weak_alias(kgdb_entry_notice, kgdb_voidop);
+
+static void
+kgdb_voidop(void)
+{
+       return;
+}
+
 /*
  * This little routine exists simply so that bcopy() can be debugged.
  */
@@ -321,6 +329,8 @@ kgdb_trap(int type, db_regs_t *regs)
        size_t len;
        u_char *p;
 
+       kgdb_entry_notice(type, regs);
+
        if (kgdb_dev == NODEV || kgdb_getc == NULL) {
                /* not debugging */
                return (0);
@@ -527,3 +537,9 @@ kgdb_trap(int type, db_regs_t *regs)
        kgdb_recover = 0;
        return (1);
 }
+
+int
+kgdb_disconnected(void)
+{
+       return 1;
+}
Index: sys/sys/kgdb.h
===================================================================
RCS file: /cvsroot/src/sys/sys/kgdb.h,v
retrieving revision 1.11
diff -u -p -r1.11 kgdb.h
--- sys/sys/kgdb.h      11 Jan 2009 10:20:53 -0000      1.11
+++ sys/sys/kgdb.h      20 Mar 2011 19:56:31 -0000
@@ -89,12 +89,14 @@ void kgdb_attach(int (*)(void *), void (
 void kgdb_connect(int);
 void kgdb_panic(void);
 int kgdb_trap(int, db_regs_t *);
+int kgdb_disconnected(void);
 
 /*
  * Machine dependent functions needed by kgdb_stub.c
  */
 int kgdb_signal(int);
 int kgdb_acc(vaddr_t, size_t);
+void kgdb_entry_notice(int, db_regs_t *);
 void kgdb_getregs(db_regs_t *, kgdb_reg_t *);
 void kgdb_setregs(db_regs_t *, kgdb_reg_t *);
 
Index: sys/arch/amd64/amd64/kgdb_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/amd64/amd64/kgdb_machdep.c,v
retrieving revision 1.7
diff -u -p -r1.7 kgdb_machdep.c
--- sys/arch/amd64/amd64/kgdb_machdep.c 20 Dec 2010 00:25:24 -0000      1.7
+++ sys/arch/amd64/amd64/kgdb_machdep.c 20 Mar 2011 20:25:48 -0000
@@ -99,6 +99,13 @@ kgdb_acc(vaddr_t va, size_t len)
        return (1);
 }
 
+void
+kgdb_entry_notice(int type, db_regs_t *regs)
+{
+       if (type == T_NMI)
+               printf("NMI ... going to debugger\n");
+}
+
 /*
  * Translate a trap number into a unix compatible signal value.
  * (gdb only understands unix signal numbers).


Home | Main Index | Thread Index | Old Index