Source-Changes-HG archive

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

[src/nathanw_sa]: src/lib/libpthread/arch/i386 Define, initialize, and use fu...



details:   https://anonhg.NetBSD.org/src/rev/a3717cd0f29f
branches:  nathanw_sa
changeset: 506160:a3717cd0f29f
user:      nathanw <nathanw%NetBSD.org@localhost>
date:      Wed Aug 14 18:48:00 2002 +0000

description:
Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.

diffstat:

 lib/libpthread/arch/i386/_context_u.S     |  104 +++++++++++------------------
 lib/libpthread/arch/i386/_getsetc.S       |   97 +++++++++++++++++++++++++++
 lib/libpthread/arch/i386/genassym.cf      |    4 +-
 lib/libpthread/arch/i386/pthread_md.h     |   20 +++++-
 lib/libpthread/arch/i386/pthread_switch.S |   12 +-
 5 files changed, 165 insertions(+), 72 deletions(-)

diffs (truncated from 338 to 300 lines):

diff -r ee146d5a7c59 -r a3717cd0f29f lib/libpthread/arch/i386/_context_u.S
--- a/lib/libpthread/arch/i386/_context_u.S     Wed Aug 14 18:41:50 2002 +0000
+++ b/lib/libpthread/arch/i386/_context_u.S     Wed Aug 14 18:48:00 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: _context_u.S,v 1.1.2.8 2002/04/24 20:04:12 nathanw Exp $       */
+/*     $NetBSD: _context_u.S,v 1.1.2.9 2002/08/14 18:48:00 nathanw Exp $       */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -39,68 +39,12 @@
 #include <machine/asm.h>
 #include "assym.h"
 
-#define GETC \
-       movl    %edi,  (UC_REGS + _REG_EDI * 4)(%ecx)   ; \
-       movl    %esi,  (UC_REGS + _REG_ESI * 4)(%ecx)   ; \
-       movl    %ebp,  (UC_REGS + _REG_EBP * 4)(%ecx)   ; \
-       movl    %ebx,  (UC_REGS + _REG_EBX * 4)(%ecx)   ; \
-       movl    %edx,  (UC_REGS + _REG_EIP * 4)(%ecx)   ; \
-       fnsave  UC_FPREGS(%ecx)                         ; \
-       movl    $(_UC_USER | _UC_CPU | _UC_FPU),%eax    ; \
-       movl    %eax,   UC_FLAGS(%ecx)  
 
