Module Name: src Committed By: maxv Date: Sat Oct 21 08:08:26 UTC 2017
Modified Files: src/sys/arch/amd64/amd64: locore.S trap.c Log Message: Use labels instead of disassembling *(%rip). intrfastexit is now the only place where the segregs can fault. To generate a diff of this commit: cvs rdiff -u -r1.137 -r1.138 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.103 -r1.104 src/sys/arch/amd64/amd64/trap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.137 src/sys/arch/amd64/amd64/locore.S:1.138 --- src/sys/arch/amd64/amd64/locore.S:1.137 Sat Oct 21 06:55:54 2017 +++ src/sys/arch/amd64/amd64/locore.S Sat Oct 21 08:08:26 2017 @@ -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 @@ lwp_32bit: 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 @@ ENTRY(intrfastexit) .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 Index: src/sys/arch/amd64/amd64/trap.c diff -u src/sys/arch/amd64/amd64/trap.c:1.103 src/sys/arch/amd64/amd64/trap.c:1.104 --- src/sys/arch/amd64/amd64/trap.c:1.103 Sat Oct 21 07:23:22 2017 +++ src/sys/arch/amd64/amd64/trap.c Sat Oct 21 08:08:26 2017 @@ -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 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 @@ trap_user_kernelmode(struct trapframe *f */ 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 @@ trap_user_kernelmode(struct trapframe *f 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 @@ trap_user_kernelmode(struct trapframe *f if (KERNELMODE(vframe->tf_cs)) return; /* There is no valid address for the fault */ - break; - - default: + } else { return; }