Home | History | Annotate | Line # | Download | only in sh3
pthread_md.h revision 1.1
      1  1.1  uwe /*	$NetBSD: pthread_md.h,v 1.1 2003/06/23 19:34:45 uwe Exp $ */
      2  1.1  uwe 
      3  1.1  uwe /*
      4  1.1  uwe  * Copyright 2003 Wasabi Systems, Inc.
      5  1.1  uwe  * All rights reserved.
      6  1.1  uwe  *
      7  1.1  uwe  * Written by Steve C. Woodford for Wasabi Systems, Inc.
      8  1.1  uwe  *
      9  1.1  uwe  * Redistribution and use in source and binary forms, with or without
     10  1.1  uwe  * modification, are permitted provided that the following conditions
     11  1.1  uwe  * are met:
     12  1.1  uwe  * 1. Redistributions of source code must retain the above copyright
     13  1.1  uwe  *    notice, this list of conditions and the following disclaimer.
     14  1.1  uwe  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  uwe  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  uwe  *    documentation and/or other materials provided with the distribution.
     17  1.1  uwe  * 3. All advertising materials mentioning features or use of this software
     18  1.1  uwe  *    must display the following acknowledgement:
     19  1.1  uwe  *      This product includes software developed for the NetBSD Project by
     20  1.1  uwe  *      Wasabi Systems, Inc.
     21  1.1  uwe  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1  uwe  *    or promote products derived from this software without specific prior
     23  1.1  uwe  *    written permission.
     24  1.1  uwe  *
     25  1.1  uwe  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1  uwe  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  uwe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  uwe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1  uwe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  uwe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  uwe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  uwe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  uwe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  uwe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  uwe  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  uwe  */
     37  1.1  uwe 
     38  1.1  uwe #ifndef _LIB_PTHREAD_SH3_MD_H
     39  1.1  uwe #define _LIB_PTHREAD_SH3_MD_H
     40  1.1  uwe 
     41  1.1  uwe static __inline long
     42  1.1  uwe pthread__sp(void)
     43  1.1  uwe {
     44  1.1  uwe 	long ret;
     45  1.1  uwe 	__asm("mov r15, %0" : "=r" (ret));
     46  1.1  uwe 
     47  1.1  uwe 	return ret;
     48  1.1  uwe }
     49  1.1  uwe 
     50  1.1  uwe #define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_R15])
     51  1.1  uwe #define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[_REG_PC])
     52  1.1  uwe 
     53  1.1  uwe 
     54  1.1  uwe /*
     55  1.1  uwe  * SH3 requires no extra stack space
     56  1.1  uwe  */
     57  1.1  uwe #define STACKSPACE	0
     58  1.1  uwe 
     59  1.1  uwe 
     60  1.1  uwe /*
     61  1.1  uwe  * Conversions between struct reg and struct mcontext. Used by
     62  1.1  uwe  * libpthread_dbg.
     63  1.1  uwe  */
     64  1.1  uwe 
     65  1.1  uwe #define PTHREAD_UCONTEXT_TO_REG(reg, uc)				\
     66  1.1  uwe 	memcpy((reg), &(uc)->uc_mcontext.__gregs[0], sizeof(*(reg)))
     67  1.1  uwe 
     68  1.1  uwe #define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {				\
     69  1.1  uwe 	memcpy(&(uc)->uc_mcontext.__gregs[0], (reg), sizeof(*(reg)));	\
     70  1.1  uwe 	(uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;	\
     71  1.1  uwe 	} while (/*CONSTCOND*/0)
     72  1.1  uwe 
     73  1.1  uwe #if 0 /* no struct fpreg!!! */
     74  1.1  uwe #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc)       			\
     75  1.1  uwe 	memcpy((freg), &(uc)->uc_mcontext.__fpregs, sizeof(*(freg)));
     76  1.1  uwe 
     77  1.1  uwe #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {       	       		\
     78  1.1  uwe 	memcpy(&(uc)->uc_mcontext.__fpregs, (freg), sizeof(*(freg)));	\
     79  1.1  uwe 	(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;       	\
     80  1.1  uwe 	} while (/*CONSTCOND*/0)
     81  1.1  uwe 
     82  1.1  uwe #else  /* SBUBS */
     83  1.1  uwe #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc)
     84  1.1  uwe #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg)
     85  1.1  uwe #endif
     86  1.1  uwe 
     87  1.1  uwe #endif /* _LIB_PTHREAD_SH3_MD_H */
     88