-#define SETC \
-       bt      $_UC_USER_BIT, UC_FLAGS(%ecx)           ; \
-       jnc     1f                                      ; \
-                                                       ; \
-       movl    (UC_REGS + _REG_EDI * 4)(%ecx), %edi    ; \
-       movl    (UC_REGS + _REG_ESI * 4)(%ecx), %esi    ; \
-       movl    (UC_REGS + _REG_EBP * 4)(%ecx), %ebp    ; \
-       movl    (UC_REGS + _REG_EBX * 4)(%ecx), %ebx    ; \
-       movl    (UC_REGS + _REG_UESP * 4)(%ecx), %edx   ; \
-       movl    (UC_REGS + _REG_EIP * 4)(%ecx), %eax    ; \
-       movl    %eax, -4(%edx)                          ; \
-       leal    -4(%edx), %esp                          ; \
-       ret                                             ; \
-                                                       ; \
-1:     movl    UC_FLAGS(%ecx), %eax                    ; \
-       and     $_UC_FPU, %eax                          ; \
-       jz      2f                                      ; \
-       frstor  UC_FPREGS(%ecx)                         ; \
-2:     movl    (UC_REGS + _REG_GS * 4)(%ecx), %gs      ; \
-       movl    (UC_REGS + _REG_FS * 4)(%ecx), %fs      ; \
-       movl    (UC_REGS + _REG_ES * 4)(%ecx), %es      ; \
-       movl    (UC_REGS + _REG_EDI * 4)(%ecx), %edi    ; \
-       movl    (UC_REGS + _REG_ESI * 4)(%ecx), %esi    ; \
-       movl    (UC_REGS + _REG_EBP * 4)(%ecx), %ebp    ; \
-       movl    (UC_REGS + _REG_EBX * 4)(%ecx), %ebx    ; \
-       movl    (UC_REGS + _REG_UESP * 4)(%ecx), %edx   ; \
-       movl    (UC_REGS + _REG_CS * 4)(%ecx), %eax     ; \
-       mov     %eax, -4(%edx)                          ; \
-       movl    (UC_REGS + _REG_EIP * 4)(%ecx), %eax    ; \
-       movl    %eax, -8(%edx)                          ; \
-       movl    (UC_REGS + _REG_DS * 4)(%ecx), %eax     ; \
-       movl    %eax, -12(%edx)                         ; \
-       movl    (UC_REGS + _REG_EDX * 4)(%ecx), %eax    ; \
-       movl    %eax, -16(%edx)                         ; \
-       movl    (UC_REGS + _REG_ECX * 4)(%ecx), %eax    ; \
-       movl    %eax, -20(%edx)                         ; \
-       movl    (UC_REGS + _REG_EAX * 4)(%ecx), %eax    ; \
-       movl    %eax, -24(%edx)                         ; \
-       movl    (UC_REGS + _REG_EFL * 4)(%ecx), %eax    ; \
-       movl    %eax, -28(%edx)                         ; \
-       movl    (UC_REGS + _REG_SS * 4)(%ecx), %ss      ; \
-       leal    -28(%edx), %esp                         ; \
-       popfl                                           ; \
-       popl    %eax                                    ; \
-       popl    %ecx                                    ; \
-       popl    %edx                                    ; \
-       popl    %ds                                     ; \
-       lret
-
-
-
-ENTRY(_getcontext_u)
+#define FPSAVE(reg)    fnsave UC_FPREGS(reg)
+#define FPLOAD(reg)    frstor UC_FPREGS(reg)
+#include "_getsetc.S"
+       
+ENTRY(_getcontext_u_s87)
        movl    4(%esp), %ecx
        movl    0(%esp), %edx
        GETC
@@ -110,11 +54,11 @@
        xorl    %eax,  %eax
        ret
 
-ENTRY(_setcontext_u)                                   
+ENTRY(_setcontext_u_s87)                                       
        movl    4(%esp), %ecx
        SETC
 
-ENTRY(_swapcontext_u)
+ENTRY(_swapcontext_u_s87)
        movl    4(%esp), %ecx
        movl    0(%esp), %edx
        GETC
@@ -123,3 +67,35 @@
        movl    %eax, (UC_REGS + _REG_UESP * 4)(%ecx)
        movl    8(%esp), %ecx
        SETC
