Home | History | Annotate | Line # | Download | only in i386
pthread_md.h revision 1.1.2.5
      1  1.1.2.5  nathanw /*	$NetBSD: pthread_md.h,v 1.1.2.5 2002/04/24 05:20:48 nathanw Exp $	*/
      2  1.1.2.1  nathanw 
      3  1.1.2.2  nathanw /*-
      4  1.1.2.2  nathanw  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1.2.2  nathanw  * All rights reserved.
      6  1.1.2.2  nathanw  *
      7  1.1.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.2  nathanw  * by Nathan J. Williams.
      9  1.1.2.2  nathanw  *
     10  1.1.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.1.2.2  nathanw  * are met:
     13  1.1.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.1.2.2  nathanw  *    must display the following acknowledgement:
     20  1.1.2.2  nathanw  *        This product includes software developed by the NetBSD
     21  1.1.2.2  nathanw  *        Foundation, Inc. and its contributors.
     22  1.1.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.1.2.2  nathanw  *    from this software without specific prior written permission.
     25  1.1.2.2  nathanw  *
     26  1.1.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.2.2  nathanw  */
     38  1.1.2.1  nathanw 
     39  1.1.2.1  nathanw #ifndef _LIB_PTHREAD_I386_MD_H
     40  1.1.2.1  nathanw #define _LIB_PTHREAD_I386_MD_H
     41  1.1.2.1  nathanw 
     42  1.1.2.1  nathanw 
     43  1.1.2.1  nathanw static __inline long
     44  1.1.2.1  nathanw pthread__sp(void)
     45  1.1.2.1  nathanw {
     46  1.1.2.1  nathanw 	long ret;
     47  1.1.2.1  nathanw 	__asm("movl %%esp, %0" : "=g" (ret));
     48  1.1.2.1  nathanw 
     49  1.1.2.1  nathanw 	return ret;
     50  1.1.2.1  nathanw }
     51  1.1.2.1  nathanw 
     52  1.1.2.1  nathanw #define pthread__uc_sp(ucp) ((ucp)->uc_mcontext.__gregs[_REG_UESP])
     53  1.1.2.4   briggs #define pthread__uc_pc(ucp) ((ucp)->uc_mcontext.__gregs[_REG_EIP])
     54  1.1.2.3  nathanw 
     55  1.1.2.3  nathanw /*
     56  1.1.2.3  nathanw  * Usable stack space below the ucontext_t.
     57  1.1.2.3  nathanw  * See comment in pthread_switch.S about STACK_SWITCH.
     58  1.1.2.3  nathanw  */
     59  1.1.2.3  nathanw #define STACKSPACE	32	/* room for 8 integer values */
     60  1.1.2.5  nathanw 
     61  1.1.2.5  nathanw /*
     62  1.1.2.5  nathanw  * Conversions between struct reg and struct mcontext. Used by
     63  1.1.2.5  nathanw  * libpthread_dbg.
     64  1.1.2.5  nathanw  */
     65  1.1.2.5  nathanw 
     66  1.1.2.5  nathanw #define PTHREAD_UCONTEXT_TO_REG(reg, uc) do {				\
     67  1.1.2.5  nathanw 	(reg)->r_gs  = (uc)->uc_mcontext.__gregs[_REG_GS];		\
     68  1.1.2.5  nathanw 	(reg)->r_fs  = (uc)->uc_mcontext.__gregs[_REG_FS];		\
     69  1.1.2.5  nathanw 	(reg)->r_es  = (uc)->uc_mcontext.__gregs[_REG_ES];		\
     70  1.1.2.5  nathanw 	(reg)->r_ds  = (uc)->uc_mcontext.__gregs[_REG_DS];		\
     71  1.1.2.5  nathanw 	(reg)->r_edi = (uc)->uc_mcontext.__gregs[_REG_EDI];		\
     72  1.1.2.5  nathanw 	(reg)->r_esi = (uc)->uc_mcontext.__gregs[_REG_ESI];		\
     73  1.1.2.5  nathanw 	(reg)->r_ebp = (uc)->uc_mcontext.__gregs[_REG_EBP];		\
     74  1.1.2.5  nathanw 	(reg)->r_ebx = (uc)->uc_mcontext.__gregs[_REG_EBX];		\
     75  1.1.2.5  nathanw 	(reg)->r_edx = (uc)->uc_mcontext.__gregs[_REG_EDX];		\
     76  1.1.2.5  nathanw 	(reg)->r_ecx = (uc)->uc_mcontext.__gregs[_REG_ECX];		\
     77  1.1.2.5  nathanw 	(reg)->r_eax = (uc)->uc_mcontext.__gregs[_REG_EAX];		\
     78  1.1.2.5  nathanw 	(reg)->r_eip = (uc)->uc_mcontext.__gregs[_REG_EIP];		\
     79  1.1.2.5  nathanw 	(reg)->r_cs  = (uc)->uc_mcontext.__gregs[_REG_CS];		\
     80  1.1.2.5  nathanw 	(reg)->r_eflags  = (uc)->uc_mcontext.__gregs[_REG_EFL];		\
     81  1.1.2.5  nathanw 	(reg)->r_esp = (uc)->uc_mcontext.__gregs[_REG_UESP];		\
     82  1.1.2.5  nathanw 	(reg)->r_ss  = (uc)->uc_mcontext.__gregs[_REG_SS];		\
     83  1.1.2.5  nathanw 	} while (/*CONSTCOND*/0)
     84  1.1.2.5  nathanw 
     85  1.1.2.5  nathanw #define PTHREAD_REG_TO_UCONTEXT(uc, reg) do {				\
     86  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_GS]  = (reg)->r_gs;		\
     87  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_FS]  = (reg)->r_fs; 		\
     88  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_ES]  = (reg)->r_es; 		\
     89  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_DS]  = (reg)->r_ds; 		\
     90  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EDI] = (reg)->r_edi; 		\
     91  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_ESI] = (reg)->r_esi; 		\
     92  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EBP] = (reg)->r_ebp; 		\
     93  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EBX] = (reg)->r_ebx; 		\
     94  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EDX] = (reg)->r_edx; 		\
     95  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_ECX] = (reg)->r_ecx; 		\
     96  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EAX] = (reg)->r_eax; 		\
     97  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EIP] = (reg)->r_eip; 		\
     98  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_CS]  = (reg)->r_cs; 		\
     99  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_EFL] = (reg)->r_eflags; 		\
    100  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_UESP]= (reg)->r_esp;		\
    101  1.1.2.5  nathanw 	(uc)->uc_mcontext.__gregs[_REG_SS]  = (reg)->r_ss; 		\
    102  1.1.2.5  nathanw 	(uc)->uc_flags = ((uc)->uc_flags | _UC_CPU) & ~_UC_USER;       	\
    103  1.1.2.5  nathanw 	} while (/*CONSTCOND*/0)
    104  1.1.2.5  nathanw 
    105  1.1.2.5  nathanw #define PTHREAD_UCONTEXT_TO_FPREG(freg, uc)		       		\
    106  1.1.2.5  nathanw 	memcpy((freg)->__data,						\
    107  1.1.2.5  nathanw         (uc)->uc_mcontext.__fpregs.__fp_reg_set.__fpchip_state.__fp_state, \
    108  1.1.2.5  nathanw 	sizeof(struct fpreg))
    109  1.1.2.5  nathanw 
    110  1.1.2.5  nathanw #define PTHREAD_FPREG_TO_UCONTEXT(uc, freg) do {       	       		\
    111  1.1.2.5  nathanw 	memcpy(								\
    112  1.1.2.5  nathanw         (uc)->uc_mcontext.__fpregs.__fp_reg_set.__fpchip_state.__fp_state, \
    113  1.1.2.5  nathanw 	(freg)->__data, sizeof(struct fpreg));				\
    114  1.1.2.5  nathanw 	(uc)->uc_flags = ((uc)->uc_flags | _UC_FPU) & ~_UC_USER;       	\
    115  1.1.2.5  nathanw 	} while (/*CONSTCOND*/0)
    116  1.1.2.1  nathanw 
    117  1.1.2.1  nathanw #endif /* _LIB_PTHREAD_I386_MD_H */
    118