Index: sys/arch/amd64/amd64/genassym.cf =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/amd64/genassym.cf,v retrieving revision 1.68 diff -u -r1.68 genassym.cf --- sys/arch/amd64/amd64/genassym.cf 30 Mar 2018 10:01:36 -0000 1.68 +++ sys/arch/amd64/amd64/genassym.cf 14 Jul 2018 16:04:39 -0000 @@ -190,6 +190,7 @@ define PCB_COMPAT32 PCB_COMPAT32 define PCB_FS offsetof(struct pcb, pcb_fs) define PCB_GS offsetof(struct pcb, pcb_gs) +define PCB_DBREGS offsetof(struct pcb, pcb_dbregs) define TF_RDI offsetof(struct trapframe, tf_rdi) define TF_RSI offsetof(struct trapframe, tf_rsi) Index: sys/arch/amd64/amd64/locore.S =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/amd64/locore.S,v retrieving revision 1.171 diff -u -r1.171 locore.S --- sys/arch/amd64/amd64/locore.S 14 Jul 2018 14:29:40 -0000 1.171 +++ sys/arch/amd64/amd64/locore.S 14 Jul 2018 16:04:39 -0000 @@ -1142,6 +1142,40 @@ #endif .Lring0_switched: + /* New lwp using dbregs? If so, restore. */ + cmpq $0,PCB_DBREGS(%r14) + jne .Ldbregs_restore + + /* Old lwp using dbregs? If so, reset. */ + testq %r13,%r13 /* oldlwp = NULL ? */ + jz .Ldbregs_done + movq L_PCB(%r13),%rax + cmpq $0,PCB_DBREGS(%rax) + je .Ldbregs_done + + /* Reset the dbregs. */ + xorq %rax,%rax + movq %rax,%dr7 + movq %rax,%dr6 + jmp .Ldbregs_done + + /* Restore the dbregs. */ +.Ldbregs_restore: + movq PCB_DBREGS(%r14),%rax + movq (0*8)(%rax),%rdx + movq %rdx,%dr0 + movq (1*8)(%rax),%rdx + movq %rdx,%dr1 + movq (2*8)(%rax),%rdx + movq %rdx,%dr2 + movq (3*8)(%rax),%rdx + movq %rdx,%dr3 + movq (6*8)(%rax),%rdx + movq %rdx,%dr6 + movq (7*8)(%rax),%rdx + movq %rdx,%dr7 +.Ldbregs_done: + #ifndef XEN movb _C_LABEL(x86_fpu_eager),%dl testb %dl,%dl Index: sys/arch/amd64/amd64/machdep.c =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/amd64/machdep.c,v retrieving revision 1.306 diff -u -r1.306 machdep.c --- sys/arch/amd64/amd64/machdep.c 12 Jul 2018 19:48:16 -0000 1.306 +++ sys/arch/amd64/amd64/machdep.c 14 Jul 2018 16:04:39 -0000 @@ -1368,6 +1368,7 @@ if (pcb->pcb_dbregs != NULL) { pool_put(&x86_dbregspl, pcb->pcb_dbregs); pcb->pcb_dbregs = NULL; + x86_dbregs_clear(l); } l->l_proc->p_flag &= ~PK_32; Index: sys/arch/amd64/amd64/netbsd32_machdep.c =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/amd64/netbsd32_machdep.c,v retrieving revision 1.115 diff -u -r1.115 netbsd32_machdep.c --- sys/arch/amd64/amd64/netbsd32_machdep.c 7 Dec 2017 23:11:50 -0000 1.115 +++ sys/arch/amd64/amd64/netbsd32_machdep.c 14 Jul 2018 16:04:39 -0000 @@ -62,6 +62,7 @@ #include #include +#include #include #include #include @@ -141,6 +142,7 @@ if (pcb->pcb_dbregs != NULL) { pool_put(&x86_dbregspl, pcb->pcb_dbregs); pcb->pcb_dbregs = NULL; + x86_dbregs_clear(l); } p->p_flag |= PK_32; Index: sys/arch/amd64/amd64/trap.c =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/amd64/trap.c,v retrieving revision 1.113 diff -u -r1.113 trap.c --- sys/arch/amd64/amd64/trap.c 25 Feb 2018 13:09:33 -0000 1.113 +++ sys/arch/amd64/amd64/trap.c 14 Jul 2018 16:04:39 -0000 @@ -93,6 +93,7 @@ #include #include +#include #include #include #include Index: sys/arch/amd64/include/userret.h =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/include/userret.h,v retrieving revision 1.12 diff -u -r1.12 userret.h --- sys/arch/amd64/include/userret.h 23 Feb 2017 03:34:22 -0000 1.12 +++ sys/arch/amd64/include/userret.h 14 Jul 2018 16:04:39 -0000 @@ -67,7 +67,6 @@ */ #include -#include static __inline void userret(struct lwp *); @@ -78,13 +77,6 @@ static __inline void userret(struct lwp *l) { - struct pcb *pcb = lwp_getpcb(l); - /* Invoke MI userret code */ mi_userret(l); - - if (pcb->pcb_dbregs) - x86_dbregs_set(l); - else - x86_dbregs_clear(l); } Index: sys/arch/x86/x86/vm_machdep.c =================================================================== RCS file: /cvsroot/src/sys/arch/x86/x86/vm_machdep.c,v retrieving revision 1.35 diff -u -r1.35 vm_machdep.c --- sys/arch/x86/x86/vm_machdep.c 1 Jul 2018 08:32:41 -0000 1.35 +++ sys/arch/x86/x86/vm_machdep.c 14 Jul 2018 16:04:40 -0000 @@ -291,6 +291,7 @@ if (pcb->pcb_dbregs) { pool_put(&x86_dbregspl, pcb->pcb_dbregs); pcb->pcb_dbregs = NULL; + x86_dbregs_clear(l); } }