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/sparc Port of Andrey Petrovs sparc6...



details:   https://anonhg.NetBSD.org/src/rev/8c4c63918377
branches:  nathanw_sa
changeset: 506484:8c4c63918377
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Nov 23 14:14:47 2002 +0000

description:
Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.

diffstat:

 lib/libpthread/arch/sparc/_context_u.S     |   98 +++++++++
 lib/libpthread/arch/sparc/genassym.cf      |   55 +++++
 lib/libpthread/arch/sparc/pthread_md.h     |   83 ++++++++
 lib/libpthread/arch/sparc/pthread_switch.S |  295 +++++++++++++++++++++++++++++
 4 files changed, 531 insertions(+), 0 deletions(-)

diffs (truncated from 547 to 300 lines):

diff -r 5179c0806764 -r 8c4c63918377 lib/libpthread/arch/sparc/_context_u.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/arch/sparc/_context_u.S    Sat Nov 23 14:14:47 2002 +0000
@@ -0,0 +1,98 @@
+/*     $NetBSD: _context_u.S,v 1.1.2.1 2002/11/23 14:14:47 martin Exp $        */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#include <machine/asm.h>
+#include <machine/trap.h>
+#include "assym.h"
+
+#define        FLUSHW                  t T_FLUSHWIN
+#define NOTREACHED             t T_DIV0
+
+       .global _C_LABEL(setcontext)
+
+       /*
+       * For voluntary context switches save/restore take care
+       * of caller's window, the only registers which should be
+       * saved are frame pointer and return address
+       */
+
+#define GETC(reg)                                        \
+       st      %i6, [ reg + UC_GREG + _REG_O6 * 4 ]    ; \
+       add     %i7, 8, %l0                             ; \
+       st      %l0, [ reg + UC_GREG + _REG_PC * 4 ]    ; \
+                                                         \
+       sethi   %hi(0x40000000), %l1                    ; \
+       or      %l1, _UC_CPU, %l1                       ; \
+                                                         \
+       st      %l1, [ reg + UC_FLAGS ]
+
+#define SETC(reg)                                        \
+       ld      [ reg + UC_FLAGS ], %l0                 ; \
+       sethi   %hi(0x40000000), %l1                    ; \
+       andcc   %l0, %l1, %g0                           ; \
+       bz      1f                                      ; \
+        nop                                            ; \
+                                                         \
+       ld      [ reg + UC_GREG + _REG_PC * 4 ], %i7    ; \
+       ld      [ reg + UC_GREG + _REG_O6 * 4 ], %i6    ; \
+                                                       ; \
+       jmp     %i7                                     ; \
+        restore                                        ; \
+1:     call _C_LABEL(setcontext)                       ; \
+        mov    reg, %o0
+
+ENTRY(_getcontext_u)
+       save    %sp, -CCFSZ, %sp
+       FLUSHW                          ! XXX
+       GETC(%i0)
+       clr     %i0
+       ret
+        restore
+
+ENTRY(_setcontext_u)
+       save    %sp, -CCFSZ, %sp
+       FLUSHW
+       mov     %i0, %o0
+       SETC(%o0)
+       NOTREACHED
+
+ENTRY(_swapcontext_u)
+       save    %sp, -CCFSZ, %sp
+       FLUSHW
+       GETC(%i0)
+       mov %i1, %o0
+       SETC(%o0)
+       NOTREACHED
+
diff -r 5179c0806764 -r 8c4c63918377 lib/libpthread/arch/sparc/genassym.cf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/arch/sparc/genassym.cf     Sat Nov 23 14:14:47 2002 +0000
@@ -0,0 +1,55 @@
+#      $NetBSD: genassym.cf,v 1.1.2.1 2002/11/23 14:14:47 martin Exp $
+
+
+include <ucontext.h>
+include <sys/queue.h>
+include <machine/reg.h>
+include <machine/mcontext.h>
+include <machine/frame.h>
+include "pthread.h"
+include "pthread_int.h"
+include "pthread_md.h"
+
+define PT_NEXT          offsetof(struct pthread_st, pt_next)
+define PT_STATE         offsetof(struct pthread_st, pt_state)
+define PT_SWITCHTO      offsetof(struct pthread_st, pt_switchto)
+define PT_SWITCHTOUC    offsetof(struct pthread_st, pt_switchtouc)
+define PT_SLEEPUC       offsetof(struct pthread_st, pt_sleepuc)
+define PT_SPINLOCKS     offsetof(struct pthread_st, pt_spinlocks)
+define PT_HELDLOCK      offsetof(struct pthread_st, pt_heldlock)
+define PT_UC            offsetof(struct pthread_st, pt_uc)
+define CONTEXTSIZE      sizeof(ucontext_t)
+define UC_FLAGS                offsetof(ucontext_t, uc_flags)
+define UC_GREG         offsetof(ucontext_t, uc_mcontext.__greg)
+define UC_FPREG                offsetof(ucontext_t, uc_mcontext.__fpreg)
+define PT_STATE_RECYCLABLE      PT_STATE_RECYCLABLE
+define STACKSPACE       STACKSPACE
+define _UC_USER_BIT    _UC_USER_BIT
+define _UC_CPU         _UC_CPU
+define _UC_FPU         _UC_FPU
+
+define CCFSZ           CCFSZ
+
+define FPRS_FEF                FPRS_FEF
+
+define _REG_CCR        _REG_CCR
+define _REG_PC         _REG_PC
+define _REG_nPC        _REG_nPC
+define _REG_Y          _REG_Y
+define _REG_G1         _REG_G1
+define _REG_G2         _REG_G2
+define _REG_G3         _REG_G3
+define _REG_G4         _REG_G4
+define _REG_G5         _REG_G5
+define _REG_G6         _REG_G6
+define _REG_G7         _REG_G7
+define _REG_O0         _REG_O0
+define _REG_O1         _REG_O1
+define _REG_O2         _REG_O2
+define _REG_O3         _REG_O3
+define _REG_O4         _REG_O4
+define _REG_O5         _REG_O5
+define _REG_O6         _REG_O6
+define _REG_O7         _REG_O7
+define _REG_ASI        _REG_ASI
+define _REG_FPRS       _REG_FPRS
diff -r 5179c0806764 -r 8c4c63918377 lib/libpthread/arch/sparc/pthread_md.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/arch/sparc/pthread_md.h    Sat Nov 23 14:14:47 2002 +0000
@@ -0,0 +1,83 @@
+/*     $NetBSD: pthread_md.h,v 1.1.2.1 2002/11/23 14:14:47 martin Exp $        */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef _LIB_PTHREAD_SPARC_MD_H
+#define _LIB_PTHREAD_SPARC_MD_H
+
+/*
+ * pthread__sp used for identifying thread
+ */
+static __inline long
+pthread__sp(void)
+{
+       long ret;
+
+       __asm("mov %%sp, %0" : "=r" (ret));
+
+       return ret;
+}
+
+#define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__greg[_REG_O6])
+#define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__greg[_REG_PC])
+
+#define STACKSPACE 96  /* min stack frame XXX */
+
+/*
+ * Conversions between struct reg and struct mcontext. Used by
+ * libpthread_dbg.
+ * XXX macros
+ */
+
+#define PTHREAD_UCONTEXT_TO_REG(reg, uc) do {                          \
+       memcpy(&(reg)->r_global, &(uc)->uc_mcontext.__greg, sizeof(__gregset_t));\
+       } while (/*CONSTCOND*/0)
+
+#define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {                          \
+       memcpy(&(uc)->uc_mcontext.__greg, &(reg)->r_global, sizeof(__gregset_t));\
+       (uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;        \
+       } while (/*CONSTCOND*/0)
+
+#define PTHREAD_UCONTEXT_TO_FPREG(freg, uc)                            \
+       memcpy((freg), &(uc)->uc_mcontext.__freg,                       \
+           sizeof(struct fpreg))                                       \
+
+#define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {                               \
+       memcpy(&(uc)->uc_mcontext.__freg, (freg),                       \
+           sizeof(struct fpreg));                                      \
+       (uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;        \
+       } while (/*CONSTCOND*/0)
+
+#endif /* _LIB_PTHREAD_SPARC_MD_H */
+
diff -r 5179c0806764 -r 8c4c63918377 lib/libpthread/arch/sparc/pthread_switch.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpthread/arch/sparc/pthread_switch.S        Sat Nov 23 14:14:47 2002 +0000
@@ -0,0 +1,295 @@
+/*     $NetBSD: pthread_switch.S,v 1.1.2.1 2002/11/23 14:14:47 martin Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+/*
+ * This file implements low-level routines that are exported to
+ * the machine-independent parts of the thread library. The routines are:
+ * 
+ * void        pthread__switch(pthread_t self, pthread_t next);
+ * void        pthread__upcall_switch(pthread_t self, pthread_t next);
+ * void        pthread__locked_switch(pthread_t self, pthread_t next, 
+ *           pt_spin_t *lock);
+ *        
+ * as well as some utility code used by these routines. 
+ */
+
+#include <machine/asm.h>



Home | Main Index | Thread Index | Old Index