Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/amd64/amd64 Use labels instead of disassembling *(%...



details:   https://anonhg.NetBSD.org/src/rev/82670742981d
branches:  trunk
changeset: 827230:82670742981d
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Oct 21 08:08:26 2017 +0000

description:
Use labels instead of disassembling *(%rip). intrfastexit is now the
only place where the segregs can fault.

diffstat:

 sys/arch/amd64/amd64/locore.S |  12 ++++++++++--
 sys/arch/amd64/amd64/trap.c   |  23 ++++++++++-------------
 2 files changed, 20 insertions(+), 15 deletions(-)

diffs (110 lines):

diff -r 4c7a4f24b308 -r 82670742981d sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Sat Oct 21 07:24:26 2017 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Sat Oct 21 08:08:26 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.137 2017/10/21 06:55:54 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.138 2017/10/21 08:08:26 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -330,6 +330,10 @@
        .globl  _C_LABEL(biosextmem)
        .globl  _C_LABEL(lwp0uarea)
        .globl  do_sysret
+       .globl  do_mov_es
+       .globl  do_mov_ds
+       .globl  do_mov_fs
+       .globl  do_mov_gs
        .globl  do_iret
 
        .type   _C_LABEL(tablesize), @object
@@ -1196,7 +1200,7 @@
        movq    PCB_GS(%r14),%rax
        movq    %rax,(GUGS_SEL*8)(%rcx)
 
-       /* Set default 32bit values in %ds, %es, %fs and %gs. */
+       /* Set default 32bit values in %ds, %es and %fs. %gs is special. */
        movq    L_MD_REGS(%r12),%rbx
        movq    $GSEL(GUDATA32_SEL, SEL_UPL),%rax
        movw    %ax,%ds
@@ -1482,11 +1486,15 @@
 
 .Luexit32:
        NOT_XEN(cli;)
+do_mov_es:
        movw    TF_ES(%rsp),%es
+do_mov_ds:
        movw    TF_DS(%rsp),%ds
+do_mov_fs:
        movw    TF_FS(%rsp),%fs
        SWAPGS
 #ifndef XEN
+do_mov_gs:
        movw    TF_GS(%rsp),%gs
 #endif
        jmp     .Lkexit
diff -r 4c7a4f24b308 -r 82670742981d sys/arch/amd64/amd64/trap.c
--- a/sys/arch/amd64/amd64/trap.c       Sat Oct 21 07:24:26 2017 +0000
+++ b/sys/arch/amd64/amd64/trap.c       Sat Oct 21 08:08:26 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.103 2017/10/21 07:23:22 maxv Exp $  */
+/*     $NetBSD: trap.c,v 1.104 2017/10/21 08:08:26 maxv Exp $  */
 
 /*
  * Copyright (c) 1998, 2000, 2017 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.103 2017/10/21 07:23:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.104 2017/10/21 08:08:26 maxv Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -236,6 +236,8 @@
 static void
 trap_user_kernelmode(struct trapframe *frame, int type, lwp_t *l, proc_t *p)
 {
+       extern uint64_t do_mov_es, do_mov_ds, do_mov_fs, do_mov_gs;
+       extern uint64_t do_iret;
        struct trapframe *vframe;
        ksiginfo_t ksi;
 
@@ -260,8 +262,7 @@
         */
        vframe = (void *)frame->tf_rsp;
 
-       switch (*(uint16_t *)frame->tf_rip) {
-       case 0xcf48:    /* iretq */
+       if (frame->tf_rip == (uint64_t)&do_iret) {
                /*
                 * The 'iretq' instruction faulted, so we have the
                 * 'user' registers saved after the kernel
@@ -277,12 +278,10 @@
                memmove(vframe, frame, offsetof(struct trapframe, tf_rip));
                /* Set the faulting address to the user %rip */
                ksi.ksi_addr = (void *)vframe->tf_rip;
-               break;
-
-       case 0x848e:    /* mov 0xa8(%rsp),%es (8e 84 24 a8 00 00 00) */
-       case 0x9c8e:    /* mov 0xb0(%rsp),%ds (8e 9c 24 b0 00 00 00) */
-       case 0xa48e:    /* mov 0xa0(%rsp),%fs (8e a4 24 a0 00 00 00) */
-       case 0xac8e:    /* mov 0x98(%rsp),%gs (8e ac 24 98 00 00 00) */
+       } else if (frame->tf_rip == (uint64_t)&do_mov_es ||
+           frame->tf_rip == (uint64_t)&do_mov_ds ||
+           frame->tf_rip == (uint64_t)&do_mov_fs ||
+           frame->tf_rip == (uint64_t)&do_mov_gs) {
                /*
                 * We faulted loading one of the user segment registers.
                 * The stack frame containing the user registers is
@@ -291,9 +290,7 @@
                if (KERNELMODE(vframe->tf_cs))
                        return;
                /* There is no valid address for the fault */
-               break;
-
-       default:
+       } else {
                return;
        }
 



Home | Main Index | Thread Index | Old Index