pthread_md.h revision 1.2
11.2Sthorpej/*	$NetBSD: pthread_md.h,v 1.2 2003/01/18 10:34:21 thorpej Exp $	*/
21.2Sthorpej
31.2Sthorpej/*
41.2Sthorpej * Copyright (c) 2001 Wasabi Systems, Inc.
51.2Sthorpej * All rights reserved.
61.2Sthorpej *
71.2Sthorpej * Written by Allen Briggs for Wasabi Systems, Inc.
81.2Sthorpej *
91.2Sthorpej * Redistribution and use in source and binary forms, with or without
101.2Sthorpej * modification, are permitted provided that the following conditions
111.2Sthorpej * are met:
121.2Sthorpej * 1. Redistributions of source code must retain the above copyright
131.2Sthorpej *    notice, this list of conditions and the following disclaimer.
141.2Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
151.2Sthorpej *    notice, this list of conditions and the following disclaimer in the
161.2Sthorpej *    documentation and/or other materials provided with the distribution.
171.2Sthorpej * 3. All advertising materials mentioning features or use of this software
181.2Sthorpej *    must display the following acknowledgement:
191.2Sthorpej *      This product includes software developed for the NetBSD Project by
201.2Sthorpej *      Wasabi Systems, Inc.
211.2Sthorpej * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.2Sthorpej *    or promote products derived from this software without specific prior
231.2Sthorpej *    written permission.
241.2Sthorpej *
251.2Sthorpej * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.2Sthorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.2Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.2Sthorpej * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.2Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.2Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.2Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.2Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.2Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.2Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.2Sthorpej * POSSIBILITY OF SUCH DAMAGE.
361.2Sthorpej */
371.2Sthorpej
381.2Sthorpej#ifndef _LIB_PTHREAD_POWERPC_MD_H
391.2Sthorpej#define _LIB_PTHREAD_POWERPC_MD_H
401.2Sthorpej
411.2Sthorpejstatic __inline long
421.2Sthorpejpthread__sp(void)
431.2Sthorpej{
441.2Sthorpej	long	ret;
451.2Sthorpej
461.2Sthorpej	__asm("mr %0,1" : "=r" (ret));
471.2Sthorpej
481.2Sthorpej	return ret;
491.2Sthorpej}
501.2Sthorpej
511.2Sthorpej#define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[1])
521.2Sthorpej#define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[34])
531.2Sthorpej
541.2Sthorpej/*
551.2Sthorpej * Set initial, sane values for registers whose values aren't just
561.2Sthorpej * "don't care".
571.2Sthorpej * 0xd032 is PSL_USERSET from arch/powerpc/include/psl.h
581.2Sthorpej */
591.2Sthorpej#define _INITCONTEXT_U_MD(ucp)						\
601.2Sthorpej	(ucp)->uc_mcontext.__gregs[35] = 0xd032;
611.2Sthorpej
621.2Sthorpej/*
631.2Sthorpej * Usable stack space below the ucontext_t.
641.2Sthorpej *    For a good time, see comments in pthread_switch.S and
651.2Sthorpej *    ../i386/pthread_switch.S about STACK_SWITCH.
661.2Sthorpej */
671.2Sthorpej#define STACKSPACE	16	/* room for 4 integer values */
681.2Sthorpej
691.2Sthorpej/*
701.2Sthorpej * Conversions between struct reg and struct mcontext. Used by
711.2Sthorpej * libpthread_dbg.
721.2Sthorpej */
731.2Sthorpej
741.2Sthorpej#define PTHREAD_UCONTEXT_TO_REG(reg, uc) do {				\
751.2Sthorpej	memcpy((reg)->fixreg, (uc)->uc_mcontext.__gregs, 32 * 4);	\
761.2Sthorpej	(reg)->cr = (uc)->uc_mcontext.__gregs[32];			\
771.2Sthorpej	(reg)->lr = (uc)->uc_mcontext.__gregs[33];			\
781.2Sthorpej	(reg)->pc = (uc)->uc_mcontext.__gregs[34];			\
791.2Sthorpej	(reg)->ctr = (uc)->uc_mcontext.__gregs[36];			\
801.2Sthorpej	(reg)->xer = (uc)->uc_mcontext.__gregs[37];			\
811.2Sthorpej	} while (/*CONSTCOND*/0)
821.2Sthorpej
831.2Sthorpej#define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {				\
841.2Sthorpej	memcpy((uc)->uc_mcontext.__gregs, (reg)->fixreg, 32 * 4);	\
851.2Sthorpej	(uc)->uc_mcontext.__gregs[32] = (reg)->cr;			\
861.2Sthorpej	(uc)->uc_mcontext.__gregs[33] = (reg)->lr;			\
871.2Sthorpej	(uc)->uc_mcontext.__gregs[34] = (reg)->pc;			\
881.2Sthorpej	(uc)->uc_mcontext.__gregs[36] = (reg)->ctr;			\
891.2Sthorpej	(uc)->uc_mcontext.__gregs[37] = (reg)->xer;			\
901.2Sthorpej	(uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;       	\
911.2Sthorpej	} while (/*CONSTCOND*/0)
921.2Sthorpej
931.2Sthorpej#define PTHREAD_UCONTEXT_TO_FPREG(freg, uc) do {	       		\
941.2Sthorpej	memcpy((freg)->fpreg, (uc)->uc_mcontext.__fpregs.__fpu_regs,	\
951.2Sthorpej		32 * 4);	       					\
961.2Sthorpej	(freg)->fpscr = (uc)->uc_mcontext.__fpregs.__fpu_fpscr;		\
971.2Sthorpej	} while (/*CONSTCOND*/0)
981.2Sthorpej
991.2Sthorpej#define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {	       		\
1001.2Sthorpej	memcpy((uc)->uc_mcontext.__fpregs.__fpu_regs, (freg)->fpreg,	\
1011.2Sthorpej		32 * 4);						\
1021.2Sthorpej	(uc)->uc_mcontext.__fpregs.__fpu_fpscr = (freg)->fpscr;		\
1031.2Sthorpej	(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;       	\
1041.2Sthorpej	} while (/*CONSTCOND*/0)
1051.2Sthorpej
1061.2Sthorpej#endif /* _LIB_PTHREAD_POWERPC_MD_H */
107