pthread_md.h revision 1.6
1/* $NetBSD: pthread_md.h,v 1.6 2008/04/28 20:23:02 martin Exp $ */ 2 3/*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Nathan J. Williams. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32/* 33 * Based on the i386 version. 34 */ 35 36#ifndef _LIB_PTHREAD_M68K_MD_H 37#define _LIB_PTHREAD_M68K_MD_H 38 39 40static inline long 41pthread__sp(void) 42{ 43 long ret; 44 __asm("movl %%sp, %0" : "=g" (ret)); 45 46 return ret; 47} 48 49#define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_A7]) 50#define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[_REG_PC]) 51 52/* 53 * Usable stack space below the ucontext_t. 54 * See comment in pthread_switch.S about STACK_SWITCH. 55 */ 56#define STACKSPACE 12 /* room for 3 integer values */ 57 58/* 59 * Conversions between struct reg and struct mcontext. Used by 60 * libpthread_dbg. 61 */ 62 63#define PTHREAD_UCONTEXT_TO_REG(reg, uc) do { \ 64 memcpy(&(reg)->r_regs, &(uc)->uc_mcontext.__gregs, \ 65 _REG_PC * sizeof(__greg_t)); \ 66 (reg)->r_sr = (uc)->uc_mcontext.__gregs[_REG_PS]; \ 67 (reg)->r_pc = (uc)->uc_mcontext.__gregs[_REG_PC]; \ 68 } while (/*CONSTCOND*/0) 69 70#define PTHREAD_REG_TO_UCONTEXT(uc, reg) do { \ 71 memcpy(&(uc)->uc_mcontext.__gregs, &(reg)->r_regs, \ 72 _REG_PC * sizeof(__greg_t)); \ 73 (uc)->uc_mcontext.__gregs[_REG_PS] = (reg)->r_sr; \ 74 (uc)->uc_mcontext.__gregs[_REG_PC] = (reg)->r_pc; \ 75 (uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER; \ 76 } while (/*CONSTCOND*/0) 77 78#define PTHREAD_UCONTEXT_TO_FPREG(freg, uc) do { \ 79 memcpy(&(freg)->r_regs, &(uc)->uc_mcontext.__fpregs.__fp_fpregs,\ 80 8 * 3 * sizeof(int)); \ 81 (freg)->r_fpcr = (uc)->uc_mcontext.__fpregs.__fp_pcr; \ 82 (freg)->r_fpsr = (uc)->uc_mcontext.__fpregs.__fp_psr; \ 83 (freg)->r_fpiar = (uc)->uc_mcontext.__fpregs.__fp_piaddr; \ 84 } while (/*CONSTCOND*/0) 85 86#define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do { \ 87 memcpy(&(uc)->uc_mcontext.__fpregs.__fp_fpregs, &(freg)->r_regs,\ 88 8 * 3 * sizeof(int)); \ 89 (uc)->uc_mcontext.__fpregs.__fp_pcr = (freg)->r_fpcr; \ 90 (uc)->uc_mcontext.__fpregs.__fp_psr = (freg)->r_fpsr; \ 91 (uc)->uc_mcontext.__fpregs.__fp_piaddr = (freg)->r_fpiar; \ 92 (uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER; \ 93 } while (/*CONSTCOND*/0) 94 95/* m68k will not go SMP */ 96#define PTHREAD__ATOMIC_IS_MEMBAR 97 98#endif /* _LIB_PTHREAD_M68K_MD_H */ 99