xref: /netbsd-src/lib/libpthread/arch/m68k/pthread_md.h (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: pthread_md.h,v 1.3 2003/11/25 21:27:30 christos 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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Based on the i386 version.
41  */
42 
43 #ifndef _LIB_PTHREAD_M68K_MD_H
44 #define _LIB_PTHREAD_M68K_MD_H
45 
46 
47 static __inline long
48 pthread__sp(void)
49 {
50 	long ret;
51 	__asm("movl %%sp, %0" : "=g" (ret));
52 
53 	return ret;
54 }
55 
56 #define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_A7])
57 #define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[_REG_PC])
58 
59 /*
60  * Usable stack space below the ucontext_t.
61  * See comment in pthread_switch.S about STACK_SWITCH.
62  */
63 #define STACKSPACE	12	/* room for 3 integer values */
64 
65 /*
66  * Conversions between struct reg and struct mcontext. Used by
67  * libpthread_dbg.
68  */
69 
70 #define PTHREAD_UCONTEXT_TO_REG(reg, uc) do {				\
71 	memcpy(&(reg)->r_regs, &(uc)->uc_mcontext.__gregs,		\
72 		_REG_PC * sizeof(__greg_t));				\
73 	(reg)->r_sr = (uc)->uc_mcontext.__gregs[_REG_PS];		\
74 	(reg)->r_pc = (uc)->uc_mcontext.__gregs[_REG_PC];		\
75 	} while (/*CONSTCOND*/0)
76 
77 #define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {				\
78 	memcpy(&(uc)->uc_mcontext.__gregs, &(reg)->r_regs,		\
79 		_REG_PC * sizeof(__greg_t));				\
80 	(uc)->uc_mcontext.__gregs[_REG_PS] = (reg)->r_sr;		\
81 	(uc)->uc_mcontext.__gregs[_REG_PC] = (reg)->r_pc;		\
82 	(uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;       	\
83 	} while (/*CONSTCOND*/0)
84 
85 #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc) do {       			\
86 	memcpy(&(freg)->r_regs, &(uc)->uc_mcontext.__fpregs.__fp_fpregs,\
87 		8 * 3 * sizeof(int));					\
88 	(freg)->r_fpcr = (uc)->uc_mcontext.__fpregs.__fp_pcr;		\
89 	(freg)->r_fpsr = (uc)->uc_mcontext.__fpregs.__fp_psr;		\
90 	(freg)->r_fpiar = (uc)->uc_mcontext.__fpregs.__fp_piaddr;      	\
91 	} while (/*CONSTCOND*/0)
92 
93 #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {       	       		\
94 	memcpy(&(uc)->uc_mcontext.__fpregs.__fp_fpregs, &(freg)->r_regs,\
95 		8 * 3 * sizeof(int));					\
96 	(uc)->uc_mcontext.__fpregs.__fp_pcr = (freg)->r_fpcr;		\
97 	(uc)->uc_mcontext.__fpregs.__fp_psr = (freg)->r_fpsr;		\
98 	(uc)->uc_mcontext.__fpregs.__fp_piaddr = (freg)->r_fpiar;      	\
99 	(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;       	\
100 	} while (/*CONSTCOND*/0)
101 
102 #endif /* _LIB_PTHREAD_M68K_MD_H */
103