In order to dynamically instrument kernel functions, I plan to add
breakpoints where a probe needs to be executed.  Trap handlers will
be modified to check if the address of the trapping instruction
correspond to a registered probe, and if that's the case, the kernel
will execute the associated code.

While implementing such mechanism for amd64 and i386, I discovered
some differences in the existing code that only history seems to justify.

So the diff below get rids of the BPTTRAP() and other small differences
around 'calltrap' for these architectures.  In particular interrupts
are now enabled unconditionally on i386 before entering trap().  Any
counter indication for doing so?

I wonder if I should split i386's locore.s to match amd64's vector.S...

Comments, ok?

Index: arch/amd64/amd64/vector.S
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/vector.S,v
retrieving revision 1.44
diff -u -p -r1.44 vector.S
--- arch/amd64/amd64/vector.S   8 Dec 2015 19:45:55 -0000       1.44
+++ arch/amd64/amd64/vector.S   28 Feb 2016 13:12:56 -0000
@@ -96,24 +96,22 @@
  * (possibly the next clock tick).  Thus, we disable interrupt before checking,
  * and only enable them again on the final `iret' or before calling the AST
  * handler.
- */ 
+ */
 
 /*****************************************************************************/
 
 #define        TRAP(a)         pushq $(a) ; jmp _C_LABEL(alltraps)
 #define        ZTRAP(a)        pushq $0 ; TRAP(a)
 
-#define        BPTTRAP(a)      ZTRAP(a)
-
        .text
 IDTVEC(trap00)
        ZTRAP(T_DIVIDE)
 IDTVEC(trap01)
-       BPTTRAP(T_TRCTRAP)
+       ZTRAP(T_TRCTRAP)
 IDTVEC(trap02)
        ZTRAP(T_NMI)
 IDTVEC(trap03)
-       BPTTRAP(T_BPTFLT)
+       ZTRAP(T_BPTFLT)
 IDTVEC(trap04)
        ZTRAP(T_OFLOW)
 IDTVEC(trap05)
@@ -245,7 +243,6 @@ NENTRY(resume_iret)
 NENTRY(alltraps)
        INTRENTRY
        sti
-       .globl  calltrap
 calltrap:
        cld
 #ifdef DIAGNOSTIC
Index: arch/i386/i386/locore.s
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/locore.s,v
retrieving revision 1.163
diff -u -p -r1.163 locore.s
--- arch/i386/i386/locore.s     26 Feb 2016 02:25:09 -0000      1.163
+++ arch/i386/i386/locore.s     28 Feb 2016 13:13:07 -0000
@@ -1306,16 +1306,11 @@ ENTRY(savectx)
  * (possibly the next clock tick).  Thus, we disable interrupt before checking,
  * and only enable them again on the final `iret' or before calling the AST
  * handler.
- *
- * XXX - debugger traps are now interrupt gates so at least bdb doesn't lose
- * control.  The sti's give the standard losing behaviour for ddb and kgdb.
  */
 #define        IDTVEC(name)    ALIGN_TEXT; .globl X##name; X##name:
 
 #define        TRAP(a)         pushl $(a) ; jmp _C_LABEL(alltraps)
 #define        ZTRAP(a)        pushl $0 ; TRAP(a)
-#define        BPTTRAP(a)      testb $(PSL_I>>8),13(%esp) ; jz 1f ; sti ; 1: ; 
\
-                       TRAP(a)
 
        .text
 IDTVEC(div)
@@ -1328,12 +1323,11 @@ IDTVEC(dbg)
        andb    $~0xf,%al
        movl    %eax,%dr6
        popl    %eax
-       BPTTRAP(T_TRCTRAP)
+       TRAP(T_TRCTRAP)
 IDTVEC(nmi)
        ZTRAP(T_NMI)
 IDTVEC(bpt)
-       pushl   $0
-       BPTTRAP(T_BPTFLT)
+       ZTRAP(T_BPTFLT)
 IDTVEC(ofl)
        ZTRAP(T_OFLOW)
 IDTVEC(bnd)
@@ -1447,8 +1441,13 @@ NENTRY(resume_pop_fs)
        sti
        jmp     calltrap
 
+/*
+ * All traps go through here. Call the generic trap handler, and
+ * check for ASTs afterwards.
+ */
 NENTRY(alltraps)
        INTRENTRY
+       sti
 calltrap:
 #ifdef DIAGNOSTIC
        movl    CPL,%ebx

Reply via email to