+
+
+#undef FPSAVE
+#undef FPLOAD
+               
+#define FPSAVE(reg)    fxrstor UC_FXSAVEREGS(reg)
+#define FPLOAD(reg)    fxsave UC_FXSAVEREGS(reg)
+#include "_getsetc.S"
+
+ENTRY(_getcontext_u_xmm)
+       movl    4(%esp), %ecx
+       movl    0(%esp), %edx
+       GETC
+       movl    %esp, %eax
+       addl    $4, %eax
+       movl    %eax, (UC_REGS + _REG_UESP * 4)(%ecx)
+       xorl    %eax,  %eax
+       ret
+
+ENTRY(_setcontext_u_xmm)                                       
+       movl    4(%esp), %ecx
+       SETC
+
+ENTRY(_swapcontext_u_xmm)
+       movl    4(%esp), %ecx
+       movl    0(%esp), %edx
+       GETC
+       movl    %esp, %eax
+       addl    $4, %eax
+       movl    %eax, (UC_REGS + _REG_UESP * 4)(%ecx)
+       movl    8(%esp), %ecx
+       SETC
diff -r ee146d5a7c59 -r a3717cd0f29f lib/libpthread/arch/i386/_getsetc.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/arch/i386/_getsetc.S       Wed Aug 14 18:48:00 2002 +0000
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nathan J. Williams.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#undef GETC
+#undef SETC
+
+#define GETC \
+       movl    %edi,  (UC_REGS + _REG_EDI * 4)(%ecx)   ; \
+       movl    %esi,  (UC_REGS + _REG_ESI * 4)(%ecx)   ; \
+       movl    %ebp,  (UC_REGS + _REG_EBP * 4)(%ecx)   ; \
+       movl    %ebx,  (UC_REGS + _REG_EBX * 4)(%ecx)   ; \
+       movl    %edx,  (UC_REGS + _REG_EIP * 4)(%ecx)   ; \
+       FPSAVE(%ecx)                                    ; \
+       movl    $(_UC_USER | _UC_CPU | _UC_FPU),%eax    ; \
+       movl    %eax,   UC_FLAGS(%ecx)  
+
+#define SETC \
+       movl    UC_FLAGS(%ecx), %eax                    ; \
+       bt      $_UC_USER_BIT, %eax                     ; \
+       jnc     1f                                      ; \
+                                                       ; \
+       movl    (UC_REGS + _REG_EDI * 4)(%ecx), %edi    ; \
+       movl    (UC_REGS + _REG_ESI * 4)(%ecx), %esi    ; \
+       movl    (UC_REGS + _REG_EBP * 4)(%ecx), %ebp    ; \
+       movl    (UC_REGS + _REG_EBX * 4)(%ecx), %ebx    ; \
+       movl    (UC_REGS + _REG_UESP * 4)(%ecx), %edx   ; \
+       movl    (UC_REGS + _REG_EIP * 4)(%ecx), %eax    ; \
+       movl    %eax, -4(%edx)                          ; \
+       leal    -4(%edx), %esp                          ; \
+       ret                                             ; \
+                                                       ; \
+1:     bt      $_UC_FPU, %eax                          ; \
+       jnc     2f                                      ; \
+       FPLOAD(%ecx)                                    ; \
+2:     movl    (UC_REGS + _REG_GS * 4)(%ecx), %gs      ; \
+       movl    (UC_REGS + _REG_FS * 4)(%ecx), %fs      ; \
+       movl    (UC_REGS + _REG_ES * 4)(%ecx), %es      ; \
+       movl    (UC_REGS + _REG_EDI * 4)(%ecx), %edi    ; \
+       movl    (UC_REGS + _REG_ESI * 4)(%ecx), %esi    ; \
+       movl    (UC_REGS + _REG_EBP * 4)(%ecx), %ebp    ; \
+       movl    (UC_REGS + _REG_EBX * 4)(%ecx), %ebx    ; \
+       movl    (UC_REGS + _REG_UESP * 4)(%ecx), %edx   ; \
+       movl    (UC_REGS + _REG_CS * 4)(%ecx), %eax     ; \
+       mov     %eax, -4(%edx)                          ; \
+       movl    (UC_REGS + _REG_EIP * 4)(%ecx), %eax    ; \
+       movl    %eax, -8(%edx)                          ; \
+       movl    (UC_REGS + _REG_DS * 4)(%ecx), %eax     ; \
+       movl    %eax, -12(%edx)                         ; \
+       movl    (UC_REGS + _REG_EDX * 4)(%ecx), %eax    ; \
+       movl    %eax, -16(%edx)                         ; \
+       movl    (UC_REGS + _REG_ECX * 4)(%ecx), %eax    ; \
+       movl    %eax, -20(%edx)                         ; \
+       movl    (UC_REGS + _REG_EAX * 4)(%ecx), %eax    ; \
+       movl    %eax, -24(%edx)                         ; \
+       movl    (UC_REGS + _REG_EFL * 4)(%ecx), %eax    ; \
+       movl    %eax, -28(%edx)                         ; \
+       movl    (UC_REGS + _REG_SS * 4)(%ecx), %ss      ; \
+       leal    -28(%edx), %esp                         ; \
+       popfl                                           ; \
+       popl    %eax                                    ; \
+       popl    %ecx                                    ; \
+       popl    %edx                                    ; \
+       popl    %ds                                     ; \
+       lret
diff -r ee146d5a7c59 -r a3717cd0f29f lib/libpthread/arch/i386/genassym.cf
--- a/lib/libpthread/arch/i386/genassym.cf      Wed Aug 14 18:41:50 2002 +0000
+++ b/lib/libpthread/arch/i386/genassym.cf      Wed Aug 14 18:48:00 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.1.2.8 2002/03/25 03:43:02 nathanw Exp $
+#      $NetBSD: genassym.cf,v 1.1.2.9 2002/08/14 18:48:00 nathanw Exp $
 
 # Copyright (c) 2001 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -55,6 +55,8 @@
 define UC_REGS         offsetof(ucontext_t, uc_mcontext.__gregs)
 define UC_EIP          offsetof(ucontext_t, uc_mcontext.__gregs[_REG_EIP])
 define UC_FPREGS       offsetof(ucontext_t, uc_mcontext.__fpregs.__fp_reg_set.__fpchip_state.__fp_state)
