Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/x86_64 Consistently handle segment selectors in tra...
details: https://anonhg.NetBSD.org/src/rev/f5c2674547aa
branches: trunk
changeset: 534051:f5c2674547aa
user: fvdl <fvdl%NetBSD.org@localhost>
date: Sun Jul 14 12:20:45 2002 +0000
description:
Consistently handle segment selectors in traps and interrupts.
diffstat:
sys/arch/x86_64/include/frame.h | 10 ++-
sys/arch/x86_64/include/frameasm.h | 94 +++++++++++++++++-------------
sys/arch/x86_64/x86_64/genassym.cf | 6 +-
sys/arch/x86_64/x86_64/locore.S | 12 +---
sys/arch/x86_64/x86_64/machdep.c | 32 ++++------
sys/arch/x86_64/x86_64/netbsd32_machdep.c | 64 +++++---------------
sys/arch/x86_64/x86_64/netbsd32_sigcode.S | 4 -
sys/arch/x86_64/x86_64/vector.S | 23 +++++-
8 files changed, 114 insertions(+), 131 deletions(-)
diffs (truncated from 434 to 300 lines):
diff -r 80b09180dccd -r f5c2674547aa sys/arch/x86_64/include/frame.h
--- a/sys/arch/x86_64/include/frame.h Sun Jul 14 10:40:54 2002 +0000
+++ b/sys/arch/x86_64/include/frame.h Sun Jul 14 12:20:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: frame.h,v 1.4 2002/06/25 01:24:49 thorpej Exp $ */
+/* $NetBSD: frame.h,v 1.5 2002/07/14 12:20:45 fvdl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -107,6 +107,10 @@
int64_t tf_rdx;
int64_t tf_rcx;
int64_t tf_rax;
+ int64_t tf_gs;
+ int64_t tf_fs;
+ int64_t tf_es;
+ int64_t tf_ds;
int64_t tf_trapno;
/* below portion defined in hardware */
int64_t tf_err;
@@ -138,6 +142,10 @@
int64_t if_rdx;
int64_t if_rcx;
int64_t if_rax;
+ int64_t tf_gs;
+ int64_t tf_fs;
+ int64_t tf_es;
+ int64_t tf_ds;
u_int64_t __if_trapno; /* for compat with trap frame - trapno */
u_int64_t __if_err; /* for compat with trap frame - err */
/* below portion defined in hardware */
diff -r 80b09180dccd -r f5c2674547aa sys/arch/x86_64/include/frameasm.h
--- a/sys/arch/x86_64/include/frameasm.h Sun Jul 14 10:40:54 2002 +0000
+++ b/sys/arch/x86_64/include/frameasm.h Sun Jul 14 12:20:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: frameasm.h,v 1.3 2002/06/03 18:23:16 fvdl Exp $ */
+/* $NetBSD: frameasm.h,v 1.4 2002/07/14 12:20:45 fvdl Exp $ */
#ifndef _X86_64_MACHINE_FRAMEASM_H
#define _X86_64_MACHINE_FRAMEASM_H
@@ -11,52 +11,64 @@
/*
* These are used on interrupt or trap entry or exit.
*/
-#define INTR_SAVEARGS \
- pushq %rax ; \
- pushq %rcx ; \
- pushq %rdx ; \
- pushq %rbx ; \
- pushq %rbp ; \
- pushq %rsi ; \
- pushq %rdi ; \
- pushq %r8 ; \
- pushq %r9 ; \
- pushq %r10 ; \
- pushq %r11 ; \
- pushq %r12 ; \
- pushq %r13 ; \
- pushq %r14 ; \
- pushq %r15
+#define INTR_SAVE_GPRS \
+ subq $120,%rsp ; \
+ movq %r15,0(%rsp) ; \
+ movq %r14,8(%rsp) ; \
+ movq %r13,16(%rsp) ; \
+ movq %r12,24(%rsp) ; \
+ movq %r11,32(%rsp) ; \
+ movq %r10,40(%rsp) ; \
+ movq %r9,48(%rsp) ; \
+ movq %r8,56(%rsp) ; \
+ movq %rdi,64(%rsp) ; \
+ movq %rsi,72(%rsp) ; \
+ movq %rbp,80(%rsp) ; \
+ movq %rbx,88(%rsp) ; \
+ movq %rdx,96(%rsp) ; \
+ movq %rcx,104(%rsp) ; \
+ movq %rax,112(%rsp)
-#define INTR_RESTOREARGS \
- popq %r15 ; \
- popq %r14 ; \
- popq %r13 ; \
- popq %r12 ; \
- popq %r11 ; \
- popq %r10 ; \
- popq %r9 ; \
- popq %r8 ; \
- popq %rdi ; \
- popq %rsi ; \
- popq %rbp ; \
- popq %rbx ; \
- popq %rdx ; \
- popq %rcx ; \
- popq %rax
+#define INTR_RESTORE_GPRS \
+ movq 0(%rsp),%r15 ; \
+ movq 8(%rsp),%r14 ; \
+ movq 16(%rsp),%r13 ; \
+ movq 24(%rsp),%r12 ; \
+ movq 32(%rsp),%r11 ; \
+ movq 40(%rsp),%r10 ; \
+ movq 48(%rsp),%r9 ; \
+ movq 56(%rsp),%r8 ; \
+ movq 64(%rsp),%rdi ; \
+ movq 72(%rsp),%rsi ; \
+ movq 80(%rsp),%rbp ; \
+ movq 88(%rsp),%rbx ; \
+ movq 96(%rsp),%rdx ; \
+ movq 104(%rsp),%rcx ; \
+ movq 112(%rsp),%rax ; \
+ addq $120,%rsp
#define INTRENTRY \
- testq $SEL_UPL,24(%rsp) ; \
+ subq $32,%rsp ; \
+ testq $SEL_UPL,56(%rsp) ; \
je 98f ; \
swapgs ; \
-98: INTR_SAVEARGS
+ movw %gs,0(%rsp) ; \
+ movw %fs,8(%rsp) ; \
+ movw %ds,16(%rsp) ; \
+ movw %es,24(%rsp) ; \
+98: INTR_SAVE_GPRS
#define INTRFASTEXIT \
- INTR_RESTOREARGS ; \
- addq $16,%rsp ; \
- testq $SEL_UPL,8(%rsp) ;\
- je 99f ;\
- swapgs ;\
-99: iretq
+ INTR_RESTORE_GPRS ; \
+ testq $SEL_UPL,56(%rsp) ; \
+ je 99f ; \
+ cli ; \
+ swapgs ; \
+ movw 0(%rsp),%gs ; \
+ movw 8(%rsp),%fs ; \
+ movw 16(%rsp),%ds ; \
+ movw 24(%rsp),%es ; \
+99: addq $48,%rsp ; \
+ iretq
#endif /* _X86_64_MACHINE_FRAMEASM_H */
diff -r 80b09180dccd -r f5c2674547aa sys/arch/x86_64/x86_64/genassym.cf
--- a/sys/arch/x86_64/x86_64/genassym.cf Sun Jul 14 10:40:54 2002 +0000
+++ b/sys/arch/x86_64/x86_64/genassym.cf Sun Jul 14 12:20:45 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.6 2002/06/25 01:24:50 thorpej Exp $
+# $NetBSD: genassym.cf,v 1.7 2002/07/14 12:20:45 fvdl Exp $
#
# Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -154,6 +154,10 @@
define PCB_ONFAULT offsetof(struct pcb, pcb_onfault)
define TF_CS offsetof(struct trapframe, tf_cs)
+define TF_DS offsetof(struct trapframe, tf_ds)
+define TF_ES offsetof(struct trapframe, tf_es)
+define TF_FS offsetof(struct trapframe, tf_fs)
+define TF_GS offsetof(struct trapframe, tf_gs)
define TF_RIP offsetof(struct trapframe, tf_rip)
define TF_RSP offsetof(struct trapframe, tf_rsp)
define TF_SS offsetof(struct trapframe, tf_ss)
diff -r 80b09180dccd -r f5c2674547aa sys/arch/x86_64/x86_64/locore.S
--- a/sys/arch/x86_64/x86_64/locore.S Sun Jul 14 10:40:54 2002 +0000
+++ b/sys/arch/x86_64/x86_64/locore.S Sun Jul 14 12:20:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.8 2002/07/04 10:34:22 fvdl Exp $ */
+/* $NetBSD: locore.S,v 1.9 2002/07/14 12:20:45 fvdl Exp $ */
/*
* Copyright-o-rama!
@@ -666,10 +666,6 @@
* Handler has returned here as if we called it. The sigcontext
* is now the first thing on the stack.
*/
- movl SC_FS(%rsp),%ecx /* XXXfvdl these are wrong */
- movl SC_GS(%rsp),%edx
- movl %ecx,%fs
- movl %edx,%gs
movq %rsp,%rdi
pushq %rdi /* fake return address */
movq $SYS___sigreturn14,%rax
@@ -1115,12 +1111,6 @@
/* We're always in the kernel, so we don't need the LDT. */
-#if 0
- movl $GSEL(GUDATA_SEL,SEL_KPL),%ecx
- movl %ecx,%fs
- movl %ecx,%gs
-#endif
-
/* Restore cr0 (including FPU state). */
movl PCB_CR0(%rsi),%ecx
movq %rcx,%cr0
diff -r 80b09180dccd -r f5c2674547aa sys/arch/x86_64/x86_64/machdep.c
--- a/sys/arch/x86_64/x86_64/machdep.c Sun Jul 14 10:40:54 2002 +0000
+++ b/sys/arch/x86_64/x86_64/machdep.c Sun Jul 14 12:20:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.15 2002/07/10 01:55:43 fvdl Exp $ */
+/* $NetBSD: machdep.c,v 1.16 2002/07/14 12:20:45 fvdl Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -537,12 +537,10 @@
}
/* Save register context. */
- __asm("movl %%gs,%0" : "=r" (frame.sf_sc.sc_gs));
- __asm("movl %%fs,%0" : "=r" (frame.sf_sc.sc_fs));
-#if 0
frame.sf_sc.sc_es = tf->tf_es;
frame.sf_sc.sc_ds = tf->tf_ds;
-#endif
+ frame.sf_sc.sc_fs = tf->tf_fs;
+ frame.sf_sc.sc_gs = tf->tf_gs;
frame.sf_sc.sc_rflags = tf->tf_rflags;
frame.sf_sc.sc_r15 = tf->tf_r15;
frame.sf_sc.sc_r14 = tf->tf_r14;
@@ -584,12 +582,11 @@
/*
* Build context to run handler in.
*/
-#if 0
- __asm("movl %0,%%gs" : : "r" (GSEL(GUDATA_SEL, SEL_UPL)));
- __asm("movl %0,%%fs" : : "r" (GSEL(GUDATA_SEL, SEL_UPL)));
+ tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL);
tf->tf_es = GSEL(GUDATA_SEL, SEL_UPL);
- tf->tf_ds = GSEL(GUDATA_SEL, SEL_UPL);
-#endif
+ tf->tf_fs = GSEL(GUDATA_SEL, SEL_UPL);
+ tf->tf_gs = GSEL(GUDATA_SEL, SEL_UPL);
+
tf->tf_rdi = sig;
tf->tf_rsi = code;
tf->tf_rdx = (int64_t) &fp->sf_sc;
@@ -648,11 +645,10 @@
!USERMODE(context.sc_cs, context.sc_rflags))
return (EINVAL);
- /* %fs and %gs were restored by the trampoline. */
-#if 0
+ tf->tf_ds = context.sc_ds;
tf->tf_es = context.sc_es;
- tf->tf_ds = context.sc_ds;
-#endif
+ tf->tf_fs = context.sc_fs;
+ tf->tf_gs = context.sc_gs;
tf->tf_rflags = context.sc_rflags;
tf->tf_rdi = context.sc_rdi;
tf->tf_rsi = context.sc_rsi;
@@ -1028,12 +1024,10 @@
p->p_flag &= ~P_32;
tf = p->p_md.md_regs;
-#if 0
- __asm("movl %0,%%gs" : : "r" (LSEL(LUDATA_SEL, SEL_UPL)));
- __asm("movl %0,%%fs" : : "r" (LSEL(LUDATA_SEL, SEL_UPL)));
+ tf->tf_ds = LSEL(LUDATA_SEL, SEL_UPL);
tf->tf_es = LSEL(LUDATA_SEL, SEL_UPL);
- tf->tf_ds = LSEL(LUDATA_SEL, SEL_UPL);
-#endif
+ tf->tf_fs = LSEL(LUDATA_SEL, SEL_UPL);
+ tf->tf_gs = LSEL(LUDATA_SEL, SEL_UPL);
tf->tf_rdi = 0;
tf->tf_rsi = 0;
tf->tf_rbp = 0;
diff -r 80b09180dccd -r f5c2674547aa sys/arch/x86_64/x86_64/netbsd32_machdep.c
--- a/sys/arch/x86_64/x86_64/netbsd32_machdep.c Sun Jul 14 10:40:54 2002 +0000
+++ b/sys/arch/x86_64/x86_64/netbsd32_machdep.c Sun Jul 14 12:20:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netbsd32_machdep.c,v 1.10 2002/07/07 23:25:37 fvdl Exp $ */
+/* $NetBSD: netbsd32_machdep.c,v 1.11 2002/07/14 12:20:46 fvdl Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -97,23 +97,10 @@
p->p_flag |= P_32;
tf = p->p_md.md_regs;
-#if 0
- __asm("movl %0,%%gs" : : "r" (LSEL(LUDATA32_SEL, SEL_UPL)));
- __asm("movl %0,%%fs" : : "r" (LSEL(LUDATA32_SEL, SEL_UPL)));
-#endif
-
- /*
- * XXXfvdl needs to be revisited
- * if USER_LDT is going to be supported, these need
- * to be saved/restored.
- */
-#if 1
- __asm("movl %0,%%ds" : : "r" (LSEL(LUDATA32_SEL, SEL_UPL)));
- __asm("movl %0,%%es" : : "r" (LSEL(LUDATA32_SEL, SEL_UPL)));
-#else
+ tf->tf_ds = LSEL(LUDATA32_SEL, SEL_UPL);
tf->tf_es = LSEL(LUDATA32_SEL, SEL_UPL);
- tf->tf_ds = LSEL(LUDATA32_SEL, SEL_UPL);
Home |
Main Index |
Thread Index |
Old Index