Home | History | Annotate | Line # | Download | only in sh3
pthread_md.h revision 1.6.4.2
      1  1.6.4.2  uwe /*	$NetBSD: pthread_md.h,v 1.6.4.2 2008/10/27 00:52:08 uwe Exp $ */
      2  1.6.4.2  uwe 
      3  1.6.4.2  uwe /*
      4  1.6.4.2  uwe  * Copyright 2003 Wasabi Systems, Inc.
      5  1.6.4.2  uwe  * All rights reserved.
      6  1.6.4.2  uwe  *
      7  1.6.4.2  uwe  * Written by Steve C. Woodford for Wasabi Systems, Inc.
      8  1.6.4.2  uwe  *
      9  1.6.4.2  uwe  * Redistribution and use in source and binary forms, with or without
     10  1.6.4.2  uwe  * modification, are permitted provided that the following conditions
     11  1.6.4.2  uwe  * are met:
     12  1.6.4.2  uwe  * 1. Redistributions of source code must retain the above copyright
     13  1.6.4.2  uwe  *    notice, this list of conditions and the following disclaimer.
     14  1.6.4.2  uwe  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.6.4.2  uwe  *    notice, this list of conditions and the following disclaimer in the
     16  1.6.4.2  uwe  *    documentation and/or other materials provided with the distribution.
     17  1.6.4.2  uwe  * 3. All advertising materials mentioning features or use of this software
     18  1.6.4.2  uwe  *    must display the following acknowledgement:
     19  1.6.4.2  uwe  *      This product includes software developed for the NetBSD Project by
     20  1.6.4.2  uwe  *      Wasabi Systems, Inc.
     21  1.6.4.2  uwe  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.6.4.2  uwe  *    or promote products derived from this software without specific prior
     23  1.6.4.2  uwe  *    written permission.
     24  1.6.4.2  uwe  *
     25  1.6.4.2  uwe  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.6.4.2  uwe  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.6.4.2  uwe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.6.4.2  uwe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.6.4.2  uwe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.6.4.2  uwe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.6.4.2  uwe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.6.4.2  uwe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.6.4.2  uwe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.6.4.2  uwe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.6.4.2  uwe  * POSSIBILITY OF SUCH DAMAGE.
     36  1.6.4.2  uwe  */
     37  1.6.4.2  uwe 
     38  1.6.4.2  uwe #ifndef _LIB_PTHREAD_SH3_MD_H
     39  1.6.4.2  uwe #define _LIB_PTHREAD_SH3_MD_H
     40  1.6.4.2  uwe 
     41  1.6.4.2  uwe static inline long
     42  1.6.4.2  uwe pthread__sp(void)
     43  1.6.4.2  uwe {
     44  1.6.4.2  uwe 	long ret;
     45  1.6.4.2  uwe 	__asm("mov r15, %0" : "=r" (ret));
     46  1.6.4.2  uwe 
     47  1.6.4.2  uwe 	return ret;
     48  1.6.4.2  uwe }
     49  1.6.4.2  uwe 
     50  1.6.4.2  uwe #define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_R15])
     51  1.6.4.2  uwe #define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[_REG_PC])
     52  1.6.4.2  uwe 
     53  1.6.4.2  uwe /*
     54  1.6.4.2  uwe  * Set initial, sane values for registers whose values aren't just
     55  1.6.4.2  uwe  * "don't care".
     56  1.6.4.2  uwe  */
     57  1.6.4.2  uwe #define _INITCONTEXT_U_MD(ucp)						\
     58  1.6.4.2  uwe 	(ucp)->uc_mcontext.__gregs[_REG_SR] = 0;
     59  1.6.4.2  uwe 
     60  1.6.4.2  uwe /*
     61  1.6.4.2  uwe  * SH3 requires no extra stack space
     62  1.6.4.2  uwe  */
     63  1.6.4.2  uwe #define STACKSPACE	0
     64  1.6.4.2  uwe 
     65  1.6.4.2  uwe 
     66  1.6.4.2  uwe /*
     67  1.6.4.2  uwe  * Conversions between struct reg and struct mcontext. Used by
     68  1.6.4.2  uwe  * libpthread_dbg.
     69  1.6.4.2  uwe  */
     70  1.6.4.2  uwe 
     71  1.6.4.2  uwe #define PTHREAD_UCONTEXT_TO_REG(reg, uc) do {				\
     72  1.6.4.2  uwe 	(reg)->r_spc = (uc)->uc_mcontext.__gregs[_REG_PC];		\
     73  1.6.4.2  uwe 	(reg)->r_ssr = (uc)->uc_mcontext.__gregs[_REG_SR];		\
     74  1.6.4.2  uwe 	(reg)->r_pr = (uc)->uc_mcontext.__gregs[_REG_PR];		\
     75  1.6.4.2  uwe 	(reg)->r_mach = (uc)->uc_mcontext.__gregs[_REG_MACH];		\
     76  1.6.4.2  uwe 	(reg)->r_macl = (uc)->uc_mcontext.__gregs[_REG_MACL];		\
     77  1.6.4.2  uwe 	(reg)->r_r15 = (uc)->uc_mcontext.__gregs[_REG_R15];		\
     78  1.6.4.2  uwe 	(reg)->r_r14 = (uc)->uc_mcontext.__gregs[_REG_R14];		\
     79  1.6.4.2  uwe 	(reg)->r_r13 = (uc)->uc_mcontext.__gregs[_REG_R13];		\
     80  1.6.4.2  uwe 	(reg)->r_r12 = (uc)->uc_mcontext.__gregs[_REG_R12];		\
     81  1.6.4.2  uwe 	(reg)->r_r11 = (uc)->uc_mcontext.__gregs[_REG_R11];		\
     82  1.6.4.2  uwe 	(reg)->r_r10 = (uc)->uc_mcontext.__gregs[_REG_R10];		\
     83  1.6.4.2  uwe 	(reg)->r_r9 = (uc)->uc_mcontext.__gregs[_REG_R9];		\
     84  1.6.4.2  uwe 	(reg)->r_r8 = (uc)->uc_mcontext.__gregs[_REG_R8];		\
     85  1.6.4.2  uwe 	(reg)->r_r7 = (uc)->uc_mcontext.__gregs[_REG_R7];		\
     86  1.6.4.2  uwe 	(reg)->r_r6 = (uc)->uc_mcontext.__gregs[_REG_R6];		\
     87  1.6.4.2  uwe 	(reg)->r_r5 = (uc)->uc_mcontext.__gregs[_REG_R5];		\
     88  1.6.4.2  uwe 	(reg)->r_r4 = (uc)->uc_mcontext.__gregs[_REG_R4];		\
     89  1.6.4.2  uwe 	(reg)->r_r3 = (uc)->uc_mcontext.__gregs[_REG_R3];		\
     90  1.6.4.2  uwe 	(reg)->r_r2 = (uc)->uc_mcontext.__gregs[_REG_R2];		\
     91  1.6.4.2  uwe 	(reg)->r_r1 = (uc)->uc_mcontext.__gregs[_REG_R1];		\
     92  1.6.4.2  uwe 	(reg)->r_r0 = (uc)->uc_mcontext.__gregs[_REG_R0];		\
     93  1.6.4.2  uwe 	(reg)->r_gbr = (uc)->uc_mcontext.__gregs[_REG_GBR];		\
     94  1.6.4.2  uwe 	} while (/*CONSTCOND*/0)
     95  1.6.4.2  uwe 
     96  1.6.4.2  uwe #define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {				\
     97  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_GBR] = (reg)->r_gbr;		\
     98  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_PC] = (reg)->r_spc;		\
     99  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_SR] = (reg)->r_ssr;		\
    100  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_PR] = (reg)->r_pr; 		\
    101  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_MACH] = (reg)->r_mach;		\
    102  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_MACL] = (reg)->r_macl;		\
    103  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R15] = (reg)->r_r15;		\
    104  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R14] = (reg)->r_r14;		\
    105  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R13] = (reg)->r_r13;		\
    106  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R12] = (reg)->r_r12;		\
    107  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R11] = (reg)->r_r11;		\
    108  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R10] = (reg)->r_r10;		\
    109  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R9] = (reg)->r_r9;		\
    110  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R8] = (reg)->r_r8;		\
    111  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R7] = (reg)->r_r7;		\
    112  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R6] = (reg)->r_r6;		\
    113  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R5] = (reg)->r_r5;		\
    114  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R4] = (reg)->r_r4;		\
    115  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R3] = (reg)->r_r3;		\
    116  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R2] = (reg)->r_r2;		\
    117  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R1] = (reg)->r_r1;		\
    118  1.6.4.2  uwe 	(uc)->uc_mcontext.__gregs[_REG_R0] = (reg)->r_r0;		\
    119  1.6.4.2  uwe 									\
    120  1.6.4.2  uwe 	(uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;	\
    121  1.6.4.2  uwe 	} while (/*CONSTCOND*/0)
    122  1.6.4.2  uwe 
    123  1.6.4.2  uwe #if 0 /* no struct fpreg!!! */
    124  1.6.4.2  uwe #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc)       			\
    125  1.6.4.2  uwe 	memcpy((freg), &(uc)->uc_mcontext.__fpregs, sizeof(*(freg)));
    126  1.6.4.2  uwe 
    127  1.6.4.2  uwe #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {       	       		\
    128  1.6.4.2  uwe 	memcpy(&(uc)->uc_mcontext.__fpregs, (freg), sizeof(*(freg)));	\
    129  1.6.4.2  uwe 	(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;       	\
    130  1.6.4.2  uwe 	} while (/*CONSTCOND*/0)
    131  1.6.4.2  uwe 
    132  1.6.4.2  uwe #else  /* stubs */
    133  1.6.4.2  uwe #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc)
    134  1.6.4.2  uwe #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg)
    135  1.6.4.2  uwe #endif
    136  1.6.4.2  uwe 
    137  1.6.4.2  uwe /* sh3 will not go SMP */
    138  1.6.4.2  uwe #define	PTHREAD__ATOMIC_IS_MEMBAR
    139  1.6.4.2  uwe 
    140  1.6.4.2  uwe #endif /* _LIB_PTHREAD_SH3_MD_H */
    141