1 /* $NetBSD: pthread_md.h,v 1.7 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 #ifndef _LIB_PTHREAD_MIPS_MD_H 33 #define _LIB_PTHREAD_MIPS_MD_H 34 35 static inline long 36 pthread__sp(void) 37 { 38 long ret; 39 40 __asm("move %0, $sp" : "=r" (ret)); 41 42 return ret; 43 } 44 45 #define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_SP]) 46 #define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[_REG_EPC]) 47 48 /* 49 * Usable stack space below the ucontext_t. 50 * For a good time, see comments in pthread_switch.S and 51 * ../i386/pthread_switch.S about STACK_SWITCH. 52 */ 53 #define STACKSPACE (6*4) /* 6 integer values */ 54 55 /* 56 * Conversions between struct reg and struct mcontext. Used by 57 * libpthread_dbg. Note that in the "reg" structure, the indices 58 * are the same as are used in the "frame" structure in the kernel. 59 * These do NOT, in all cases, match the indices used in the 60 * "mcontext" structure. 61 */ 62 #include <mips/regnum.h> 63 64 #define PTHREAD_UCONTEXT_TO_REG(reg, uc) \ 65 do { \ 66 memcpy(&(reg)->r_regs[_R_AST], &(uc)->uc_mcontext.__gregs[_REG_AT],\ 67 sizeof(__greg_t) * 31); \ 68 (reg)->r_regs[_R_MULLO] = (uc)->uc_mcontext.__gregs[_REG_MDLO]; \ 69 (reg)->r_regs[_R_MULHI] = (uc)->uc_mcontext.__gregs[_REG_MDHI]; \ 70 (reg)->r_regs[_R_CAUSE] = (uc)->uc_mcontext.__gregs[_REG_CAUSE];\ 71 (reg)->r_regs[_R_PC] = (uc)->uc_mcontext.__gregs[_REG_EPC]; \ 72 (reg)->r_regs[_R_SR] = (uc)->uc_mcontext.__gregs[_REG_SR]; \ 73 } while (/*CONSTCOND*/0) 74 75 #define PTHREAD_REG_TO_UCONTEXT(uc, reg) \ 76 do { \ 77 memcpy(&(uc)->uc_mcontext.__gregs[_REG_AT], &(reg)->r_regs[_R_AST],\ 78 sizeof(__greg_t) * 31); \ 79 (uc)->uc_mcontext.__gregs[_REG_MDLO] = (reg)->r_regs[_R_MULLO]; \ 80 (uc)->uc_mcontext.__gregs[_REG_MDHI] = (reg)->r_regs[_R_MULHI]; \ 81 (uc)->uc_mcontext.__gregs[_REG_CAUSE] = (reg)->r_regs[_R_CAUSE];\ 82 (uc)->uc_mcontext.__gregs[_REG_EPC] = (reg)->r_regs[_R_PC]; \ 83 (uc)->uc_mcontext.__gregs[_REG_SR] = (reg)->r_regs[_R_SR]; \ 84 \ 85 (uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER; \ 86 } while (/*CONSTCOND*/0) 87 88 #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc) \ 89 do { \ 90 memcpy((freg), &(uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs, \ 91 sizeof((uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs)); \ 92 (freg)->r_regs[_R_FSR - _FPBASE] = \ 93 (uc)->uc_mcontext.__fpregs.__fp_csr; \ 94 } while (/*CONSTCOND*/0) 95 96 #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) \ 97 do { \ 98 memcpy(&(uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs, (freg), \ 99 sizeof((uc)->uc_mcontext.__fpregs.__fp_r.__fp_regs)); \ 100 (uc)->uc_mcontext.__fpregs.__fp_csr = \ 101 (freg)->r_regs[_R_FSR - _FPBASE]; \ 102 \ 103 (uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER; \ 104 } while (/*CONSTCOND*/0) 105 106 #endif /* !_LIB_PTHREAD_MIPS_MD_H */ 107