pthread_md.h revision 1.4
1/*	$NetBSD: pthread_md.h,v 1.4 2004/02/11 21:04:10 nathanw Exp $	*/
2
3/*
4 * Copyright (c) 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Allen Briggs for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 *    must display the following acknowledgement:
19 *      This product includes software developed for the NetBSD Project by
20 *      Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 *    or promote products derived from this software without specific prior
23 *    written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _LIB_PTHREAD_POWERPC_MD_H
39#define _LIB_PTHREAD_POWERPC_MD_H
40
41static __inline long
42pthread__sp(void)
43{
44	long	ret;
45
46	__asm("mr %0,1" : "=r" (ret));
47
48	return ret;
49}
50
51#define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[1])
52#define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[34])
53
54/*
55 * Set initial, sane values for registers whose values aren't just
56 * "don't care".
57 * 0xd032 is PSL_USERSET from arch/powerpc/include/psl.h
58 */
59#define _INITCONTEXT_U_MD(ucp)						\
60	(ucp)->uc_mcontext.__gregs[_REG_MSR] = 0xd032;
61
62/*
63 * Usable stack space below the ucontext_t.
64 *    For a good time, see comments in pthread_switch.S and
65 *    ../i386/pthread_switch.S about STACK_SWITCH.
66 */
67#define STACKSPACE	16	/* room for 4 integer values */
68
69/*
70 * Conversions between struct reg and struct mcontext. Used by
71 * libpthread_dbg.
72 */
73
74#define PTHREAD_UCONTEXT_TO_REG(reg, uc) do {				\
75	memcpy((reg)->fixreg, (uc)->uc_mcontext.__gregs, 32 * 4);	\
76	(reg)->cr = (uc)->uc_mcontext.__gregs[_REG_CR];			\
77	(reg)->lr = (uc)->uc_mcontext.__gregs[_REG_LR];			\
78	(reg)->pc = (uc)->uc_mcontext.__gregs[_REG_PC];			\
79	(reg)->ctr = (uc)->uc_mcontext.__gregs[_REG_CTR];		\
80	(reg)->xer = (uc)->uc_mcontext.__gregs[_REG_XER];		\
81	} while (/*CONSTCOND*/0)
82
83#define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {				\
84	memcpy((uc)->uc_mcontext.__gregs, (reg)->fixreg, 32 * 4);	\
85	(uc)->uc_mcontext.__gregs[_REG_CR] = (reg)->cr;			\
86	(uc)->uc_mcontext.__gregs[_REG_LR] = (reg)->lr;			\
87	(uc)->uc_mcontext.__gregs[_REG_PC] = (reg)->pc;			\
88	(uc)->uc_mcontext.__gregs[_REG_CTR] = (reg)->ctr;		\
89	(uc)->uc_mcontext.__gregs[_REG_XER] = (reg)->xer;		\
90	(uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;       	\
91	} while (/*CONSTCOND*/0)
92
93#define PTHREAD_UCONTEXT_TO_FPREG(freg, uc) do {	       		\
94	memcpy((freg)->fpreg, (uc)->uc_mcontext.__fpregs.__fpu_regs,	\
95		32 * 4);	       					\
96	(freg)->fpscr = (uc)->uc_mcontext.__fpregs.__fpu_fpscr;		\
97	} while (/*CONSTCOND*/0)
98
99#define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {	       		\
100	memcpy((uc)->uc_mcontext.__fpregs.__fpu_regs, (freg)->fpreg,	\
101		32 * 4);						\
102	(uc)->uc_mcontext.__fpregs.__fpu_fpscr = (freg)->fpscr;		\
103	(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;       	\
104	} while (/*CONSTCOND*/0)
105
106#define PTHREAD_UCONTEXT_XREG_FLAG	_UC_POWERPC_VEC
107
108#define PTHREAD_UCONTEXT_TO_XREG(xreg, uc) do {				\
109	memcpy(((struct vreg *)(xreg))->vreg,				\
110		(uc)->uc_mcontext.__vrf.__vrs,				\
111		16 * _NVR);						\
112	((struct vreg *)(xreg))->vscr = (uc)->uc_mcontext.__vrf.__vscr;	\
113	((struct vreg *)(xreg))->vrsave = (uc)->uc_mcontext.__vrf.__vrsave; \
114	} while (/*CONSTCOND*/0)
115
116#define PTHREAD_XREG_TO_UCONTEXT(uc, xreg) do {				\
117	memcpy((uc)->uc_mcontext.__vrf.__vrs,				\
118		((struct vreg *)(xreg))->vreg,				\
119		16 * _NVR);						\
120	(uc)->uc_mcontext.__vrf.__vscr = ((struct vreg *)(xreg))->vscr;	\
121	(uc)->uc_mcontext.__vrf.__vrsave = ((struct vreg *)(xreg))->vrsave; \
122	(uc)->uc_flags = ((uc)->uc_flags | _UC_POWERPC_VEC) & ~_UC_USER; \
123	} while (/*CONSTCOND*/0)
124
125#endif /* _LIB_PTHREAD_POWERPC_MD_H */
126