+define UC_FXSAVEREGS   offsetof(ucontext_t, uc_mcontext.__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm)
+
 define PT_STATE_RECYCLABLE     PT_STATE_RECYCLABLE
 define STACKSPACE              STACKSPACE
 
diff -r ee146d5a7c59 -r a3717cd0f29f lib/libpthread/arch/i386/pthread_md.h
--- a/lib/libpthread/arch/i386/pthread_md.h     Wed Aug 14 18:41:50 2002 +0000
+++ b/lib/libpthread/arch/i386/pthread_md.h     Wed Aug 14 18:48:00 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_md.h,v 1.1.2.5 2002/04/24 05:20:48 nathanw Exp $       */
+/*     $NetBSD: pthread_md.h,v 1.1.2.6 2002/08/14 18:48:01 nathanw Exp $       */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -39,6 +39,24 @@
 #ifndef _LIB_PTHREAD_I386_MD_H
 #define _LIB_PTHREAD_I386_MD_H
 
+extern int (*_md_getcontext_u)(ucontext_t *);
+extern int (*_md_setcontext_u)(const ucontext_t *);
+extern int (*_md_swapcontext_u)(ucontext_t *, const ucontext_t *);
+
+#define _getcontext_u(uc) (*_md_getcontext_u)((uc))
+#define _setcontext_u(uc) (*_md_setcontext_u)((uc))
+#define _swapcontext_u(ouc, nuc) (*_md_swapcontext_u)((ouc), (nuc))
+
+int _getcontext_u_s87(ucontext_t *);
+int _setcontext_u_s87(const ucontext_t *);
+int _swapcontext_u_s87(ucontext_t *, const ucontext_t *);
+int _getcontext_u_xmm(ucontext_t *);
+int _setcontext_u_xmm(const ucontext_t *);
+int _swapcontext_u_xmm(ucontext_t *, const ucontext_t *);
+
+void pthread__i386_init(void);
+
+#define PTHREAD_MD_INIT pthread__i386_init();
 
 static __inline long
 pthread__sp(void)
diff -r ee146d5a7c59 -r a3717cd0f29f lib/libpthread/arch/i386/pthread_switch.S
--- a/lib/libpthread/arch/i386/pthread_switch.S Wed Aug 14 18:41:50 2002 +0000
+++ b/lib/libpthread/arch/i386/pthread_switch.S Wed Aug 14 18:48:00 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_switch.S,v 1.1.2.12 2001/09/04 21:21:08 nathanw Exp $  */
+/*     $NetBSD: pthread_switch.S,v 1.1.2.13 2002/08/14 18:48:01 nathanw Exp $  */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
        movl    PT_UC(%ecx), %esi
        pushl   %esi                    /* ucontext_t *ucp */
        pushl   %edi                    /* ucontext_t *oucp */
-       call    PIC_PLT(_C_LABEL(_swapcontext_u))



Home | Main Index | Thread Index | Old Index